Exemple #1
0
def get_current_member():
    identity = get_jwt_identity()
    if identity['scope'] != 'zcx':
        raise AuthFailed()
    remote_addr = identity.get('remote_addr')
    if remote_addr and remote_addr != request.remote_addr:
        raise AuthFailed()
    # token is granted , member must be exit
    # 如果token已经被颁发,则该用户一定存在
    member = Member.get(id=identity['uid'], one=True)
    if member is None:
        raise NotFound(msg='会员不存在')
    if not member.is_active:
        raise AuthFailed(msg='您目前处于未激活状态,请联系超级管理员')
    return member
Exemple #2
0
def get():
    form = MemberLoginForm().validate_for_api()
    openid = WxHelper.get_openid(form.code.data)
    if openid:
        member = Member.get(one=True, openid=openid)
        if not member:
            member = Member.create(openid=openid,
                                   nickName=form.nickName.data,
                                   avatarUrl=form.avatarUrl.data,
                                   gender=form.gender.data,
                                   country=form.country.data,
                                   province=form.province.data,
                                   city=form.city.data,
                                   commit=True)
        access_token, refresh_token = get_member_tokens(member)
    else:
        raise WxCodeException()

    return jsonify({
        'access_token': access_token,
        'refresh_token': refresh_token
    })