def get_user_extid(service, userdata): """ Retrieves a 'user', 'extid' and 'useremail' from the given service and userdata. """ provider = login_registry[service] extid = getextid(service=service, userid=userdata['userid']) user = None useremail = None if userdata.get('email'): useremail = UserEmail.get(email=userdata['email']) if extid is not None: user = extid.user # It is possible at this time that extid.user and useremail.user are different. # We do not handle it here, but in the parent function login_service_postcallback. elif useremail is not None and useremail.user is not None: user = useremail.user else: # Cross-check with all other instances of the same LoginProvider (if we don't have a user) # This is (for eg) for when we have two Twitter services with different access levels. for other_service, other_provider in login_registry.items(): if (other_service != service and other_provider.__class__ == provider.__class__): other_extid = getextid(service=other_service, userid=userdata['userid']) if other_extid is not None: user = other_extid.user break # TODO: Make this work when we have multiple confirmed email addresses available return user, extid, useremail
def get_user_extid(service, userdata): """ Retrieves a 'user', 'extid' and 'useremail' from the given service and userdata. """ provider = login_registry[service] extid = getextid(service=service, userid=userdata['userid']) user = None useremail = None if userdata.get('email'): useremail = UserEmail.get(email=userdata['email']) if extid is not None: user = extid.user # It is possible at this time that extid.user and useremail.user are different. # We do not handle it here, but in the parent function login_service_postcallback. elif useremail is not None and useremail.user is not None: user = useremail.user else: # Cross-check with all other instances of the same LoginProvider (if we don't have a user) # This is (for eg) for when we have two Twitter services with different access levels. for other_service, other_provider in login_registry.items(): if other_service != service and other_provider.__class__ == provider.__class__: other_extid = getextid(service=other_service, userid=userdata['userid']) if other_extid is not None: user = other_extid.user break # TODO: Make this work when we have multiple confirmed email addresses available return user, extid, useremail
def get_user_extid(service, userdata): """ Retrieves a 'user', 'extid' and 'useremail' from the given service and userdata. """ provider = login_registry[service] extid = getextid(service=service, userid=userdata['userid']) useremail = None if 'email' in userdata: useremail = UserEmail.query.filter_by(email=userdata['email']).first() user = None if extid is not None: user = extid.user elif useremail is not None: user = useremail.user else: # Cross-check with all other instances of the same LoginProvider (if we don't have a user) # This is (for eg) for when we have two Twitter services with different access levels. for other_service, other_provider in login_registry.items(): if other_service != service and other_provider.__class__ == provider.__class__: other_extid = getextid(service=other_service, userid=userdata['userid']) if other_extid is not None: user = other_extid.user break # TODO: Make this work when we have multiple confirmed email addresses available return user, extid, useremail
def test_getextid(self): """ Test for retrieving user given service and userid """ crusoe = self.fixtures.crusoe email = crusoe.email.email service_facebook = u'facebook' externalid = models.UserExternalId(service=service_facebook, user=crusoe, userid=crusoe.email.email, username=crusoe.email.email, oauth_token=environ.get('FACEBOOK_OAUTH_TOKEN'), oauth_token_type=u'bearer') db.session.add(externalid) db.session.commit() result = models.getextid(service_facebook, userid=email) self.assertIsInstance(result, models.UserExternalId) assert u'<UserExternalId {service}:{username} of {user}>'.format( service=service_facebook, username=email, user=repr(crusoe)[1:-1]) in repr(result)
def test_getextid(self): """ Test for retrieving user given service and userid """ crusoe = self.fixtures.crusoe email = crusoe.email.email service_facebook = u'facebook' externalid = models.UserExternalId( service=service_facebook, user=crusoe, userid=crusoe.email.email, username=crusoe.email.email, oauth_token=environ.get('FACEBOOK_OAUTH_TOKEN'), oauth_token_type=u'bearer') db.session.add(externalid) db.session.commit() result = models.getextid(service_facebook, userid=email) self.assertIsInstance(result, models.UserExternalId) assert u'<UserExternalId {service}:{username} of {user}>'.format( service=service_facebook, username=email, user=repr(crusoe)[1:-1]) in repr(result)