You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by li...@apache.org on 2019/12/09 11:06:38 UTC

[incubator-dolphinscheduler] branch dev-db updated: dolphinscheduler-#1403][bug]improve the check rules (#1408)

This is an automated email from the ASF dual-hosted git repository.

lidongdai pushed a commit to branch dev-db
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/dev-db by this push:
     new be4fd58  dolphinscheduler-#1403][bug]improve the check rules (#1408)
be4fd58 is described below

commit be4fd58347ce00b88be1defd2d31fd8c834483b5
Author: zhukai <bo...@qq.com>
AuthorDate: Mon Dec 9 19:06:31 2019 +0800

    dolphinscheduler-#1403][bug]improve the check rules (#1408)
    
    1. When check failed, we don’t know whitch parameter has is wrong, Because username、password、email and phone were checks together. I refactored the check method ,Now it will return failed msg by each field.
    2. The email check regex support [_|\-|\.]?) in createUser.vue, But it do not support in backend server , I fix it, Now they have the same check regex both in frontend and backend
---
 .../dolphinscheduler/api/service/UsersService.java | 36 ++++++++++++++++++++--
 .../apache/dolphinscheduler/common/Constants.java  |  2 +-
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
index 8d27d9e..92319e7 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
@@ -96,8 +96,12 @@ public class UsersService extends BaseService {
                                           String queue) throws Exception {
 
         Map<String, Object> result = new HashMap<>(5);
-        if (!CheckUtils.checkUserParams(userName, userPassword, email, phone)) {
-            putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,userName);
+
+        //check all user params
+        String msg = this.checkUserParams(userName, userPassword, email, phone);
+
+        if (!StringUtils.isEmpty(msg)) {
+            putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,msg);
             return result;
         }
         if (!isAdmin(loginUser)) {
@@ -687,4 +691,32 @@ public class UsersService extends BaseService {
     private boolean checkTenantExists(int tenantId) {
         return tenantMapper.queryById(tenantId) != null ? true : false;
     }
+
+    /**
+     *
+     * @param userName
+     * @param password
+     * @param email
+     * @param phone
+     * @return if check failed return the field, otherwise return null
+     */
+    private String checkUserParams(String userName, String password, String email, String phone) {
+
+        String msg = null;
+        if (!CheckUtils.checkUserName(userName)) {
+
+            msg = userName;
+        } else if (!CheckUtils.checkPassword(password)) {
+
+            msg = password;
+        } else if (!CheckUtils.checkEmail(email)) {
+
+            msg = email;
+        } else if (!CheckUtils.checkPhone(phone)) {
+
+            msg = phone;
+        }
+
+        return msg;
+    }
 }
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
index efcb4e1..352fa96 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
@@ -330,7 +330,7 @@ public final class Constants {
     /**
      * email regex
      */
-    public static final Pattern REGEX_MAIL_NAME = Pattern.compile("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");
+    public static final Pattern REGEX_MAIL_NAME = Pattern.compile("^([a-z0-9A-Z]+[_|\\-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");
 
     /**
      * read permission