From b4608708f6f0f2e0d8ae846da3c490cf894d2b46 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 25 Mar 2021 16:32:55 +0300 Subject: login page refactoring * drop jQuery * merge styles * show login error message --- src/main/java/com/juick/www/controllers/Login.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/juick/www/controllers/Login.java b/src/main/java/com/juick/www/controllers/Login.java index 8f3e9e9a..33fcc011 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())); -- cgit v1.2.3