コード例 #1
0
ファイル: token.py プロジェクト: qingxiaoye/yjcloud-learn
def token_get():
    form = LoginForm().validate_for_api()
    identity = QiInfoUser.verify(form.account.data, form.password.data)

    # gen Token
    expiration = current_app.config['TOKEN_EXPIRATION']
    token = generate_auth_token(identity['uid'], identity['ac_type'],
                                identity['scope'], expiration)
    t = {'token': token.decode('ascii')}

    return CreateSuccess(msg='令牌生成', data=t)
コード例 #2
0
def get_token():
    '''生成「令牌」(4种登录方式)'''
    form = ClientValidator().validate_for_api()
    promise = {
        ClientTypeEnum.USERNAME: User.verify_by_username,  # 用户名&密码登录
        ClientTypeEnum.EMAIL: User.verify_by_email,  # 邮箱&密码登录
        ClientTypeEnum.MOBILE: User.verify_by_mobile,  # 手机号&密码登录
        ClientTypeEnum.WX_MINA: User.verify_by_wx_mina,  # 微信·小程序登录
    }
    # 微信登录, 则account为code(需要微信小程序调用wx.login接口获取), secret为空
    identity = promise[ClientTypeEnum(form.type.data)](form.account.data,
                                                       form.secret.data)
    # token生成
    expiration = current_app.config['TOKEN_EXPIRATION']  # token有效期
    token = generate_auth_token(identity['uid'], form.type.data.value,
                                identity['scope'], expiration)
    return Success(data=token)
コード例 #3
0
 def put(self):
     token = generate_auth_token(g.user.id, TOKEN_EXPIRATION)
     return {'token': token}
コード例 #4
0
 def post(self):
     identity = User.verify(**login_parser.parse_args())
     token = generate_auth_token(identity['uid'], TOKEN_EXPIRATION)
     return {'token': token}