Compare commits
2 Commits
cb010470a9
...
a17fa07805
Author | SHA1 | Date | |
---|---|---|---|
a17fa07805 | |||
3e7a9c9b00 |
8
django/trancendence/accounts/templates/delete.html
Normal file
8
django/trancendence/accounts/templates/delete.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<html>
|
||||||
|
<form method='post'>
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="text" name="username" placeholder="username">
|
||||||
|
<input type="text" name="password" placeholder="password">
|
||||||
|
<input type='submit'>
|
||||||
|
</form>
|
||||||
|
</html>
|
8
django/trancendence/accounts/templates/login.html
Normal file
8
django/trancendence/accounts/templates/login.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<html>
|
||||||
|
<form method='post'>
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="text" name="username" placeholder="username">
|
||||||
|
<input type="text" name="password" placeholder="password">
|
||||||
|
<input type='submit'>
|
||||||
|
</form>
|
||||||
|
</html>
|
@ -4,9 +4,30 @@ from django.views import View
|
|||||||
# Create your views here.
|
# Create your views here.
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.db.models.query import QuerySet
|
||||||
|
|
||||||
class Login(View):
|
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):
|
class Register(View):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
@ -29,4 +50,26 @@ class Register(View):
|
|||||||
return HttpResponse("ok: user added")
|
return HttpResponse("ok: user added")
|
||||||
|
|
||||||
class Delete(View):
|
class Delete(View):
|
||||||
pass
|
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")
|
Loading…
Reference in New Issue
Block a user