def patch(uid=None): if not check_utils.check_param_format( request.path, [r"^/v1/bms/user/([1-9][0-9]*)/password/$"]): return status_code.URL_ERROR try: user_service = UserService() new_password = get_reset_password() user_service.update_user_password(user_id=uid, new_password=new_password) result = status_code.SUCCESS result["new_password"] = new_password 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