I'm trying to modify the signup form which the user is shown when logging in from a socialaccount provider.
Here's me custom signup form code:
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'
}
But the problem is, that my signup method never gets called, and so, the confirm_password
method isn't called either, and there's no validation on password being done. That is, if I enter two different passwords, the first password is saved.
What could be wrong?
Are you setting this value SOCIALACCOUNT_AUTO_SIGNUP = False ? This is to make sure that upon successful authentication the user is redirected to your signup form.
I came to your link because I had to implement exact same feature. So this is how I have done it on my end.
forms.py
I got the idea to explore the original code in https://github.com/pennersr/django-allauth/blob/master/allauth/account/forms.py and found out that there is no such function like clean_password1() but there is clean_password2() which is doing the intended work. So just copied it as it is and everything worked :)
If it works for you then don't forget to accept it as answer.
I basically created my version of the SignupForm class:
Worked for me, flawlessly. You guys can compare the default SignupForm in socialaccount.forms and my implementation, for the differences.