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 +- src/main/resources/templates/layouts/login.html | 280 +++++++++++++++++++++ src/main/resources/templates/views/login.html | 261 ------------------- 3 files changed, 295 insertions(+), 265 deletions(-) create mode 100644 src/main/resources/templates/layouts/login.html delete mode 100644 src/main/resources/templates/views/login.html (limited to 'src/main') 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())); diff --git a/src/main/resources/templates/layouts/login.html b/src/main/resources/templates/layouts/login.html new file mode 100644 index 00000000..4a3be9b8 --- /dev/null +++ b/src/main/resources/templates/layouts/login.html @@ -0,0 +1,280 @@ + + + + + Juick + + + + + + + + + +
juick.com © 2008-2021   Контакты · + Помощь +
+ +
+ {{ i18n("messages","label.register") }}: +
Facebook
+
ВКонтакте
+
+ +
+
+ +
+
+
+ + {{ i18n("messages","question.areRegistered") }} + +
+
+

{{ authErrorMessage | default('') }}

+ + + +
+
+
+ + + + \ No newline at end of file diff --git a/src/main/resources/templates/views/login.html b/src/main/resources/templates/views/login.html deleted file mode 100644 index 2f6cc741..00000000 --- a/src/main/resources/templates/views/login.html +++ /dev/null @@ -1,261 +0,0 @@ - - - - - Juick - - - - - - - - - -
juick.com © 2008-2021   Контакты · - Помощь -
- -
- {{ i18n("messages","label.register") }}: -
Facebook
-
ВКонтакте
-
- -
-
- -
-
-
- - {{ i18n("messages","question.areRegistered") }} - -
-
- - - -
-
-
- - - - \ No newline at end of file -- cgit v1.2.3