<s> from __future__ import absolute_import <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . core . urlresolvers import reverse <EOL> from django . core . exceptions import ValidationError <EOL> from . . utils import ( import_attribute , <EOL> email_address_exists , <EOL> valid_email_or_none ) <EOL> from . . account . utils import user_email , user_username , user_field <EOL> from . . account . models import EmailAddress <EOL> from . . account . adapter import get_adapter as get_account_adapter <EOL> from . . account import app_settings as account_settings <EOL> from . . account . app_settings import EmailVerificationMethod <EOL> from . import app_settings <EOL> class DefaultSocialAccountAdapter ( object ) : <EOL> def __init__ ( self , request = None ) : <EOL> self . request = request <EOL> def pre_social_login ( self , request , sociallogin ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def authentication_error ( self , <EOL> request , <EOL> provider_id , <EOL> error = None , <EOL> exception = None , <EOL> extra_context = None ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def new_user ( self , request , sociallogin ) : <EOL> """<STR_LIT>""" <EOL> return get_account_adapter ( ) . new_user ( request ) <EOL> def save_user ( self , request , sociallogin , form = None ) : <EOL> """<STR_LIT>""" <EOL> u = sociallogin . user <EOL> u . set_unusable_password ( ) <EOL> if form : <EOL> get_account_adapter ( ) . save_user ( request , u , form ) <EOL> else : <EOL> get_account_adapter ( ) . populate_username ( request , u ) <EOL> sociallogin . save ( request ) <EOL> return u <EOL> def populate_user ( self , <EOL> request , <EOL> sociallogin , <EOL> data ) : <EOL> """<STR_LIT>""" <EOL> username = data . get ( '<STR_LIT:username>' ) <EOL> first_name = data . get ( '<STR_LIT>' ) <EOL> last_name = data . get ( '<STR_LIT>' ) <EOL> email = data . get ( '<STR_LIT:email>' ) <EOL> name = data . get ( '<STR_LIT:name>' ) <EOL> user = sociallogin . user <EOL> user_username ( user , username or '<STR_LIT>' ) <EOL> user_email ( user , valid_email_or_none ( email ) or '<STR_LIT>' ) <EOL> name_parts = ( name or '<STR_LIT>' ) . partition ( '<STR_LIT:U+0020>' ) <EOL> user_field ( user , '<STR_LIT>' , first_name or name_parts [ <NUM_LIT:0> ] ) <EOL> user_field ( user , '<STR_LIT>' , last_name or name_parts [ <NUM_LIT:2> ] ) <EOL> return user <EOL> def get_connect_redirect_url ( self , request , socialaccount ) : <EOL> """<STR_LIT>""" <EOL> assert request . user . is_authenticated ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> return url <EOL> def validate_disconnect ( self , account , accounts ) : <EOL> """<STR_LIT>""" <EOL> if len ( accounts ) == <NUM_LIT:1> : <EOL> if not account . user . has_usable_password ( ) : <EOL> raise ValidationError ( _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> if app_settings . EMAIL_VERIFICATION == EmailVerificationMethod . MANDATORY : <EOL> if EmailAddress . objects . filter ( user = account . user , <EOL> verified = True ) . count ( ) == <NUM_LIT:0> : <EOL> raise ValidationError ( _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> def is_auto_signup_allowed ( self , request , sociallogin ) : <EOL> auto_signup = app_settings . AUTO_SIGNUP <EOL> if auto_signup : <EOL> email = user_email ( sociallogin . user ) <EOL> if email : <EOL> if account_settings . UNIQUE_EMAIL : <EOL> if email_address_exists ( email ) : <EOL> auto_signup = False <EOL> elif app_settings . EMAIL_REQUIRED : <EOL> auto_signup = False <EOL> return auto_signup <EOL> def is_open_for_signup ( self , request , sociallogin ) : <EOL> """<STR_LIT>""" <EOL> return get_account_adapter ( request ) . is_open_for_signup ( request ) <EOL> def get_adapter ( request = None ) : <EOL> return import_attribute ( app_settings . ADAPTER ) ( request ) </s>
