aboutsummaryrefslogtreecommitdiff
path: root/juick-spring-www/src
diff options
context:
space:
mode:
authorGravatar Alexander Alexeev2016-12-11 13:56:26 +0700
committerGravatar Vitaly Takmazov2016-12-11 18:24:38 +0300
commitf2454d531e9e99c406a513d92702858510fef4b9 (patch)
tree19090e8f207e875615bec60d3aa65ac6e4e34e12 /juick-spring-www/src
parentf9d9f6ac709b0dfe1c1e3f711b2fee6a93f33d42 (diff)
i18n, using SecurityContextHolder for get currentUser (user always not null)
Diffstat (limited to 'juick-spring-www/src')
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java22
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/LoginController.java34
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/PMController.java16
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java4
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java4
-rw-r--r--juick-spring-www/src/main/resources/messages.properties17
-rw-r--r--juick-spring-www/src/main/resources/messages_en.properties17
-rw-r--r--juick-spring-www/src/main/webapp/WEB-INF/templates/index.html1
-rw-r--r--juick-spring-www/src/main/webapp/WEB-INF/templates/layout/mainLayout.html1
-rw-r--r--juick-spring-www/src/main/webapp/WEB-INF/templates/views/help.html3
-rw-r--r--juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/footer.html12
-rw-r--r--juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/navigation.html31
12 files changed, 73 insertions, 89 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) {
diff --git a/juick-spring-www/src/main/resources/messages.properties b/juick-spring-www/src/main/resources/messages.properties
index 29715d5d..a7034c5f 100644
--- a/juick-spring-www/src/main/resources/messages.properties
+++ b/juick-spring-www/src/main/resources/messages.properties
@@ -6,5 +6,20 @@ link.contacts=Контакты
link.help=Помощь
link.adv=Реклама
+link.popular=Популярные
+link.allMessages=Все сообщения
+link.withPhotos=Фотографии
+link.my=Моя лента
+link.privateMessages=Приватные
+link.discuss=Обсуждения
+link.recommended=Рекомендации
+link.postMessage=Написать сообщение
+link.logout=Выйти
+
label.sponsor=Спонсор
-label.sponsors=Спонсоры \ No newline at end of file
+label.sponsors=Спонсоры
+label.search=Поиск
+
+message.loginForSending=Чтобы добавлять сообщения и комментарии, <a href="{0}">представьтесь</a>
+
+title.help=Справка \ No newline at end of file
diff --git a/juick-spring-www/src/main/resources/messages_en.properties b/juick-spring-www/src/main/resources/messages_en.properties
index 9efa2cbb..02c83e12 100644
--- a/juick-spring-www/src/main/resources/messages_en.properties
+++ b/juick-spring-www/src/main/resources/messages_en.properties
@@ -6,5 +6,20 @@ link.contacts=Contacts
link.help=Help
link.adv=Advertisement
+link.popular=Popular
+link.allMessages=All messages
+link.withPhotos=Photos
+link.my=My messages
+link.privateMessages=My private messages
+link.discuss=Discuss
+link.recommended=Recommended
+link.postMessage=Post
+link.logout=Logout
+
label.sponsor=Sponsor
-label.sponsors=Sponsors \ No newline at end of file
+label.sponsors=Sponsors
+label.search=Search
+
+message.loginForSending=<a href="{0}">Login</a> for post messages and comments
+
+title.help=Help \ No newline at end of file
diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/index.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/index.html
index 5687985d..1695cd02 100644
--- a/juick-spring-www/src/main/webapp/WEB-INF/templates/index.html
+++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/index.html
@@ -10,6 +10,5 @@
<section layout:fragment="content">
<p>Главная страница !</p>
</section>
-
</body>
</html> \ No newline at end of file
diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/mainLayout.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/mainLayout.html
index 33995d65..06805dc6 100644
--- a/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/mainLayout.html
+++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/mainLayout.html
@@ -11,7 +11,6 @@
<script type="text/javascript" src="/scripts.js" th:href="@{/scripts.js}"></script>
<title layout:title-pattern="$LAYOUT_TITLE - $CONTENT_TITLE">Juick.com</title>
- <meta layout:fragment="headers" />
<link rel="icon" href="//i.juick.com/favicon.png"/>
<!--[if lt IE 9 & (!IEMobile 7)]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/views/help.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/help.html
index 0500839b..d935b9d4 100644
--- a/juick-spring-www/src/main/webapp/WEB-INF/templates/views/help.html
+++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/help.html
@@ -3,7 +3,7 @@
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/mainLayout}">
<head>
- <title th:text="${title}">Help title</title>
+ <title th:text="#{title.help}">Help title</title>
</head>
<body>
@@ -13,6 +13,5 @@
<aside id="column">
<p layout:fragment="column" th:utext="${help_nav}">Help navigation</p>
</aside>
-
</body>
</html> \ No newline at end of file
diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/footer.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/footer.html
index cc165af7..fb53eb20 100644
--- a/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/footer.html
+++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/footer.html
@@ -5,10 +5,10 @@
<body layout:fragment="footer">
<div id="footer">
<div id="footer-right">
- <a href="/settings" th:href="@{/settings}" rel="nofollow">Настройки</a> &#183;
- <a href="/help/ru/contacts" th:href="@{/help/ru/contacts}" rel="nofollow">Контакты</a> &#183;
- <a href="/help/" th:href="@{/help/}" rel="nofollow">Справка</a> &#183;
- <a href="/help/ru/adv" th:href="@{/help/ru/adv}" rel="nofollow">Реклама</a>
+ <a href="/settings" th:href="@{/settings}" th:text="#{link.settings}" rel="nofollow">Настройки</a> &#183;
+ <a href="/help/ru/contacts" th:href="@{/help/ru/contacts}" th:text="#{link.contacts}" rel="nofollow">Контакты</a> &#183;
+ <a href="/help/" th:href="@{/help/}" th:text="#{link.help}" rel="nofollow">Справка</a> &#183;
+ <a href="/help/ru/adv" th:href="@{/help/ru/adv}" th:text="#{link.adv}" rel="nofollow">Реклама</a>
</div>
<div id="footer-social">
<a href="https://twitter.com/Juick" rel="nofollow" class="ico32-twi">Twitter</a>
@@ -16,8 +16,8 @@
<a href="https://www.facebook.com/JuickCom" rel="nofollow" class="ico32-fb">Facebook</a>
</div>
<div id="footer-left">
- juick.com &copy; 2008-2016
- <th:block th:if="${links != null}"/><br/>Спонсоры: <span th:text="${links}">&nbsp;</span></th:block>
+ <a href="http://juick.com">juick.com</a> &copy; 2008-2016
+ <th:block th:if="${links != null}"/><br/><span th:text="#{label.sponsors}">Спонсоры:</span><span th:text="${links}">&nbsp;</span></th:block>
</div>
</div>
<script>
diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/navigation.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/navigation.html
index 79b41211..51489194 100644
--- a/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/navigation.html
+++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/navigation.html
@@ -3,40 +3,39 @@
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<body layout:fragment="nav">
- <div id="logo"><a href="/">Juick</a></div>
+ <div id="logo"><a href="/" th:href="@{/}">Juick</a></div>
<nav id="global">
<ul>
- <li><a href="/" th:href="@{/}">Популярные</a></li>
- <li><a href="/?show=all" th:href="@{/?show=all}" rel="nofollow">Все сообщения</a></li>
- <li><a href="/?show=photos" th:href="@{/?show=photos}" rel="nofollow">Фотографии</a></li>
+ <li><a href="/" th:href="@{/}" th:text="#{link.popular}">Популярные</a></li>
+ <li><a href="/?show=all" th:href="@{/?show=all}" rel="nofollow" th:text="#{link.allMessages}">Все сообщения</a></li>
+ <li><a href="/?show=photos" th:href="@{/?show=photos}" rel="nofollow" th:text="#{link.withPhotos}">Фотографии</a></li>
</ul>
</nav>
<div id="search">
<form action="/">
- <input type="text" name="search" class="text" placeholder="Поиск" th:value="${param.search}"/>
+ <input type="text" name="search" class="text" placeholder="Поиск" th:placeholder="#{label.search}" th:value="${param.search}"/>
</form>
</div>
- <section id="headdiv" th:switch="${visitor.getUid() > 0}">
- <th:block th:case="true">
+ <section id="headdiv" th:switch="${visitor.isAnonym()}">
+ <th:block th:case="false">
<nav id="user">
<ul>
- <li><a href="/?show=my" th:href="@{/?show=my}">Моя лента</a></li>
- <li><a href="/pm/inbox" th:href="@{/pm/inbox}">Приватные</a></li>
- <li><a href="/?show=discuss" th:href="@{/?show=discuss}">Обсуждения</a></li>
- <li><a href="/?show=recommended" th:href="@{/?show=recommended}">Рекомендации</a></li>
+ <li><a href="/?show=my" th:href="@{/?show=my}" th:text="#{link.my}">Моя лента</a></li>
+ <li><a href="/pm/inbox" th:href="@{/pm/inbox}" th:text="#{link.privateMessages}">Приватные</a></li>
+ <li><a href="/?show=discuss" th:href="@{/?show=discuss}" th:text="#{link.discuss}">Обсуждения</a></li>
+ <li><a href="/?show=recommended" th:href="@{/?show=recommended}" th:text="#{link.recommended}">Рекомендации</a></li>
</ul>
</nav>
<nav id="actions">
<ul>
- <li><a href="/#post" th:href="@{/#post}">Написать</a></li>
+ <li><a href="/#post" th:href="@{/#post}" th:text="#{link.postMessage}">Написать</a></li>
<li><a href="/ugnich" th:href="@{/{userName}(userName=${visitor.name})}" th:text="'@'+${visitor.name}">@ugnich</a></li>
- <li><a href="/logout" th:href="@{/logout}">Выйти</a></li>
+ <li><a href="/logout" th:href="@{/logout}" th:text="#{link.logout}">Выйти</a></li>
</ul>
</nav>
</th:block>
- <th:block th:case="false">
- <p>Чтобы добавлять сообщения и комментарии, <a href="/login" th:href="@{/login}">представьтесь</a>.
- </p>
+ <th:block th:case="true">
+ <p>[(#{message.loginForSending(@{/login})})]</p>
</th:block>
</section>
</body>