def authenticate(self, provider, access_token): ''' Authenticate user with the given access_token on the specific provider method. If it returns the user data, try to fetch the user on the database or create user if it doesn`t exist and then return the user object. Otherwise, returns None, meaning invalid authentication parameters. ''' if provider == u'GooglePlus': oauth_user = yield self.authenticate_on_google(access_token) else: oauth_user = None if oauth_user: db = self.application.db user = User.by_email(oauth_user['email'], db) if user: user.last_login = datetime.utcnow() db.flush() db.commit() # FIXME, test if commit() is necessary user.first_login = False else: user = User.add_user(db, oauth_user['fullname'], oauth_user['email'], provider, datetime.utcnow()) user.first_login = True else: user = None raise gen.Return(user)
def authenticate(self, provider, access_token): ''' Authenticate user with the given access_token on the specific provider method. If it returns the user data, try to fetch the user on the database or create user if it doesn`t exist and then return the user object. Otherwise, returns None, meaning invalid authentication parameters. ''' if provider == u'GooglePlus': oauth_user = yield self.authenticate_on_google(access_token) else: oauth_user = None if oauth_user: db = self.application.db user = User.by_email(oauth_user['email'], db) if user: user.last_login = datetime.utcnow() db.flush() db.commit() # FIXME, test if commit() is necessary user.first_login = False else: user = User.add_user( db, oauth_user['fullname'], oauth_user['email'], provider, datetime.utcnow() ) user.first_login = True else: user = None raise gen.Return(user)