示例#1
0
文件: auth.py 项目: pburakov/zenrent
def google_authorized():
    resp = google.authorized_response()
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    if isinstance(resp, OAuthException):
        return 'Access denied: %s' % resp.message

    session['google_token'] = (resp['access_token'], '')
    me = google.get('userinfo')

    user_exists = UserController.email_exists(me.data['email'])
    if user_exists is True:
        user_controller = UserController(email=me.data['email'])
        user_controller.update(idp_tokens={'google': resp})
    else:
        UserController().create(
            type='landlord',
            first_name=me.data['given_name'],
            last_name=me.data['family_name'],
            email=me.data['email'],
            idp_tokens={'google': resp}
        )
    return redirect(url_for('index'))
示例#2
0
文件: auth.py 项目: pburakov/zenrent
def facebook_authorized():
    resp = facebook.authorized_response()
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    if isinstance(resp, OAuthException):
        return 'Access denied: %s' % resp.message
    session['facebook_token'] = (resp['access_token'], '')
    me = facebook.get('me?fields=id,name,picture{is_silhouette,url},email')
    user_exists = UserController.email_exists(me.data['email'])
    if user_exists is True:
        user = UserController(email=me.data['email'])
        user.update(idp_tokens={'facebook': resp})
    else:
        if type(me.data['name']) is str:
            first_name = me.data['name'].split()[0]
            last_name = me.data['name'].split()[1]

        UserController().create(
            type='landlord',
            first_name=first_name,
            last_name=last_name,
            email=me.data['email'],
            idp_tokens={'facebook': resp}
        )
    return redirect(url_for('index'))