def authorize(self, user = None, login=True): if self.user is None: if user is None: raise TypeError self.user = user """Guarda el token de autorizacion""" if self.user is not None:#el usuario ya esta conectado, pero pide permisos if OAUTH_Access.get_token(self.token.key) is None: OAUTH_Access.remove_token(self.user, 'twitter') access = OAUTH_Access.add_token( token_key=self.token.key, token_secret=self.token.secret, provider='twitter', user=self.user, ) if login: twitterInfo = self.get_user_info() if self.user.twitter_user is None: TwitterUser.register(user=self.user, uid=twitterInfo['id'], username = twitterInfo['screen_name'], realname = twitterInfo['name'], picurl = twitterInfo['profile_image_url'], ) else: self.user.twitter_user.update( username = twitterInfo['screen_name'], realname = twitterInfo['name'], picurl = twitterInfo['profile_image_url'] ) return True return False
def authorize(self, user=None): """Guarda el token de autorizacion""" if user is not None:#el usuario ya esta conectado, pero pide permisos if OAUTH_Access.get_token(self.token.key) is None: OAUTH_Access.remove_token(user, 'google') access = OAUTH_Access.add_token( token_key=self.token.key, token_secret=self.token.secret, provider='google', user=user, ) return True return False
def authorize(self, user=None): """Guarda el token de autorizacion""" if user is not None: #el usuario ya esta conectado, pero pide permisos if OAUTH_Access.get_token(self.token.key) is None: OAUTH_Access.remove_token(user, 'google') access = OAUTH_Access.add_token( token_key=self.token.key, token_secret=self.token.secret, provider='google', user=user, ) return True return False
def authorize(self, user): """guarda el token de autorizacion""" if user is not None:#el usuario ya esta conectado, pero pide permisos token = OAUTH_Access.get_token(self.consumer.access_token) if token is None: OAUTH_Access.remove_token(user, 'facebook') token = OAUTH_Access.add_token( token_key=self.consumer.access_token, token_secret='', provider='facebook', user=user, ) else: token.user = user token.put() self.consumer = GraphAPI(access_token=token.token_key) facebookInfo = self.get_user_info() if user.facebook_user is None: fbuser = FacebookUser.register(user=user, uid=facebookInfo['id'], email=facebookInfo.get('email', None), realname=facebookInfo["name"], profile_url=facebookInfo["link"], access_token=self.consumer.access_token) else: user.facebook_user.update( uid=facebookInfo['id'], realname = facebookInfo['name'], profile_url=facebookInfo["link"], ) self.user = user self.token = token import memcache memclient = memcache.mem.Client() token_cache = {'token': token, 'user': self.user } memclient.set('%sfbclienttoken_%s' % (memcache.version, self.consumer.access_token ), token_cache) memclient.set('%sfbclientuser_%s' % (memcache.version, user.id ), memcache.serialize_instances(token) ) return True return False
def authorize(self, user): """guarda el token de autorizacion""" if user is not None: #el usuario ya esta conectado, pero pide permisos token = OAUTH_Access.get_token(self.consumer.access_token) if token is None: OAUTH_Access.remove_token(user, 'facebook') token = OAUTH_Access.add_token( token_key=self.consumer.access_token, token_secret='', provider='facebook', user=user, ) else: token.user = user token.put() self.consumer = GraphAPI(access_token=token.token_key) facebookInfo = self.get_user_info() if user.facebook_user is None: fbuser = FacebookUser.register( user=user, uid=facebookInfo['id'], email=facebookInfo.get('email', None), realname=facebookInfo["name"], profile_url=facebookInfo["link"], access_token=self.consumer.access_token) else: user.facebook_user.update( uid=facebookInfo['id'], realname=facebookInfo['name'], profile_url=facebookInfo["link"], ) self.user = user self.token = token import memcache memclient = memcache.mem.Client() token_cache = {'token': token, 'user': self.user} memclient.set( '%sfbclienttoken_%s' % (memcache.version, self.consumer.access_token), token_cache) memclient.set('%sfbclientuser_%s' % (memcache.version, user.id), memcache.serialize_instances(token)) return True return False