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.

40 lines
1.5 KiB

5 months ago
from django import forms
from django.contrib.auth import get_user_model
from .models import CaptchaModel, Fund
User = get_user_model()
class FundForm(forms.ModelForm):
class Meta:
model = Fund
fields = ['fund_id', 'fund_name']
class RegisterForm(forms.Form):
username = forms.CharField(max_length=20,min_length=2,error_messages={
'required':'请输入用户名',
'max_length':'用户长度在2~20之间',
'min_length':'用户长度在2~20之间'
})
email = forms.EmailField(error_messages={'required':'请输入邮箱','invalid':'请输入一个正确的邮箱!'})
password = forms.CharField(max_length=20,min_length=6)
def clean_email(self):
email = self.cleaned_data.get('email')
exists = User.objects.filter(email=email).exists()
if exists:
raise forms.ValidationError('邮箱已经被注册')
return email
def clean_captcha(self):
captcha = self.cleaned_data_get('captcha')
email = self.cleaned_data_get('email')
creat_time = self.cleaned_data_get('creat_time')
captcha_model = Captcha.objects.filter(email=email,captcha=captcha).first()
if not captcha_model:
raise foroms.ValidationError('验证码错误')
return captcha
class LoginForm(forms.Form):
email = forms.EmailField(error_messages={"required": '请传入邮箱!', 'invalid': '请传入一个正确的邮箱!'})
password = forms.CharField(max_length=20, min_length=6)
remember = forms.IntegerField(required=False)