diff options
Diffstat (limited to 'src/main/java/com/juick/www')
-rw-r--r-- | src/main/java/com/juick/www/SiteAttributesHandler.java (renamed from src/main/java/com/juick/www/VaryHandler.java) | 8 | ||||
-rw-r--r-- | src/main/java/com/juick/www/controllers/Site.java | 15 |
2 files changed, 13 insertions, 10 deletions
diff --git a/src/main/java/com/juick/www/VaryHandler.java b/src/main/java/com/juick/www/SiteAttributesHandler.java index 6910823d..e06a2070 100644 --- a/src/main/java/com/juick/www/VaryHandler.java +++ b/src/main/java/com/juick/www/SiteAttributesHandler.java @@ -17,15 +17,21 @@ package com.juick.www; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; import jakarta.servlet.http.HttpServletResponse; @ControllerAdvice -public class VaryHandler { +public class SiteAttributesHandler { @ModelAttribute public void setVaryResponseHeader(HttpServletResponse response) { response.setHeader("Vary", "Accept-Language"); } + @ModelAttribute + public void setReturnPathAttribute(Model model) { + model.addAttribute("retpath", ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString()); + } } diff --git a/src/main/java/com/juick/www/controllers/Site.java b/src/main/java/com/juick/www/controllers/Site.java index a0b8c5b0..aa6d574d 100644 --- a/src/main/java/com/juick/www/controllers/Site.java +++ b/src/main/java/com/juick/www/controllers/Site.java @@ -46,6 +46,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; import javax.inject.Inject; import java.net.URLEncoder; @@ -96,10 +97,12 @@ public class Site { } @GetMapping("/login") - public String getloginForm(@Visitor User visitor, HttpSession session, - @RequestParam(required = false, defaultValue = "true") boolean redirect, ModelMap model) { + public String getloginForm(@Visitor User visitor, + @RequestParam(name = "retpath", required = false, defaultValue = "/") String retPath, + HttpSession session, + ModelMap model) { if (!visitor.isAnonymous()) { - return redirect ? "redirect:/" : "redirect:/login/success"; + return String.format("redirect:%s", retPath); } model.addAttribute("visitor", visitor); model.addAttribute("tags", tagService.getPopularTags()); @@ -119,12 +122,6 @@ public class Site { return "views/login"; } - @GetMapping("/login/success") - public String getSuccessLogin(@Visitor User visitor, ModelMap model) { - model.addAttribute("hash", userService.getHashByUID(visitor.getUid())); - return "views/login_success"; - } - @GetMapping("/") protected String doGet(@Visitor User visitor, Locale locale, @RequestParam(required = false) String tag, @RequestParam(name = "show", required = false) String paramShow, |