def __check_order_valid(self): '''对订单作三种情况的检测''' # 1. 验证订单号是否存在 order = OrderModel.query.filter_by(id=self.order_id)\ .first_or_404(e=OrderException) # 2. 如果订单号存在的,验证订单号与当前用户是否匹配 if not Token.is_valid_operate(order.user_id): raise TokenException(msg='订单与用户不匹配', error_code=1003) # 3. 验证订单是否已经被支付过 if order.order_status != OrderStatusEnum.UNPAID: raise OrderException(msg='订单已支付', error_code=8003, code=404) self.order_no = order.order_no return True
def get_token(): '''生成「令牌」''' form = ClientValidator().validate_for_api() promise = { ClientTypeEnum.USER_EMAIL: User.verify_by_email, ClientTypeEnum.USER_WX: User.verify_by_wx, } # 微信登录则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 = Token.generate_auth_token(identity['uid'], form.type.data, identity['scope'], expiration) return Success(data=token)
def get_token(): '''生成「令牌」(4种登录方式)''' form = ClientValidator().validate_for_api() promise = { ClientTypeEnum.EMAIL: User.verify_by_email, # 邮箱&密码登录 ClientTypeEnum.MOBILE: User.verify_by_mobile, # 手机号&密码登录 ClientTypeEnum.WX_MINA: User.verify_by_wx_mina, # 微信小程序登录 ClientTypeEnum.WX_OPEN: User.verify_by_wx_open # 微信开发平台登录(微信扫码登录) } # 微信登录, 则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 = Token.generate_auth_token(identity['uid'], form.type.data, identity['scope'], expiration) return Success(data=token)
def get_token_info(): """解析「令牌」""" token = TokenValidator().validate_for_api().token.data result = Token.decrypt(token) return Success(data=result)