Ejemplo n.º 1
0
def bind_weixin_authorized():
    text = ''
    show_btn = True
    next_url = request.args.get('next', '/')
    response = weixin.authorized_response()
    if not response:
        current_app.logger.debug('weixin login has been denied by user')
        return redirect(next_url)  # denied by user

    if not g.user:
        login_url = url_for('.login', next=url_for('.weixin_auth'))
        current_app.logger.debug('need login first: %r' % login_url)
        return redirect(login_url)

    openid = response.get('openid')

    if not openid:
        return redirect(next_url)  # denied by user

    account = Account.get_by_alias_type(openid, ACCOUNT_REG_TYPE.WEIXIN_OPENID)

    if account:
        if account.id != g.user.id:
            logout_user()
            if account.has_mobile():
                binded_account = account.mobile[
                    :4] + '*' * 4 + account.mobile[-4:]
            elif account.has_email():
                username, domain = account.email.split('@')
                binded_account = username[:3] + '*' * 4 + '@' + domain
            text = '您的账号已经与' + binded_account + '绑定,请先解绑'
        else:
            text = '您已经绑定过了,无需重新绑定'
    else:
        # bind the current openid
        current_app.logger.debug('bind current weixin alias')
        g.user.add_alias(openid, ACCOUNT_REG_TYPE.WEIXIN_OPENID)
        text = '绑定成功'

    return render_template('accounts/weixin_bind_result.html', **locals())
Ejemplo n.º 2
0
def unbind_weixin():
    text = ''
    show_btn = True

    if not request.user_agent.is_weixin_browser:
        return Response('this is not a weixin broswer')

    if request.method == 'POST':
        if not g.user:
            login_url = url_for('.login', next=url_for('.unbind_weixin'))
            return redirect(login_url)
        weixin_openid = g.user.weixin_openid
        if weixin_openid:
            g.user.remove_alias(ACCOUNT_REG_TYPE.WEIXIN_OPENID, weixin_openid)
            current_app.logger.debug('unbind success')
            text = '解绑成功'
            logout_user()
            show_btn = False
        else:
            text = '您的账号没有绑定微信'
    else:
        text = '解绑账号'

    return render_template('accounts/weixin_bind_result.html', **locals())
Ejemplo n.º 3
0
def logout():
    if g.user:
        logout_user()
    return '', 200
Ejemplo n.º 4
0
def logout_savings():
    if g.user:
        logout_user()
    return redirect(url_for('savings.landing.index', _external=True))
Ejemplo n.º 5
0
def logout():
    if g.user:
        logout_user()
    return redirect('/accounts/login')