From 5ff660e5f3e73382781f854a0afc350d2ad6d626 Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Sun, 11 Dec 2016 00:00:35 +0700 Subject: duplicated util method is removed --- juick-api/src/main/java/com/juick/api/controllers/PM.java | 3 ++- juick-api/src/main/java/com/juick/api/controllers/Users.java | 4 ++-- juick-server/src/main/java/com/juick/util/UserUtils.java | 4 ---- .../src/main/java/com/juick/www/controllers/PMController.java | 9 ++++----- juick-www/src/main/java/com/juick/www/PM.java | 6 +++--- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/juick-api/src/main/java/com/juick/api/controllers/PM.java b/juick-api/src/main/java/com/juick/api/controllers/PM.java index ffbea4b5..478ca75e 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/PM.java +++ b/juick-api/src/main/java/com/juick/api/controllers/PM.java @@ -7,6 +7,7 @@ import com.juick.server.util.HttpForbiddenException; import com.juick.service.PMQueriesService; import com.juick.service.UserService; import com.juick.util.UserUtils; +import com.juick.util.WebUtils; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -69,7 +70,7 @@ public class PM { throw new HttpForbiddenException(); } int uid = 0; - if (UserUtils.checkUserNameValid(uname)) { + if (WebUtils.isUserName(uname)) { uid = userService.getUIDbyName(uname); } diff --git a/juick-api/src/main/java/com/juick/api/controllers/Users.java b/juick-api/src/main/java/com/juick/api/controllers/Users.java index d6035cf2..78f6175f 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/Users.java +++ b/juick-api/src/main/java/com/juick/api/controllers/Users.java @@ -68,7 +68,7 @@ public class Users { if (uname == null) { uid = vuid; } else { - if (UserUtils.checkUserNameValid(uname)) { + if (WebUtils.isUserName(uname)) { com.juick.User u = userService.getUserByName(uname); if (u != null && u.getUid() > 0) { uid = u.getUid(); @@ -102,7 +102,7 @@ public class Users { if (uname == null) { uid = vuid; } else { - if (UserUtils.checkUserNameValid(uname)) { + if (WebUtils.isUserName(uname)) { com.juick.User u = userService.getUserByName(uname); if (u != null && u.getUid() > 0) { uid = u.getUid(); diff --git a/juick-server/src/main/java/com/juick/util/UserUtils.java b/juick-server/src/main/java/com/juick/util/UserUtils.java index 372dd502..ba1bd1ab 100644 --- a/juick-server/src/main/java/com/juick/util/UserUtils.java +++ b/juick-server/src/main/java/com/juick/util/UserUtils.java @@ -22,10 +22,6 @@ public class UserUtils { return sb.toString(); } - public static boolean checkUserNameValid(final String uname) { - return uname != null && uname.length() >= 2 && uname.length() <= 16 && uname.matches("[a-zA-Z0-9\\-]+"); - } - public static String getUsername(final Principal principal, final String defaultUsername) { return principal == null ? defaultUsername : principal.getName(); } diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/PMController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/PMController.java index c3b37cf6..15a93684 100644 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/PMController.java +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/PMController.java @@ -9,6 +9,7 @@ import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.util.MessageUtils; import com.juick.util.UserUtils; +import com.juick.util.WebUtils; import com.juick.www.WebApp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,7 +29,6 @@ import java.util.List; */ @Controller public class PMController { - private static final Logger logger = LoggerFactory.getLogger(PMController.class); @Inject @@ -64,7 +64,7 @@ public class PMController { User visitor = userService.getUserByName(name); List msgs = pmQueriesService.getLastPMSent(visitor.getUid()); - if (!UserUtils.checkUserNameValid(uname)) { + if (WebUtils.isNotUserName(uname)) { uname = ""; } context.put("title", title); @@ -87,7 +87,7 @@ public class PMController { uname = uname.substring(1); } int uid = 0; - if (UserUtils.checkUserNameValid(uname)) { + if (WebUtils.isUserName(uname)) { uid = userService.getUIDbyName(uname); } @@ -131,8 +131,7 @@ public class PMController { logger.warn("XMPP unavailable"); } return "redirect:/pm/sent"; - } else { - throw new HttpBadRequestException(); } + throw new HttpBadRequestException(); } } diff --git a/juick-www/src/main/java/com/juick/www/PM.java b/juick-www/src/main/java/com/juick/www/PM.java index 78dbff10..d11de239 100644 --- a/juick-www/src/main/java/com/juick/www/PM.java +++ b/juick-www/src/main/java/com/juick/www/PM.java @@ -21,7 +21,7 @@ import com.juick.server.PMQueries; import com.juick.server.TagQueries; import com.juick.server.UserQueries; import com.juick.util.MessageUtils; -import com.juick.util.UserUtils; +import com.juick.util.WebUtils; import com.mitchellbosecke.pebble.error.PebbleException; import com.mitchellbosecke.pebble.template.PebbleTemplate; import org.slf4j.Logger; @@ -70,7 +70,7 @@ public class PM { List msgs = PMQueries.getLastPMSent(sql, visitor.getUid()); String uname = request.getParameter("uname"); - if (!UserUtils.checkUserNameValid(uname)) { + if (WebUtils.isNotUserName(uname)) { uname = ""; } @@ -93,7 +93,7 @@ public class PM { uname = uname.substring(1); } int uid = 0; - if (UserUtils.checkUserNameValid(uname)) { + if (WebUtils.isUserName(uname)) { uid = UserQueries.getUIDbyName(sql, uname); } -- cgit v1.2.3