def linkFacebook():
"""Links a Facebook account to an existing Google account.
"""
form = LinkFacebookForm()
# Check if the Service-Provider is Google
if form.validate_on_submit() and g.loginWith == 'Google' and g.currentUser['facebookId'] is None:
facebookToken = FacebookModel.getTokenValidation(app.config['FACEBOOK_ACCESS_TOKEN'], form.token.data)
if facebookToken['is_valid'] and facebookToken['user_id'] == form.facebookId.data:
# Continue only if the account doesn't exist yet.
if not FacebookModel.doesUserExist(form.facebookId.data):
if FacebookModel.linkToUserId(g.currentUser['_id'], form.facebookId.data):
return json.dumps({'result':'OK'}), 200
else:
return abort(403)
else:
return abort(401)
return abort(400)
评论列表
文章目录