本文整理汇总了Python中model.user.User.generate_auth_token方法的典型用法代码示例。如果您正苦于以下问题:Python User.generate_auth_token方法的具体用法?Python User.generate_auth_token怎么用?Python User.generate_auth_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.user.User
的用法示例。
在下文中一共展示了User.generate_auth_token方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import generate_auth_token [as 别名]
def post(self):
"""
Sign up with Facebook account and return a token
"""
args = fbUserParser.parse_args()
fb_id = args['fbid']
fb_token = args['fbtoken']
fb_email = args['fbemail']
if fb_id is None or fb_token is None or fb_email is None:
abort(400)
# verify the user's facebook account using the facebook token
fbuser_info = requests.get(
'https://graph.facebook.com/me?access_token=%s' % fb_token).json()
if not fbuser_info.get('id') or fb_id != fbuser_info['id']:
abort(406)
user = User(email=fb_email, fb_id=fb_id)
try:
user.save()
except:
return {'status': 'error', 'message': 'FBname has already existed'}
token = user.generate_auth_token(expiration=360000)
redis_store.set(str(user.id), token)
return ({'status': 'success', 'token': token}, 201)
示例2: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import generate_auth_token [as 别名]
def post(self):
args = fbUserParser.parse_args()
fb_id = args['fbid']
fb_token = args['fbtoken']
if fb_id is None or fb_token is None:
abort(400)
fbuser_info = requests.get('https://graph.facebook.com/me?access_token=%s' %fb_token).json()
if not fbuser_info.get('id') or fb_id != fbuser_info['id']:
raise InvalidUsage('User info does not match',406)
fb_email = args['fbemail']
user = User.objects(email=fb_email).first()
if user is None:
user = User(email=fb_email, fb_id=fbuser_info['id'])
user.save()
profile = Profile.objects(user=user).first()
if profile is None:
profile = Profile(user=user)
profile.save()
rongToken = rongcloudToken(profile.id)
token = user.generate_auth_token()
redis_store.set(str(user.id), token)
return {'token': token, 'rongToken' : rongToken}