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