diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/juick/www/controllers/Login.java | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/main/java/com/juick/www/controllers/Login.java b/src/main/java/com/juick/www/controllers/Login.java index 8f3e9e9a4..33fcc0111 100644 --- a/src/main/java/com/juick/www/controllers/Login.java +++ b/src/main/java/com/juick/www/controllers/Login.java @@ -19,12 +19,16 @@ package com.juick.www.controllers; import com.juick.model.User; import com.juick.service.UserService; import com.juick.service.security.annotation.Visitor; + +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.WebAttributes; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import javax.inject.Inject; +import javax.servlet.http.HttpSession; /** * @author Ugnich Anton @@ -35,14 +39,21 @@ public class Login { private UserService userService; @GetMapping("/login") - public String getloginForm( - @Visitor User visitor, - @RequestParam(required = false, defaultValue = "true") boolean redirect) { + public String getloginForm(@Visitor User visitor, HttpSession session, + @RequestParam(required = false, defaultValue = "true") boolean redirect, ModelMap model) { if (!visitor.isAnonymous()) { return redirect ? "redirect:/" : "redirect:/login/success"; } - return "views/login"; + AuthenticationException authEx = (AuthenticationException) session + .getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); + + if (authEx != null) { + model.addAttribute("authErrorMessage", authEx.getLocalizedMessage()); + } + + return "layouts/login"; } + @GetMapping("/login/success") public String getSuccessLogin(@Visitor User visitor, ModelMap model) { model.addAttribute("hash", userService.getHashByUID(visitor.getUid())); |