From 3e7a9c9b0064680a4dcc0b3fa9d733280f4243c5 Mon Sep 17 00:00:00 2001 From: starnakin Date: Tue, 24 Oct 2023 17:06:43 +0200 Subject: [PATCH] add: login --- .../accounts/templates/login.html | 8 +++++++ django/trancendence/accounts/views.py | 23 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 django/trancendence/accounts/templates/login.html diff --git a/django/trancendence/accounts/templates/login.html b/django/trancendence/accounts/templates/login.html new file mode 100644 index 0000000..2d0a7d9 --- /dev/null +++ b/django/trancendence/accounts/templates/login.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 041140b..5f5a1fa 100644 --- a/django/trancendence/accounts/views.py +++ b/django/trancendence/accounts/views.py @@ -4,9 +4,30 @@ from django.views import View # Create your views here. from django.http import HttpResponse from django.contrib.auth.models import User +from django.db.models.query import QuerySet class Login(View): - pass + def get(self, request): + return render(request, "login.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") + + return HttpResponse("ok: account valid") class Register(View): def get(self, request):