aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexander Alexeev2016-12-11 00:00:35 +0700
committerGravatar Vitaly Takmazov2016-12-11 18:24:37 +0300
commit5ff660e5f3e73382781f854a0afc350d2ad6d626 (patch)
treeab6ab4447c08d80dd3aa467daee3080b1b775395
parentb1861f326a834865f1d700745dfb5f1b1596ba1f (diff)
duplicated util method is removed
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/PM.java3
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/Users.java4
-rw-r--r--juick-server/src/main/java/com/juick/util/UserUtils.java4
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/PMController.java9
-rw-r--r--juick-www/src/main/java/com/juick/www/PM.java6
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<com.juick.Message> 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<com.juick.Message> 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);
}