You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/08/03 03:19:57 UTC

[GitHub] [dolphinscheduler] CalvinKirs commented on a diff in pull request #11255: [Feature] Add params check in createUser Function

CalvinKirs commented on code in PR #11255:
URL: https://github.com/apache/dolphinscheduler/pull/11255#discussion_r936199135


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java:
##########
@@ -206,9 +206,41 @@ public User createUser(String userName,
         User user = new User();
         Date now = new Date();
 
-        user.setUserName(userName);
-        user.setUserPassword(EncryptionUtils.getMd5(userPassword));
-        user.setEmail(email);
+        if (StringUtils.isNotEmpty(userName)) {
+
+            if (!CheckUtils.checkUserName(userName)) {
+                throw new org.apache.dolphinscheduler.service.exceptions.ServiceException(String.format("userName %s doesn't valid", userName));
+            }
+
+            User tempUser = userMapper.queryByUserNameAccurately(userName);
+            if (tempUser != null) {
+                throw new org.apache.dolphinscheduler.service.exceptions.ServiceException(String.format("userName %s exist", userName));
+            }
+            user.setUserName(userName);
+        }
+
+        if (StringUtils.isNotEmpty(userPassword)) {

Review Comment:
   I think OK, and merging can lead to unclear exception semantics.
   sometimes, code smell needs to be judged based on the actual situation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org