From c74bf0135191a35a45a66554a033e1b0335c0d99 Mon Sep 17 00:00:00 2001 From: anda-ren <781905270@qq.com> Date: Wed, 31 Aug 2022 15:50:16 +0800 Subject: [PATCH 1/3] add user name dup validation when create new user --- .../java/ai/starwhale/mlops/domain/user/UserService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/controller/src/main/java/ai/starwhale/mlops/domain/user/UserService.java b/server/controller/src/main/java/ai/starwhale/mlops/domain/user/UserService.java index 109b7bfdcf..5ace5c1d6c 100644 --- a/server/controller/src/main/java/ai/starwhale/mlops/domain/user/UserService.java +++ b/server/controller/src/main/java/ai/starwhale/mlops/domain/user/UserService.java @@ -39,6 +39,8 @@ import ai.starwhale.mlops.exception.SWAuthException.AuthType; import ai.starwhale.mlops.exception.SWProcessException; import ai.starwhale.mlops.exception.SWProcessException.ErrorType; +import ai.starwhale.mlops.exception.SWValidationException; +import ai.starwhale.mlops.exception.SWValidationException.ValidSubject; import ai.starwhale.mlops.exception.api.StarWhaleApiException; import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageHelper; @@ -172,6 +174,10 @@ public PageInfo listUsers(User user, PageParams pageParams) { public Long createUser(User user, String rawPassword) { String salt = saltGenerator.salt(); + UserEntity userByName = userMapper.findUserByName(user.getName());//todo lock this row + if (null != userByName) { + throw new SWValidationException(ValidSubject.USER).tip("user already exists"); + } UserEntity userEntity = UserEntity.builder() .userName(user.getName()) .userPwd(SWPasswordEncoder.getEncoder(salt).encode(rawPassword)) From 39223f253b0ccad211d5bb5f9cf137919c972184 Mon Sep 17 00:00:00 2001 From: dreamlandliu <205407@qq.com> Date: Thu, 1 Sep 2022 18:43:27 +0800 Subject: [PATCH 2/3] Update UserService.java --- .../main/java/ai/starwhale/mlops/domain/user/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/controller/src/main/java/ai/starwhale/mlops/domain/user/UserService.java b/server/controller/src/main/java/ai/starwhale/mlops/domain/user/UserService.java index 8b22827160..4a0a535698 100644 --- a/server/controller/src/main/java/ai/starwhale/mlops/domain/user/UserService.java +++ b/server/controller/src/main/java/ai/starwhale/mlops/domain/user/UserService.java @@ -173,7 +173,7 @@ public PageInfo listUsers(User user, PageParams pageParams) { } - public Long createUser(User user, String rawPassword) { + public Long createUser(User user, String rawPassword, String salt) { UserEntity userByName = userMapper.findUserByName(user.getName());//todo lock this row if (null != userByName) { throw new SWValidationException(ValidSubject.USER).tip("user already exists"); From dbc111cffbd611187e2a5b3b378cf2af9e6343e8 Mon Sep 17 00:00:00 2001 From: dreamlandliu <205407@qq.com> Date: Thu, 1 Sep 2022 18:44:23 +0800 Subject: [PATCH 3/3] Update UserService.java --- .../main/java/ai/starwhale/mlops/domain/user/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/controller/src/main/java/ai/starwhale/mlops/domain/user/UserService.java b/server/controller/src/main/java/ai/starwhale/mlops/domain/user/UserService.java index 4a0a535698..b59f6a2e54 100644 --- a/server/controller/src/main/java/ai/starwhale/mlops/domain/user/UserService.java +++ b/server/controller/src/main/java/ai/starwhale/mlops/domain/user/UserService.java @@ -173,7 +173,7 @@ public PageInfo listUsers(User user, PageParams pageParams) { } - public Long createUser(User user, String rawPassword, String salt) { + public Long createUser(User user, String password, String salt) { UserEntity userByName = userMapper.findUserByName(user.getName());//todo lock this row if (null != userByName) { throw new SWValidationException(ValidSubject.USER).tip("user already exists");