vecāks
44036e57e9
revīzija
cd8e918890
@ -0,0 +1,20 @@
|
||||
from django import forms
|
||||
|
||||
from accounts.models import Accounts
|
||||
from accounts.utils import LoginHelper
|
||||
|
||||
|
||||
class LoginForm(forms.Form):
|
||||
account_name = forms.CharField()
|
||||
password = forms.CharField(widget=forms.PasswordInput)
|
||||
|
||||
def is_valid(self):
|
||||
if not super(LoginForm, self).is_valid():
|
||||
return False
|
||||
|
||||
account = Accounts.objects.get(name=self.cleaned_data['account_name'])
|
||||
hashed_password = LoginHelper.hash_password(self.cleaned_data['password'])
|
||||
if account.password == hashed_password:
|
||||
return True
|
||||
else:
|
||||
return False
|
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Login</h1>
|
||||
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,9 @@
|
||||
import hashlib
|
||||
|
||||
class LoginHelper(object):
|
||||
|
||||
@staticmethod
|
||||
def hash_password(password):
|
||||
hashed_password = hashlib.sha1(password.encode('utf-8'))\
|
||||
.hexdigest()
|
||||
return hashed_password
|
Notiek ielāde…
Atsaukties uz šo jaunā problēmā