diff options
Diffstat (limited to 'juick-spring-www/src/main/java/com/juick')
5 files changed, 19 insertions, 61 deletions
diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java index c6de2fbf..c56763b1 100644 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java @@ -12,12 +12,13 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.context.MessageSource; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import javax.inject.Inject; import java.io.IOException; import java.net.URLEncoder; -import java.security.Principal; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -39,9 +40,6 @@ public class IndexController { @RequestMapping(value = "/", method = RequestMethod.GET) public String indexPage( - Principal principal, - @CookieValue("ref") Optional<String> ref, - @RequestHeader("Referer") Optional<String> referer, @RequestParam("show") Optional<String> paramShow, @RequestParam("tag") Optional<String> paramTagStr, @RequestParam(value = "before") Optional<Integer> paramBefore, @@ -49,16 +47,15 @@ public class IndexController { ModelMap model) throws IOException { if (paramTagStr.isPresent()) - return "redirect:/tag/" + URLEncoder.encode(paramTagStr.get(), "UTF-8"); + return "redirect:/tag/" + URLEncoder.encode(paramTagStr.get(), "UTF-8"); if (StringUtils.isNotEmpty(paramSearch) && paramSearch.length() > 64) paramSearch = ""; - String name = UserUtils.getUsername(principal, null); - User visitor = userService.getUserByName(name); + User visitor = UserUtils.getCurrentUser(); String title; - if (visitor.getUid() > 0) { + if (!visitor.isAnonym()) { title = "Популярные"; } else { title = "Микроблоги Juick: популярные записи"; @@ -121,4 +118,9 @@ public class IndexController { //model.addAttribute("isModerator", userService.getModerators().contains(visitor.getUid())); return "index"; } -} + + @RequestMapping(value = "/login", method = RequestMethod.GET) + public String getLoginForm() { + return "views/login"; + } +}
\ No newline at end of file diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/LoginController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/LoginController.java deleted file mode 100644 index 8827d948..00000000 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/LoginController.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.juick.www.controllers; - -import com.juick.User; -import com.juick.service.UserService; -import com.juick.util.UserUtils; -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; - -import javax.inject.Inject; -import java.security.Principal; - -/** - * Created by vitalyster on 09.12.2016. - */ -@Controller -public class LoginController { - @Inject - private UserService userService; - @Inject - private Environment env; - - @RequestMapping(value = "/login", method = RequestMethod.GET) - public String getLoginForm(Principal principal) { - String name = UserUtils.getUsername(principal, null); - User visitor = userService.getUserByName(name); - - if (visitor.getUid() > 0) - return "redirect:/login"; - - return "views/login"; - } -} diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/PMController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/PMController.java index 15a93684..41c6b33c 100644 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/PMController.java +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/PMController.java @@ -21,7 +21,6 @@ import org.springframework.web.bind.annotation.RequestParam; import rocks.xmpp.addr.Jid; import javax.inject.Inject; -import java.security.Principal; import java.util.List; /** @@ -41,9 +40,8 @@ public class PMController { WebApp webApp; @RequestMapping("/pm/inbox") - public String doGetInbox(Principal principal, ModelMap context) { - String name = UserUtils.getUsername(principal, null); - User visitor = userService.getUserByName(name); + public String doGetInbox(ModelMap context) { + User visitor = UserUtils.getCurrentUser(); String title = "PM: Inbox"; List<Message> msgs = pmQueriesService.getLastPMInbox(visitor.getUid()); msgs.forEach(m -> m.setText(MessageUtils.formatMessage(m.getText()))); @@ -56,12 +54,10 @@ public class PMController { @RequestMapping(value = "/pm/sent", method = RequestMethod.GET) public String doGetSent( - Principal principal, @RequestParam String uname, ModelMap context) { String title = "PM: Sent"; - String name = UserUtils.getUsername(principal, null); - User visitor = userService.getUserByName(name); + User visitor = UserUtils.getCurrentUser(); List<com.juick.Message> msgs = pmQueriesService.getLastPMSent(visitor.getUid()); if (WebUtils.isNotUserName(uname)) { @@ -77,12 +73,10 @@ public class PMController { @RequestMapping(value = "/pm/sent", method = RequestMethod.POST) public String doPostPM( - Principal principal, @RequestParam String uname, @RequestParam String body, ModelMap context) { - String name = UserUtils.getUsername(principal, null); - User visitor = userService.getUserByName(name); + User visitor = UserUtils.getCurrentUser(); if (uname.startsWith("@")) { uname = uname.substring(1); } @@ -132,6 +126,6 @@ public class PMController { } return "redirect:/pm/sent"; } - throw new HttpBadRequestException(); + throw new HttpBadRequestException(); } } diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java index a038389f..ceccdbb7 100644 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java @@ -36,13 +36,11 @@ public class SettingsController { @RequestMapping("settings") public String showSettings( - Principal principal, @RequestParam(required = false) String page, @RequestParam(required = false) String code, ModelMap context ) throws ServletException, IOException { - String name = UserUtils.getUsername(principal, null); - User visitor = userService.getUserByName(name); + User visitor = UserUtils.getCurrentUser(); if (visitor.getUid() == 0) { return "redirect:/login"; } diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java index 0961f683..f61928a7 100644 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java @@ -41,13 +41,11 @@ public class TagController { @RequestMapping("/tag/{tagName}") protected String doGet( - Principal principal, @PathVariable("tagName") String paramTagStr, @RequestParam(value = "before", required = false, defaultValue = "0") Integer paramBefore, @QueryString Optional<String> queryString, ModelMap model) throws UnsupportedEncodingException { - String name = UserUtils.getUsername(principal, null); - User visitor = userService.getUserByName(name); + User visitor = UserUtils.getCurrentUser(); com.juick.Tag paramTag = tagService.getTag(paramTagStr, false); if (paramTag == null) { |