Skip to content

Commit

Permalink
feat-UserInfoController-增加setPassword接口
Browse files Browse the repository at this point in the history
  • Loading branch information
aruis committed Oct 12, 2024
1 parent c4d0054 commit 9a397ac
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,26 @@ void test() {
.then()
.statusCode(200);

// 修改密码
given()
.header("userID", config.superUserId())
.contentType("application/json")
.body(Map.of(
"v_password", "pw2",
"v_password2", "pw2"
))
.when()
.post("%s/userinfo/setPassword/%s".formatted(base, id))
.then()
.statusCode(200)
.extract()
.asString();

given()
.contentType("application/json")
.body(Map.of(
"username", "test",
"password", "pw",
"password", "pw2",
"code", "muyun"
))
.when()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,29 @@ public String setUser(@PathParam("id") String id, Map<String, Object> params) {
return id;
}

@POST
@Path("/setPassword/{id}")
@Transactional
@Operation(summary = "设置用户密码")
public int setPassword(@PathParam("id") String id, Map<String, Object> params) {
String password = (String) params.get("v_password");
String password2 = (String) params.get("v_password2");

Objects.requireNonNull(password, "必须提供密码");
Objects.requireNonNull(password2, "必须提供二次输入密码");

if (!password.equals(password2)) {
throw new MyException("两次输入的密码不一致");
}

Map<String, ?> userInfo = this.view(id);
if ((boolean) userInfo.get("b_user")) {
return userController.update(id, Map.of("v_password", password));
} else {
throw new MyException("尚未创建对应的用户");
}
}

@Override
@Transactional
public Integer delete(String id) {
Expand All @@ -127,7 +150,6 @@ public Integer delete(String id) {
@Operation(summary = "禁用用户")
public String disableUser(@PathParam("id") String id) {
userController.update(id, Map.of("b_enabled", false));

return id;
}

Expand All @@ -136,7 +158,6 @@ public String disableUser(@PathParam("id") String id) {
@Operation(summary = "启用用户")
public String enableUser(@PathParam("id") String id) {
userController.update(id, Map.of("b_enabled", true));

return id;
}

Expand Down

0 comments on commit 9a397ac

Please sign in to comment.