2019-01-20 22:24:01 +01:00
|
|
|
from django import forms
|
|
|
|
|
|
|
|
from accounts.models import Accounts
|
2019-01-23 23:53:13 +01:00
|
|
|
from accounts.utils import LoginHelper, VocationHelper
|
2019-01-20 22:24:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2019-01-23 23:53:13 +01:00
|
|
|
|
|
|
|
class CreateCharacterForm(forms.Form):
|
|
|
|
name = forms.CharField()
|
2019-01-27 13:39:49 +01:00
|
|
|
#vocation = forms.ChoiceField(
|
|
|
|
# choices=VocationHelper.get_base_vocation_choices())
|
2019-01-23 23:53:13 +01:00
|
|
|
sex = forms.ChoiceField(choices=((0, 'female'), (1, 'male')))
|