You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
603 B
21 lines
603 B
5 years ago
|
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
|