def query_account_info_by_name(name): """ @api {GET} /account/query_by_name/<name> 根据用户名查询用户账户信息 @apiGroup Users @apiVersion 0.0.1 @apiDescription 根据用户名查询用户账户信息 @apiSuccess (200) {String} msg 信息 @apiSuccess (200) {int} code 0 代表无错误 1代表有错误 @apiSuccessExample {json} 返回样例: { "status": "ok", "payload":{ "user_id": "132", "balance": "1283.23", "bonus_point": "3000", "discount": "0.75" } } @apiError (400) {String} msg 信息 @apiErrorExample {json} 返回样例: {"status": "fail", "message": "用户不存在"} """ user = UserService.query_user_by_name(username=name) if user is None: return make_api_response(message="用户不存在", statusCode=400) user_id = user.get('id', 0) account_info = AccountService.account_query(user_id=user_id) if account_info: return make_api_response(payload=account_info) else: return make_api_response(message="用户不存在", statusCode=400)
def query_user_info(username): """ @api {GET} /user/query/<username> 根据用户名查询用户信息 @apiGroup Users @apiVersion 0.0.1 @apiDescription 根据用户名查询用户信息 @apiSuccess (200) {String} msg 信息 @apiSuccess (200) {int} code 0 代表无错误 1代表有错误 @apiParam {String} username 用户账户名 @apiSuccessExample {json} 返回样例: { "status": "ok", "payload":{ "id": 123, "realname": "132", "username": "******", "phone": "pwd", "mail": "*****@*****.**", "nickname": "guest", "gender": "23", "password": "******", "qq": "12312" } } @apiError (400) {String} msg 信息 @apiErrorExample {json} 返回样例: {"status": "fail", "message": "用户不存在"} """ user_id = current_user.id userinfo = UserService.query_user_by_name(username=username) if userinfo: return make_api_response(payload=userinfo) else: return make_api_response(message="用户不存在", statusCode=400)
def register(): """ @api {POST} /register 注册用户 @apiGroup Users @apiVersion 0.0.1 @apiDescription 用于注册用户 @apiParam {String} username 用户账户名 @apiParam {String} nickname 昵称 @apiParam {String} realname 真实姓名 @apiParam {String} password 密码 @apiParam {String} pwdquestion 密码提示问题 @apiParam {String} pwdanswer 密码提示问题答案 @apiParam {String} gender 性别 @apiParam {String} mail 邮箱 @apiParam {String} phone 联系电话 @apiParam {String} qq QQ @apiParamExample {json} 请求样例: { "username": "******", "nickname": "guest", "realname": "132", "password": "******", "pwdquestion": "none", "pwdanswer": "none", "gender": "23", "mail": "*****@*****.**", "phone": 1231232, "qq":12312 } @apiSuccess (200) {String} msg 信息 @apiSuccess (200) {int} code 0 代表无错误 1代表有错误 @apiSuccessExample {json} 返回样例: {"status":"ok", "message": ""} @apiError (400) {String} msg 信息 @apiErrorExample {json} 返回样例: {"status": "fail", "message": "参数错误:缺少用户名或密码"} {"status": "fail", "message": "参数错误:用户名已存在"} """ # 获取参数 user_name = request.json['username'] display_name = request.json['nickname'] real_name = request.json['realname'] password = request.json['password'] pwd_question = request.json['pwdquestion'] pwd_answer = request.json['pwdanswer'] gender = request.json['gender'] mail = request.json['mail'] phone = request.json['phone'] qq = request.json['qq'] if not user_name or not password: return make_api_response(message='参数错误:缺少用户名或密码', statusCode=400) user = UserService.query_user_by_name(username=user_name) logger.debug(user) if user is not None: return make_api_response(message='用户名已存在', statusCode=400) userinfo = { 'username': user_name, 'nickname': display_name, 'realname': real_name, 'password': password, 'question': pwd_question, 'answer': pwd_answer, 'gender': gender, 'mail': mail, 'phone': phone, 'qq': qq } # 创建用户的操作 ok = UserService.create_user(userinfo) db.session.commit() return make_api_response()