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.
 
 
 
 
 
 

38 lines
1.4 KiB

from django import forms
from accounts.models import Profile
from random import randint
from accounts.utils import normalize_phone
class LoginForm(forms.Form):
phone = forms.CharField(label='Номер мобильного телефона', max_length=45, required=True)
def clean_phone(self):
data = normalize_phone(self.cleaned_data['phone'])
try:
profile = Profile.objects.get(phone=data)
profile.temp_password = randint(1000000, 9999999)
self.temp_password = profile.temp_password
profile.save()
except Profile.DoesNotExist:
raise forms.ValidationError("Вы еще не совершали покупки в нашем магазине")
return data
class LoginSmsForm(forms.Form):
sms = forms.IntegerField(label='Одноразовый пароль', required=True)
def clean_sms(self):
data = self.cleaned_data['sms']
phone = normalize_phone(self.phone)
try:
profile = Profile.objects.get(phone=phone, temp_password=data)
self.profile = profile
#profile.temp_password = randint(1000000, 9999999)
#self.temp_password = profile.temp_password
#profile.save()
except Profile.DoesNotExist:
raise forms.ValidationError("Неверный одноразовый пароль")
return data