From a17fa078050119a22a2a772aacf41db5365ce525 Mon Sep 17 00:00:00 2001 From: starnakin Date: Tue, 24 Oct 2023 17:10:32 +0200 Subject: [PATCH] add: delete account --- .../accounts/templates/delete.html | 8 +++++++ django/trancendence/accounts/views.py | 24 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 django/trancendence/accounts/templates/delete.html diff --git a/django/trancendence/accounts/templates/delete.html b/django/trancendence/accounts/templates/delete.html new file mode 100644 index 0000000..2d0a7d9 --- /dev/null +++ b/django/trancendence/accounts/templates/delete.html @@ -0,0 +1,8 @@ + +
+ {% csrf_token %} + + + +
+ \ No newline at end of file diff --git a/django/trancendence/accounts/views.py b/django/trancendence/accounts/views.py index 5f5a1fa..fe70c26 100644 --- a/django/trancendence/accounts/views.py +++ b/django/trancendence/accounts/views.py @@ -50,4 +50,26 @@ class Register(View): return HttpResponse("ok: user added") class Delete(View): - pass \ No newline at end of file + def get(self, request): + return render(request, "delete.html") + + def post(self, request): + username = request.POST.get("username") + if (username == None): + return HttpResponse("error: username or password invalid") + + password = request.POST.get("password") + if (password == None): + return HttpResponse("error: username or password invalid") + + query: QuerySet = User.objects.filter(username=username) + if (not query.exists()): + return HttpResponse("error: username or password invalid") + + user: User = User.objects.get(username=username) + if (not user.check_password(password)): + return HttpResponse("error: username or password invalid") + + user.delete() + + return HttpResponse("ok: account has been deleted") \ No newline at end of file