# -*- coding: utf-8 -*- """ api.user ~~~~~~~~~~~~~~ 有关用户操作的接口. :copyright: 云南新八达科技有限公司. :author: 李进才. """ from utils.PageHepler import singleEntityToJson from utils.apiDoc import * # 接口路由 @user.route('/login') class IndexApi(Resource): # @api.marshal_with(return_model,code=200) # @api.expect(return_model) @staticmethod def post(): """ user login :return: user info token """ data = request.json userInfo = DictUser.query.filter_by(UserCode=data['username'], PassWord=data['password']).first() if userInfo is None: return SuccessResponse(ResultCode.USER_LOGIN_ERROR, None, None) return SuccessResponse(ResultCode.SUCCESS, None, generate_jwt_long({'UserName': userInfo.UserName})) @user.route('/info') class UserInfo(Resource): @staticmethod def post(): """ get user info :return: user info """ token = request.headers.get('X-Token') userInfo = DictUser.query.filter_by(UserName=verify_jwt_username(token)).first() if userInfo is None: return BadResponse(ResultCode.INVALID_TOKEN, None, None) return SuccessResponse(ResultCode.SUCCESS, singleEntityToJson(userInfo), None) @user.route('/code') class UserCode(Resource): @staticmethod def post(): data = request.json user_info = DictUser.query.filter_by(UserCode=data['userCode']).first() if user_info is None: return BadResponse(ResultCode.USER_NOT_EXIST, None, None) return SuccessResponse(ResultCode.SUCCESS, {'userName': user_info.UserName}, None)