def mergeGoogle():
"""Merges an existing Google account to an existing Facebook account.
"""
form = MergeGoogleForm()
# 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 does exist.
if GoogleModel.doesUserExist(form.googleId.data):
googleUser = GoogleModel.getUser(form.googleId.data)
if UserModel.mergeUsers(g.currentUser['_id'], googleUser['_id']):
return json.dumps({'result':'OK'}), 200
else:
return abort(404)
else:
return abort(401)
return abort(400)
评论列表
文章目录