diff --git a/secretnote/backend/views.py b/secretnote/backend/views.py index 32a2e56..0f1a806 100644 --- a/secretnote/backend/views.py +++ b/secretnote/backend/views.py @@ -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 @@ -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") @@ -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") @@ -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: @@ -66,11 +65,11 @@ 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() @@ -78,12 +77,11 @@ def allnotes(request): 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') @@ -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") \ No newline at end of file