我想修改社交账户提供商登录时用户看到的注册表单。
以下是我的自定义注册表单代码:
from allauth.socialaccount.forms import SignupForm
from allauth.account.forms import SetPasswordField, PasswordField
class SocialPasswordedSignupForm(SignupForm):
password1 = SetPasswordField(label=_("Password"))
password2 = PasswordField(label=_("Password (again)"))
def confirm_password(self):
print('entered confirm_password')
if ("password1" in self.cleaned_data
and "password2" in self.cleaned_data):
print('password fields found')
if self.cleaned_data['password1'] != self.cleaned_data['password2']:
print('passwords not equal')
raise forms.ValidationError(_("You must type the same password"
" each time."))
print('passwords equal')
return self.cleaned_data["password1"]
else:
print('passwords not found in form')
raise forms.ValidationError(_("Password not found in form"))
def signup(self, request, user):
print('signup in SocialPasswordedSignupForm')
password = self.confirm_password()
user.set_password(password)
user.save()
settings.py:
SOCIALACCOUNT_FORMS = {
'signup': 'users.forms.SocialPasswordedSignupForm'
}
但问题是,我的注册方法从未被调用,因此confirm_password
方法也不会被调用,密码验证也没有进行。也就是说,如果我输入两个不同的密码,第一个密码将被保存。
可能出了什么问题?