<s> from social . exceptions import AuthAlreadyAssociated , AuthException , AuthForbidden <EOL> def social_details ( backend , details , response , * args , ** kwargs ) : <EOL> return { '<STR_LIT>' : dict ( backend . get_user_details ( response ) , ** details ) } <EOL> def social_uid ( backend , details , response , * args , ** kwargs ) : <EOL> return { '<STR_LIT>' : backend . get_user_id ( details , response ) } <EOL> def auth_allowed ( backend , details , response , * args , ** kwargs ) : <EOL> if not backend . auth_allowed ( response , details ) : <EOL> raise AuthForbidden ( backend ) <EOL> def social_user ( backend , uid , user = None , * args , ** kwargs ) : <EOL> provider = backend . name <EOL> social = backend . strategy . storage . user . get_social_auth ( provider , uid ) <EOL> if social : <EOL> if user and social . user != user : <EOL> msg = '<STR_LIT>' . format ( provider ) <EOL> raise AuthAlreadyAssociated ( backend , msg ) <EOL> elif not user : <EOL> user = social . user <EOL> return { '<STR_LIT>' : social , <EOL> '<STR_LIT:user>' : user , <EOL> '<STR_LIT>' : user is None , <EOL> '<STR_LIT>' : False } <EOL> def associate_user ( backend , uid , user = None , social = None , * args , ** kwargs ) : <EOL> if user and not social : <EOL> try : <EOL> social = backend . strategy . storage . user . create_social_auth ( <EOL> user , uid , backend . name <EOL> ) <EOL> except Exception as err : <EOL> if not backend . strategy . storage . is_integrity_error ( err ) : <EOL> raise <EOL> return social_user ( backend , uid , user , * args , ** kwargs ) <EOL> else : <EOL> return { '<STR_LIT>' : social , <EOL> '<STR_LIT:user>' : social . user , <EOL> '<STR_LIT>' : True } <EOL> def associate_by_email ( backend , details , user = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if user : <EOL> return None <EOL> email = details . get ( '<STR_LIT:email>' ) <EOL> if email : <EOL> users = list ( backend . strategy . storage . user . get_users_by_email ( email ) ) <EOL> if len ( users ) == <NUM_LIT:0> : <EOL> return None <EOL> elif len ( users ) > <NUM_LIT:1> : <EOL> raise AuthException ( <EOL> backend , <EOL> '<STR_LIT>' <EOL> ) <EOL> else : <EOL> return { '<STR_LIT:user>' : users [ <NUM_LIT:0> ] } <EOL> def load_extra_data ( backend , details , response , uid , user , * args , ** kwargs ) : <EOL> social = kwargs . get ( '<STR_LIT>' ) or backend . strategy . storage . user . get_social_auth ( backend . name , uid ) <EOL> if social : <EOL> extra_data = backend . extra_data ( user , uid , response , details , <EOL> * args , ** kwargs ) <EOL> social . set_extra_data ( extra_data ) </s>
