From 4c99585f95cda1839f364524b6f68a16d063ed61 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 2 Apr 2017 22:51:18 +0300 Subject: fix login --- .../main/java/com/juick/www/controllers/Login.java | 176 ++------------------- 1 file changed, 14 insertions(+), 162 deletions(-) (limited to 'juick-www/src/main/java/com/juick/www/controllers') diff --git a/juick-www/src/main/java/com/juick/www/controllers/Login.java b/juick-www/src/main/java/com/juick/www/controllers/Login.java index 2d41d9b4..a83cbc16 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/Login.java +++ b/juick-www/src/main/java/com/juick/www/controllers/Login.java @@ -21,6 +21,9 @@ import com.juick.service.UserService; import com.juick.util.UserUtils; import com.juick.www.Utils; import com.juick.www.WebApp; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -44,170 +47,19 @@ public class Login { WebApp webApp; @RequestMapping(value = "/login", method = RequestMethod.GET) - protected void doGetLoginForm(HttpServletRequest request, HttpServletResponse response) throws IOException { - String hash = request.getQueryString(); - if (hash != null) { - if (hash.length() > 32) { - response.sendError(HttpServletResponse.SC_BAD_REQUEST); - return; - } - - if (userService.getUIDbyHash(hash) > 0) { - Cookie c = new Cookie("hash", hash); - c.setMaxAge(365 * 24 * 60 * 60); - response.addCookie(c); - response.sendRedirect("/"); - } else { - response.sendError(HttpServletResponse.SC_FORBIDDEN); - } - } + protected String doGetLoginForm(HttpServletRequest request, HttpServletResponse response) throws IOException { com.juick.User visitor = UserUtils.getCurrentUser(); - if (visitor.getUid() > 0) { - Utils.sendTemporaryRedirect(response, "/"); - return; + if (!visitor.isAnonymous()) { + return "redirect:/"; } - - response.setContentType("text/html; charset=UTF-8"); - try (PrintWriter out = response.getWriter()) { - out.println(""); - out.println(""); - out.println("
"); - out.println("