Skip to content

Commit

Permalink
fix: removed the login required decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
fatmaebrahim committed Oct 18, 2024
1 parent c8002be commit 49404cd
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions secretnote/backend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Create your views here.
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.contrib.auth import authenticate,login
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User

from django.urls import reverse
Expand All @@ -17,7 +16,7 @@
import uuid


@ratelimit(key='ip', rate='100/m')
@ratelimit(key='ip', rate='20/m')
def signup(request):
if request.method=="POST":
username = request.POST.get("username")
Expand All @@ -32,7 +31,7 @@ def signup(request):
print("all fields are required")
return render(request,"backend/signup.html")

@ratelimit(key='ip', rate='100/m')
@ratelimit(key='ip', rate='20/m')
def signin(request):
if request.method == "POST":
username = request.POST.get("username")
Expand All @@ -54,7 +53,7 @@ def homepage(request):



@ratelimit(key='ip', rate='100/m')
@ratelimit(key='ip', rate='20/m')
def content(request, note_url):
note = get_object_or_404(Note, url=note_url)
if note.views_limit<1:
Expand All @@ -66,24 +65,23 @@ def content(request, note_url):



@login_required
@ratelimit(key='ip', rate='100/m')
@ratelimit(key='ip', rate='20/m')
@never_cache
def allnotes(request):
print(request.user)
if not request.user.is_authenticated:
raise Http404("unAuthorized user")
outdated_notes = Note.objects.filter(Q(views_limit=0) | Q(expiration__lte=datetime.now()))
outdated_notes.delete()
notes=Note.objects.all()
context={"notes": notes}
return render(request,"backend/allnotes.html",context)




@login_required
@ratelimit(key='ip', rate='100/m')

@ratelimit(key='ip', rate='20/m')
def addnote(request):
print(request.user)
if not request.user.is_authenticated:
raise Http404("unAuthorized user")
if request.method == "POST":

content=request.POST.get('content')
Expand All @@ -98,8 +96,5 @@ def addnote(request):

n=Note(content=content,expiration=expiration,views_limit=views_limit,url=uuid.uuid4())
n.save()

# print(n.created_at) #2024-10-09 12:53:10.248280+00:00 datetime
# print(n.expiration) #2024-10-10T01:01 string
return HttpResponseRedirect(reverse("notes:all"))
return render(request,"backend/addnote.html")

0 comments on commit 49404cd

Please sign in to comment.