<s> from __future__ import absolute_import <EOL> from django import forms <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from allauth . account . forms import BaseSignupForm <EOL> from allauth . account . utils import ( user_username , user_email , <EOL> user_field ) <EOL> from . models import SocialAccount <EOL> from . adapter import get_adapter <EOL> from . import app_settings <EOL> from . import signals <EOL> class SignupForm ( BaseSignupForm ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . sociallogin = kwargs . pop ( '<STR_LIT>' ) <EOL> user = self . sociallogin . user <EOL> initial = { '<STR_LIT:email>' : user_email ( user ) or '<STR_LIT>' , <EOL> '<STR_LIT:username>' : user_username ( user ) or '<STR_LIT>' , <EOL> '<STR_LIT>' : user_field ( user , '<STR_LIT>' ) or '<STR_LIT>' , <EOL> '<STR_LIT>' : user_field ( user , '<STR_LIT>' ) or '<STR_LIT>' } <EOL> kwargs . update ( { <EOL> '<STR_LIT>' : initial , <EOL> '<STR_LIT>' : kwargs . get ( '<STR_LIT>' , <EOL> app_settings . EMAIL_REQUIRED ) } ) <EOL> super ( SignupForm , self ) . __init__ ( * args , ** kwargs ) <EOL> def save ( self , request ) : <EOL> adapter = get_adapter ( request ) <EOL> user = adapter . save_user ( request , self . sociallogin , form = self ) <EOL> self . custom_signup ( request , user ) <EOL> return user <EOL> def raise_duplicate_email_error ( self ) : <EOL> raise forms . ValidationError ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> % self . sociallogin . account . get_provider ( ) . name ) <EOL> class DisconnectForm ( forms . Form ) : <EOL> account = forms . ModelChoiceField ( queryset = SocialAccount . objects . none ( ) , <EOL> widget = forms . RadioSelect , <EOL> required = True ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . request = kwargs . pop ( '<STR_LIT>' ) <EOL> self . accounts = SocialAccount . objects . filter ( user = self . request . user ) <EOL> super ( DisconnectForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . queryset = self . accounts <EOL> def clean ( self ) : <EOL> cleaned_data = super ( DisconnectForm , self ) . clean ( ) <EOL> account = cleaned_data . get ( '<STR_LIT>' ) <EOL> if account : <EOL> get_adapter ( self . request ) . validate_disconnect ( <EOL> account , <EOL> self . accounts ) <EOL> return cleaned_data <EOL> def save ( self ) : <EOL> account = self . cleaned_data [ '<STR_LIT>' ] <EOL> account . delete ( ) <EOL> signals . social_account_removed . send ( sender = SocialAccount , <EOL> request = self . request , <EOL> socialaccount = account ) </s>
