def put(uid=None): if not check_utils.check_param_format( request.path, [r"^/v1/bms/user/([1-9][0-9]*)/$"]): return status_code.URL_ERROR data = request.json if not (data and isinstance(data, dict)): return status_code.JSON_PARAMS_ERROR if not data.get("phone"): return { "code": status_code.REQUIRED_PARAM_CODE, "msg_cn": status_code.REQUIRED_PARAM_MSG_CN.format("电话号码"), "msg_en": status_code.REQUIRED_PARAM_MSG_EN.format("phone") } try: user_service = UserService() user = user_service.get_user_by_id(user_id=uid) if not user: return status_code.USER_NOT_EXIST user_service.update_user_basic(user_id=uid, phone=data.get("phone"), username=data.get("username"), gender=data.get("gender"), email=data.get("email"), birth=data.get("birth")) return status_code.SUCCESS except Exception as ex: print(ex) logger.error("修改用户基础信息失败,{}".format(ex)) return status_code.FAIL
def wrapper(*args, **kwargs): if not (session and session.get("user_id") and session.get("token")): return status_code.USER_NO_LOGIN try: user_service = UserService() user = user_service.get_user_by_id(session.get("user_id")) if not user: return status_code.USER_NOT_EXIST if not user.get("is_active"): return status_code.USER_IS_NOT_ACTIVE if user.get("token") != session.get("token"): return status_code.PLEASE_LOGIN except Exception as ex: print(ex) logger.error("认证失败,{}".format(ex)) return status_code.FAIL return func(*args, **kwargs)
def get(uid=None): if not check_utils.check_param_format( request.path, [r"^/v1/bms/user/([1-9][0-9]*)/$", r"^/v1/bms/user/$"]): return status_code.URL_ERROR try: user_service = UserService() if uid: user = user_service.get_user_by_id(user_id=uid) if not user: return status_code.USER_NOT_EXIST result = status_code.SUCCESS result["data"] = user return result else: users = user_service.get_users() result = status_code.SUCCESS result["data"] = users return result except Exception as ex: print(ex) logger.error("获取用户失败,{}".format(ex)) return status_code.FAIL
def patch(): if not check_utils.check_param_format(request.path, [r"^/v1/bms/user/password/$"]): return status_code.URL_ERROR user_id = session.get("user_id") data = request.json if not (data and isinstance(data, dict)): return status_code.JSON_PARAMS_ERROR if not data.get("old_password"): return { "code": status_code.REQUIRED_PARAM_CODE, "msg_cn": status_code.REQUIRED_PARAM_MSG_CN.format("原密码"), "msg_en": status_code.REQUIRED_PARAM_MSG_EN.format("old password") } if not data.get("new_password"): return { "code": status_code.REQUIRED_PARAM_CODE, "msg_cn": status_code.REQUIRED_PARAM_MSG_CN.format("新密码"), "msg_en": status_code.REQUIRED_PARAM_MSG_EN.format("new password") } try: user_service = UserService() user = user_service.get_user_by_id(user_id=user_id) if not user: return status_code.USER_NOT_EXIST if not user_service.check_user_password( user_id=user_id, password=data.get("old_password")): return status_code.PASSWORD_ERROR user_service.update_user_password( user_id=user_id, new_password=data.get("new_password")) return status_code.SUCCESS except Exception as ex: print(ex) logger.error("修改用户密码失败,{}".format(ex)) return status_code.FAIL