From 47d7e0e533687b204e6c781f0dce57ca54e01348 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 7 Apr 2017 11:01:29 +0300 Subject: juick-www: refactoring, drop userref shit --- .../java/com/juick/www/controllers/SignUp.java | 47 +++++++--------------- 1 file changed, 14 insertions(+), 33 deletions(-) (limited to 'juick-www/src/main/java/com/juick/www/controllers/SignUp.java') diff --git a/juick-www/src/main/java/com/juick/www/controllers/SignUp.java b/juick-www/src/main/java/com/juick/www/controllers/SignUp.java index d07c3227..4746292b 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/SignUp.java +++ b/juick-www/src/main/java/com/juick/www/controllers/SignUp.java @@ -23,16 +23,15 @@ import com.juick.service.CrosspostService; import com.juick.service.MessagesService; import com.juick.service.UserService; import com.juick.util.UserUtils; -import com.juick.www.Utils; import com.juick.www.WebApp; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; import javax.inject.Inject; import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** @@ -53,13 +52,11 @@ public class SignUp { @GetMapping("/signup") - protected String doGet(HttpServletRequest request, HttpServletResponse response, ModelMap model) { + protected String doGet(@RequestParam String type, @RequestParam String hash, ModelMap model) { com.juick.User visitor = UserUtils.getCurrentUser(); - String type = request.getParameter("type"); - String hash = request.getParameter("hash"); - if (type == null || type.isEmpty() || hash == null || hash.isEmpty() || hash.length() > 36 - || !type.matches("^[a-zA-Z0-9\\-]+$") || !hash.matches("^[a-zA-Z0-9\\-]+$")) { + if (hash.length() > 36 || !type.matches("^[a-zA-Z0-9\\-]+$") + || !hash.matches("^[a-zA-Z0-9\\-]+$")) { throw new HttpBadRequestException(); } @@ -92,23 +89,24 @@ public class SignUp { } @PostMapping("/signup") - protected String doPost(HttpServletRequest request, HttpServletResponse response) { + protected String doPost( + HttpServletResponse response, + @RequestParam String type, + @RequestParam String hash, + @RequestParam String action, + @RequestParam String username, + @RequestParam String password) { com.juick.User visitor = UserUtils.getCurrentUser(); int uid = 0; - String type = request.getParameter("type"); - String hash = request.getParameter("hash"); - if (type == null || type.isEmpty() || hash == null || hash.isEmpty() || hash.length() > 36 || !type.matches("^[a-zA-Z0-9\\-]+$") || !hash.matches("^[a-zA-Z0-9\\-]+$")) { + if (hash.length() > 36 || !type.matches("^[a-zA-Z0-9\\-]+$") || !hash.matches("^[a-zA-Z0-9\\-]+$")) { throw new HttpBadRequestException(); } - String action = request.getParameter("action"); if (action.charAt(0) == 'l') { if (visitor.getUid() == 0) { - String username = request.getParameter("username"); - String password = request.getParameter("password"); - if (username == null || password == null || username.length() > 32 || password.isEmpty()) { + if (username.length() > 32) { throw new HttpBadRequestException(); } uid = userService.checkPassword(username, password); @@ -128,9 +126,7 @@ public class SignUp { } } else { // Create new account - String username = request.getParameter("username"); - String password = request.getParameter("password"); - if (username == null || password == null || username.length() < 2 || username.length() > 16 || !username.matches("^[a-zA-Z0-9\\-]+$") || password.length() < 6 || password.length() > 32) { + if (username.length() < 2 || username.length() > 16 || !username.matches("^[a-zA-Z0-9\\-]+$") || password.length() < 6 || password.length() > 32) { throw new HttpBadRequestException(); } @@ -147,21 +143,6 @@ public class SignUp { && !(type.charAt(0) == 'x' && crosspostService.setJIDUser(hash, uid))) { throw new HttpBadRequestException(); } - - int ref = 0; - String sRef = Utils.getCookie(request, "ref"); - if (sRef != null) { - try { - ref = Integer.parseInt(sRef); - } catch (Exception e) { - } - } - - if (ref > 0) { - crosspostService.setUserRef(uid, ref); - } - - visitor = null; } if (visitor == null) { -- cgit v1.2.3