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 @@ + +
+ \ 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