From 5e0500933d2f805fe879ced9171c65839c72579b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 7 Dec 2022 16:13:57 +0300 Subject: Login: use `Referer` header to redirect after the successful login --- src/main/java/com/juick/www/controllers/Site.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/main/java/com/juick/www/controllers/Site.java') 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, -- cgit v1.2.3