aboutsummaryrefslogtreecommitdiff
path: root/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java')
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java
new file mode 100644
index 00000000..338dc9be
--- /dev/null
+++ b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java
@@ -0,0 +1,52 @@
+package com.juick.www.controllers;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.regex.Pattern;
+
+/**
+ * Created by aalexeev on 11/21/16.
+ */
+@Controller
+public class ShowMessageController {
+ private static final Pattern USER_NAME_PATTERN = Pattern.compile("[a-zA-Z-_\\d]{2,16}");
+
+ private static final Pattern POST_NUMBER_PATTERN = Pattern.compile("\\d+");
+
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+
+
+ @RequestMapping("/{anything}")
+ public String parseAnything(
+ @PathVariable String anything,
+ @RequestParam(required = false, defaultValue = "0") int before,
+ Model model) {
+
+ boolean isUsername = USER_NAME_PATTERN.matcher(anything).matches();
+ boolean isPostNumber = POST_NUMBER_PATTERN.matcher(anything).matches();
+
+ return "redirect:/";
+ }
+
+ @RequestMapping("/{userName}/{postNumber}")
+ public String checkShowPost(
+ @PathVariable String userName,
+ @PathVariable String postNumber,
+ @RequestParam(required = false, defaultValue = "0") int before,
+ Model model) {
+
+ if (!USER_NAME_PATTERN.matcher(userName).matches() ||
+ !POST_NUMBER_PATTERN.matcher(postNumber).matches()) {
+ logger.warn("Invalid user name or post number, user name \"{}\", post number \"{}\"", userName, postNumber);
+ return "redirect:/";
+ }
+
+ return "index";
+ }
+}