diff options
Diffstat (limited to 'src/main/java/com/juick/server/www/controllers')
5 files changed, 19 insertions, 99 deletions
diff --git a/src/main/java/com/juick/server/www/controllers/AnythingFilter.java b/src/main/java/com/juick/server/www/controllers/AnythingFilter.java deleted file mode 100644 index 1f4cf75a..00000000 --- a/src/main/java/com/juick/server/www/controllers/AnythingFilter.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.juick.server.www.controllers; - -import com.juick.server.util.WebUtils; -import com.juick.service.MessagesService; -import com.juick.service.UserService; -import org.apache.commons.lang3.math.NumberUtils; -import org.springframework.stereotype.Component; -import org.springframework.web.filter.OncePerRequestFilter; -import org.springframework.web.servlet.support.ServletUriComponentsBuilder; -import org.springframework.web.util.UriComponents; - -import javax.annotation.Nonnull; -import javax.inject.Inject; -import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -@Component -public class AnythingFilter extends OncePerRequestFilter { - @Inject - private MessagesService messagesService; - @Inject - private UserService userService; - - @Override - public void doFilterInternal(@Nonnull HttpServletRequest servletRequest, - @Nonnull HttpServletResponse servletResponse, - @Nonnull FilterChain filterChain) throws IOException, ServletException { - String upgrade = servletRequest.getHeader("Connection"); - if (upgrade != null && upgrade.equals("Upgrade")) { - filterChain.doFilter(servletRequest, servletResponse); - return; - } - UriComponents components = ServletUriComponentsBuilder.fromCurrentRequestUri().build(); - String anything = components.getPath().substring(1); - int before = NumberUtils.toInt(components.getQueryParams().getFirst("before"), 0); - if (before == 0) { - boolean isPostNumber = WebUtils.isPostNumber(anything); - int messageId = isPostNumber ? - NumberUtils.toInt(anything) : 0; - - if (isPostNumber && anything.equals(Integer.toString(messageId))) { - if (messageId > 0) { - com.juick.User author = messagesService.getMessageAuthor(messageId); - - if (author != null) { - servletResponse.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); - servletResponse.setHeader("Location", "/" + author.getName() + "/" + anything); - return; - } - } - } - com.juick.User user = userService.getUserByName(anything); - if (user.getUid() > 0) { - servletResponse.sendRedirect("/" + user.getName() + "/"); - } else { - filterChain.doFilter(servletRequest, servletResponse); - } - } else { - com.juick.User user = userService.getUserByName(anything); - if (!user.isAnonymous()) { - servletResponse.sendRedirect("/" + user.getName() + "/?before=" + before); - } else { - filterChain.doFilter(servletRequest, servletResponse); - } - } - } -} diff --git a/src/main/java/com/juick/server/www/controllers/MessagesWWW.java b/src/main/java/com/juick/server/www/controllers/MessagesWWW.java index d845aac6..1cd89914 100644 --- a/src/main/java/com/juick/server/www/controllers/MessagesWWW.java +++ b/src/main/java/com/juick/server/www/controllers/MessagesWWW.java @@ -28,7 +28,6 @@ import com.juick.server.www.WebApp; import com.juick.service.*; import com.juick.service.security.annotation.Visitor; import com.juick.util.MessageUtils; -import org.apache.commons.codec.CharEncoding; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.text.StringEscapeUtils; @@ -44,7 +43,6 @@ import ru.sape.Sape; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; -import java.io.IOException; import java.net.URI; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; @@ -101,7 +99,7 @@ public class MessagesWWW { @RequestParam(name = "to", required = false, defaultValue = "0") Long paramTo, @RequestParam(name = "page", required = false, defaultValue = "0") Integer page, @CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie, - ModelMap model) throws IOException { + ModelMap model) { if (tag != null) { return "redirect:/tag/" + URLEncoder.encode(tag, StandardCharsets.UTF_8); } @@ -149,7 +147,7 @@ public class MessagesWWW { throw new HttpNotFoundException(); } - String head = "<meta name=\"Description\" content=\"" + title + "\" />\n";; + String head = "<meta name=\"Description\" content=\"" + title + "\" />\n"; if (paramBefore > 0 || paramShow != null) { head = "<meta name=\"robots\" content=\"noindex\"/>"; @@ -166,9 +164,7 @@ public class MessagesWWW { visitor.setUnreadCount(unread.size()); List<Integer> blUIDs = userService.checkBL(visitor.getUid(), msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList())); - msgs.forEach(m -> { - m.ReadOnly |= blUIDs.contains(m.getUser().getUid()); - }); + msgs.forEach(m -> m.ReadOnly |= blUIDs.contains(m.getUser().getUid())); } model.addAttribute("msgs", msgs); model.addAttribute("tags", tagService.getPopularTags()); @@ -183,7 +179,7 @@ public class MessagesWWW { nextpage += "&show=" + paramShow; } if (paramSearch != null) { - nextpage += "&search=" + URLEncoder.encode(paramSearch, CharEncoding.UTF_8); + nextpage += "&search=" + URLEncoder.encode(paramSearch, StandardCharsets.UTF_8); } model.addAttribute("nextpage", nextpage); } @@ -206,7 +202,7 @@ public class MessagesWWW { @PathVariable String uname, @RequestParam(required = false, defaultValue = "0") Integer before, @CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie, - ModelMap model) throws IOException { + ModelMap model) { com.juick.User user = userService.getUserByName(uname); if (user.isBanned() || user.isAnonymous()) { throw new HttpNotFoundException(); @@ -284,9 +280,7 @@ public class MessagesWWW { visitor.setUnreadCount(unread.size()); List<Integer> blUIDs = userService.checkBL(visitor.getUid(), msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList())); - msgs.forEach(m -> { - m.ReadOnly |= blUIDs.contains(m.getUser().getUid()); - }); + msgs.forEach(m -> m.ReadOnly |= blUIDs.contains(m.getUser().getUid())); } model.addAttribute("msgs", msgs); model.addAttribute("headers", head); @@ -355,7 +349,7 @@ public class MessagesWWW { @GetMapping("/{uname}/readers") protected String doGetReaders( @Visitor User visitor, - @PathVariable String uname, ModelMap model) throws IOException { + @PathVariable String uname, ModelMap model) { com.juick.User user = userService.getUserByName(uname); visitor.setAvatar(webApp.getAvatarWebPath(visitor)); model.addAttribute("title", "Читатели " + user.getName()); @@ -370,7 +364,7 @@ public class MessagesWWW { @GetMapping("/{uname}/bl") protected String doGetBL( @Visitor User visitor, - @PathVariable String uname, ModelMap model) throws IOException { + @PathVariable String uname, ModelMap model) { com.juick.User user = userService.getUserByName(uname); if (visitor.getUid() != user.getUid()) { throw new HttpForbiddenException(); @@ -391,7 +385,7 @@ public class MessagesWWW { @PathVariable String tagName, @CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie, @RequestParam(required = false, defaultValue = "0") int before, - ModelMap model) throws IOException { + ModelMap model) { visitor.setAvatar(webApp.getAvatarWebPath(visitor)); String paramTagStr = StringEscapeUtils.unescapeHtml4(tagName); com.juick.Tag paramTag = tagService.getTag(paramTagStr, false); @@ -399,13 +393,13 @@ public class MessagesWWW { throw new HttpNotFoundException(); } else if (paramTag.SynonymID > 0 && paramTag.TID != paramTag.SynonymID) { com.juick.Tag synTag = tagService.getTag(paramTag.SynonymID); - String url = "/tag/" + URLEncoder.encode(StringEscapeUtils.escapeHtml4(synTag.getName()), CharEncoding.UTF_8); + String url = "/tag/" + URLEncoder.encode(StringEscapeUtils.escapeHtml4(synTag.getName()), StandardCharsets.UTF_8); if (request.getQueryString() != null) { url += "?" + request.getQueryString(); } return "redirect:" + url; } else if (!paramTag.getName().equals(paramTagStr)) { - String url = "/tag/" + URLEncoder.encode(StringEscapeUtils.escapeHtml4(paramTag.getName()), CharEncoding.UTF_8); + String url = "/tag/" + URLEncoder.encode(StringEscapeUtils.escapeHtml4(paramTag.getName()), StandardCharsets.UTF_8); if (request.getQueryString() != null) { url += "?" + request.getQueryString(); } @@ -424,9 +418,7 @@ public class MessagesWWW { visitor.getUid(), msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList()) ); - msgs.forEach(m -> { - m.ReadOnly |= blUIDs.contains(m.getUser().getUid()); - }); + msgs.forEach(m -> m.ReadOnly |= blUIDs.contains(m.getUser().getUid())); fillUserModel(model, visitor, visitor); } diff --git a/src/main/java/com/juick/server/www/controllers/Settings.java b/src/main/java/com/juick/server/www/controllers/Settings.java index 370c2154..e147d058 100644 --- a/src/main/java/com/juick/server/www/controllers/Settings.java +++ b/src/main/java/com/juick/server/www/controllers/Settings.java @@ -111,7 +111,6 @@ public class Settings { model.addAttribute("userinfo", userService.getUserInfo(visitor)); if (page.equals("auth-email")) { if (emailService.verifyAddressByCode(visitor.getUid(), request.getParameter("code"))) { - ; model.addAttribute("result", "OK!"); } else { model.addAttribute("result", "Sorry, code unknown."); diff --git a/src/main/java/com/juick/server/www/controllers/SignUp.java b/src/main/java/com/juick/server/www/controllers/SignUp.java index 5fce2d35..18dfc2eb 100644 --- a/src/main/java/com/juick/server/www/controllers/SignUp.java +++ b/src/main/java/com/juick/server/www/controllers/SignUp.java @@ -17,7 +17,6 @@ package com.juick.server.www.controllers; import com.juick.User; -import com.juick.model.AnonymousUser; import com.juick.server.util.HttpBadRequestException; import com.juick.server.util.HttpForbiddenException; import com.juick.server.www.WebApp; diff --git a/src/main/java/com/juick/server/www/controllers/SocialLogin.java b/src/main/java/com/juick/server/www/controllers/SocialLogin.java index e845247e..602f32c3 100644 --- a/src/main/java/com/juick/server/www/controllers/SocialLogin.java +++ b/src/main/java/com/juick/server/www/controllers/SocialLogin.java @@ -74,12 +74,11 @@ public class SocialLogin { private String FACEBOOK_SECRET; @Value("${ap_base_uri:http://localhost:8080/}") private String baseUri; - private String facebookRedirectUri; private static final String VK_REDIRECT = "http://juick.com/_vklogin"; private static final String TWITTER_VERIFY_URL = "https://api.twitter.com/1.1/account/verify_credentials.json"; @Inject private ObjectMapper jsonMapper; - private ServiceBuilder facebookBuilder, twitterBuilder, vkBuilder; + private ServiceBuilder twitterBuilder; private OAuth20Service facebookAuthService, vkAuthService; @Value("${twitter_consumer_key:appid}") @@ -104,11 +103,11 @@ public class SocialLogin { @PostConstruct public void init() { - facebookBuilder = new ServiceBuilder(FACEBOOK_APPID); + ServiceBuilder facebookBuilder = new ServiceBuilder(FACEBOOK_APPID); twitterBuilder = new ServiceBuilder(twitterConsumerKey); - vkBuilder = new ServiceBuilder(VK_APPID); + ServiceBuilder vkBuilder = new ServiceBuilder(VK_APPID); UriComponentsBuilder facebookRedirectBuilder = UriComponentsBuilder.fromUriString(baseUri); - facebookRedirectUri = facebookRedirectBuilder.replacePath("/_fblogin").build().toUriString(); + String facebookRedirectUri = facebookRedirectBuilder.replacePath("/_fblogin").build().toUriString(); facebookAuthService = facebookBuilder .apiSecret(FACEBOOK_SECRET) .callback(facebookRedirectUri) @@ -168,7 +167,7 @@ public class SocialLogin { } else { if (!crosspostService.createFacebookUser(fbID, state, token.getAccessToken(), fb.getName())) { if (StringUtils.isNotEmpty(fb.getEmail())) { - logger.info("found {} for facebook user {}", fb.getEmail()); + logger.info("found {} for facebook user {}", fb.getEmail(), fb.getName()); Integer userId = crosspostService.getUIDbyFBID(fbID); if (!emailService.getEmails(userId, false).contains(fb.getEmail())) { emailService.addEmail(userId, fb.getEmail()); @@ -265,7 +264,7 @@ public class SocialLogin { throw new HttpBadRequestException(); } - Long vkID = NumberUtils.toLong(jsonUser.getId(), 0); + long vkID = NumberUtils.toLong(jsonUser.getId(), 0); int uid = crosspostService.getUIDbyVKID(vkID); if (uid > 0) { Cookie c = new Cookie("hash", userService.getHashByUID(uid)); @@ -295,7 +294,7 @@ public class SocialLogin { byte[] secretKey = DigestUtils.sha256(telegramToken); String resultString = new HmacUtils(HmacAlgorithms.HMAC_SHA_256, secretKey).hmacHex(dataCheckString); if (hash.equals(resultString)) { - Long tgUser = Long.valueOf(params.get("id")); + long tgUser = Long.parseLong(params.get("id")); int uid = telegramService.getUser(tgUser); if (uid > 0) { Cookie c = new Cookie("hash", userService.getHashByUID(uid)); |