|
|
|
|
@ -15,7 +15,7 @@ class LoginForm(AuthenticationForm):
|
|
|
|
|
attrs={'placeholder': "username", "class": "form-control"})
|
|
|
|
|
self.fields['password'].widget = widgets.PasswordInput(
|
|
|
|
|
attrs={'placeholder': "password", "class": "form-control"})
|
|
|
|
|
#自定义登录表单,在__init__方法中设置username(文本输入,占位符、form-control样式)和password(密码输入,占位符、form-control样式)字段的前端显示样式。
|
|
|
|
|
#lxy自定义登录表单,在__init__方法中设置username(文本输入,占位符、form-control样式)和password(密码输入,占位符、form-control样式)字段的前端显示样式。
|
|
|
|
|
|
|
|
|
|
class RegisterForm(UserCreationForm):
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
@ -29,17 +29,17 @@ class RegisterForm(UserCreationForm):
|
|
|
|
|
attrs={'placeholder': "password", "class": "form-control"})
|
|
|
|
|
self.fields['password2'].widget = widgets.PasswordInput(
|
|
|
|
|
attrs={'placeholder': "repeat password", "class": "form-control"})
|
|
|
|
|
#__init__方法中设置username(文本输入)、email(邮箱输入)、password1和password2(密码输入)字段的占位符与form-control样式
|
|
|
|
|
#lxy__init__方法中设置username(文本输入)、email(邮箱输入)、password1和password2(密码输入)字段的占位符与form-control样式
|
|
|
|
|
def clean_email(self):
|
|
|
|
|
email = self.cleaned_data['email']
|
|
|
|
|
if get_user_model().objects.filter(email=email).exists():
|
|
|
|
|
raise ValidationError(_("email already exists"))
|
|
|
|
|
return email
|
|
|
|
|
#clean_email方法验证邮箱是否已被注册,若存在则抛出“邮箱已存在”的验证错误
|
|
|
|
|
#lxyclean_email方法验证邮箱是否已被注册,若存在则抛出“邮箱已存在”的验证错误
|
|
|
|
|
class Meta:
|
|
|
|
|
model = get_user_model()
|
|
|
|
|
fields = ("username", "email")
|
|
|
|
|
#Meta类指定关联模型为自定义用户模型,表单字段包含username和email
|
|
|
|
|
#lxy Meta类指定关联模型为自定义用户模型,表单字段包含username和email
|
|
|
|
|
|
|
|
|
|
class ForgetPasswordForm(forms.Form):
|
|
|
|
|
new_password1 = forms.CharField(
|
|
|
|
|
@ -81,7 +81,7 @@ class ForgetPasswordForm(forms.Form):
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
#定义new_password1(新密码,密码输入)、new_password2(确认密码,密码输入)、email(邮箱,文本输入)、code(验证码,文本输入)字段,均设置form-control样式和占位符。
|
|
|
|
|
#lxy定义new_password1(新密码,密码输入)、new_password2(确认密码,密码输入)、email(邮箱,文本输入)、code(验证码,文本输入)字段,均设置form-control样式和占位符。
|
|
|
|
|
def clean_new_password2(self):
|
|
|
|
|
password1 = self.data.get("new_password1")
|
|
|
|
|
password2 = self.data.get("new_password2")
|
|
|
|
|
@ -90,7 +90,7 @@ class ForgetPasswordForm(forms.Form):
|
|
|
|
|
password_validation.validate_password(password2)
|
|
|
|
|
|
|
|
|
|
return password2
|
|
|
|
|
# clean_new_password2方法验证两次新密码是否一致,并对密码进行有效性校验
|
|
|
|
|
#lxyclean_new_password2方法验证两次新密码是否一致,并对密码进行有效性校验
|
|
|
|
|
def clean_email(self):
|
|
|
|
|
user_email = self.cleaned_data.get("email")
|
|
|
|
|
if not BlogUser.objects.filter(
|
|
|
|
|
@ -100,7 +100,7 @@ class ForgetPasswordForm(forms.Form):
|
|
|
|
|
raise ValidationError(_("email does not exist"))
|
|
|
|
|
return user_email
|
|
|
|
|
|
|
|
|
|
# clean_email方法验证邮箱是否已注册(基于BlogUser模型),未注册则抛出“邮箱不存在”的验证错误
|
|
|
|
|
#lxyclean_email方法验证邮箱是否已注册(基于BlogUser模型),未注册则抛出“邮箱不存在”的验证错误
|
|
|
|
|
def clean_code(self):
|
|
|
|
|
code = self.cleaned_data.get("code")
|
|
|
|
|
error = utils.verify(
|
|
|
|
|
@ -110,10 +110,10 @@ class ForgetPasswordForm(forms.Form):
|
|
|
|
|
if error:
|
|
|
|
|
raise ValidationError(error)
|
|
|
|
|
return code
|
|
|
|
|
#clean_code方法调用工具方法utils.verify验证验证码有效性,无效则抛出错误
|
|
|
|
|
#lxy clean_code方法调用工具方法utils.verify验证验证码有效性,无效则抛出错误
|
|
|
|
|
|
|
|
|
|
class ForgetPasswordCodeForm(forms.Form):
|
|
|
|
|
email = forms.EmailField(
|
|
|
|
|
label=_('Email'),
|
|
|
|
|
)
|
|
|
|
|
#仅包含email字段(邮箱输入),用于忘记密码流程中验证邮箱的步骤
|
|
|
|
|
#lxy仅包含email字段(邮箱输入),用于忘记密码流程中验证邮箱的步骤
|