Lang Thang
Lang Thang

Reputation: 11

Django-allauth custom social signup form

everyone. I am begin to work with django. When i search for authentication system i found django-allauth package. It is great, but i have problem when try to customise social signup form that i want to let user enter their password at that time user signup and they must fill any time they sign up. As document i write custom form.

class SocialSignupForm(forms.Form):

password1 = forms.CharField(max_length=30, label="Password")
password2 = forms.CharField(max_length=30, label="Password(again)")

def clean_password1(self):
    if ("password1" in self.cleaned_data and "password2" in self.cleaned_data):
        if self.cleaned_data['password1'] != self.cleaned_data['password2']:
            raise forms.ValidationError(_("You must type the same password"
                                          " each time."))
    return self.cleaned_data["password1"]

def signup(self, request, user):
    user.set_password(self.cleaned_data["password1"])
    user.save()

and in settings file i put

ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_EMAIL_REQUIRED = True
SOCIALACCOUNT_AUTO_SIGNUP = True
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = {
    'facebook': {
        'SCOPE': ['email', 'publish_stream'],
        'METHOD': 'oauth2'
    }
}
ACCOUNT_ADAPTER = 'myapp.adapter.MyAccountAdapter'
SOCIALACCOUNT_ADAPTER = 'myapp.adapter.MySocialAccountAdapter'
ACCOUNT_SIGNUP_FORM_CLASS = 'myapp.forms.SignupForm'
SOCIALACCOUNT_FORMS =  {'signup': 'myapp.forms.SocialSignupForm'}

but when i try to connect to social provider, i received:

init() got an unexpected keyword argument 'sociallogin'

anyone can suggest me how to fix that

Upvotes: 1

Views: 2823

Answers (1)

Wahib Ul Haq
Wahib Ul Haq

Reputation: 4385

I just replied to a similar question here : https://stackoverflow.com/a/28515254/1016544 so you can take a look. I am using the same settings like you except that I am not implementing my own custom adapter. The other significant difference is that i am overriding clean_password2() function instead of clean_password1() because it was not working in my case.

If it helps then don't forget to accept it as answer :)

Upvotes: 2

Related Questions