From a0fa66fd9587407030d1c1ed3c5ee57d15c280fb Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 10 Jul 2016 22:46:56 +0300 Subject: fix getUserByHash usage --- .../src/main/java/com/juick/www/Discover.java | 6 ++--- juick-www/src/main/java/com/juick/www/Login.java | 4 ++-- juick-www/src/main/java/com/juick/www/Main.java | 10 ++++---- juick-www/src/main/java/com/juick/www/SignUp.java | 2 +- juick-www/src/main/java/com/juick/www/User.java | 12 +++++----- .../src/main/java/com/juick/www/UserThread.java | 27 ++++++++++------------ juick-www/src/main/java/com/juick/www/Utils.java | 2 +- 7 files changed, 30 insertions(+), 33 deletions(-) (limited to 'juick-www/src/main/java/com') diff --git a/juick-www/src/main/java/com/juick/www/Discover.java b/juick-www/src/main/java/com/juick/www/Discover.java index 238af0fb..1811951b 100644 --- a/juick-www/src/main/java/com/juick/www/Discover.java +++ b/juick-www/src/main/java/com/juick/www/Discover.java @@ -71,10 +71,10 @@ public class Discover { } } - int visitor_uid = visitor != null ? visitor.getUID() : 0; + int visitor_uid = visitor.getUID(); String title = "*" + Utils.encodeHTML(paramTag.Name); - List mids = MessagesQueries.getTag(sql, paramTag.TID, visitor_uid, paramBefore, (visitor == null) ? 40 : 20); + List mids = MessagesQueries.getTag(sql, paramTag.TID, visitor_uid, paramBefore, (visitor_uid == 0) ? 40 : 20); response.setContentType("text/html; charset=UTF-8"); try (PrintWriter out = response.getWriter()) { @@ -100,7 +100,7 @@ public class Discover { ad_mid = 0; } - PageTemplates.printMessages(out, sql, null, mids, visitor, visitor == null ? 2 : 3, ad_mid); + PageTemplates.printMessages(out, sql, null, mids, visitor, visitor_uid == 0 ? 2 : 3, ad_mid); } if (mids.size() >= 20) { diff --git a/juick-www/src/main/java/com/juick/www/Login.java b/juick-www/src/main/java/com/juick/www/Login.java index 155f58d5..0ec63a8e 100644 --- a/juick-www/src/main/java/com/juick/www/Login.java +++ b/juick-www/src/main/java/com/juick/www/Login.java @@ -34,7 +34,7 @@ public class Login { protected void doGetLoginForm(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - if (visitor != null) { + if (visitor.getUID() > 0) { Utils.sendTemporaryRedirect(response, "/"); return; } @@ -228,7 +228,7 @@ public class Login { protected void doGetLogout(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - if (visitor != null) { + if (visitor.getUID() > 0) { sql.update("DELETE FROM logins WHERE user_id=?", visitor.getUID()); } diff --git a/juick-www/src/main/java/com/juick/www/Main.java b/juick-www/src/main/java/com/juick/www/Main.java index 8602447a..4d340cd8 100644 --- a/juick-www/src/main/java/com/juick/www/Main.java +++ b/juick-www/src/main/java/com/juick/www/Main.java @@ -149,7 +149,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { } } else if (uri.startsWith("/pm/")) { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - if (visitor == null) { + if (visitor.getUID() == 0) { Utils.sendTemporaryRedirect(response, "/login"); } else { switch (uri) { @@ -271,28 +271,28 @@ public class Main extends HttpServlet implements Stream.StreamListener { String uri = request.getRequestURI(); if (uri.equals("/post")) { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - if (visitor != null && !visitor.Banned) { + if (visitor.getUID() > 0 && !visitor.Banned) { pagesNewMessage.doPostMessage(sql, request, response, xmpp, visitor); } else { response.sendError(403); } } else if (uri.equals("/comment")) { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - if (visitor != null && !visitor.Banned) { + if (visitor.getUID() > 0 && !visitor.Banned) { pagesNewMessage.doPostComment(sql, request, response, xmpp, visitor); } else { response.sendError(403); } } else if (uri.equals("/like")) { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - if (visitor != null && !visitor.Banned) { + if (visitor.getUID() > 0 && !visitor.Banned) { pagesNewMessage.doPostRecomm(sql, request, response, xmpp, visitor); } else { response.sendError(403); } } else if (uri.equals("/pm/send")) { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - if (visitor != null && !visitor.Banned) { + if (visitor.getUID() > 0 && !visitor.Banned) { pm.doPostPM(sql, request, response, xmpp, visitor); } else { response.sendError(403); diff --git a/juick-www/src/main/java/com/juick/www/SignUp.java b/juick-www/src/main/java/com/juick/www/SignUp.java index bba1d34e..7dbfb6dc 100644 --- a/juick-www/src/main/java/com/juick/www/SignUp.java +++ b/juick-www/src/main/java/com/juick/www/SignUp.java @@ -127,7 +127,7 @@ public class SignUp { String action = request.getParameter("action"); if (action.charAt(0) == 'l') { - if (visitor == null) { + if (visitor.getUID() == 0) { String username = request.getParameter("username"); String password = request.getParameter("password"); if (username == null || password == null || username.length() > 32 || password.isEmpty()) { diff --git a/juick-www/src/main/java/com/juick/www/User.java b/juick-www/src/main/java/com/juick/www/User.java index ae1aee2a..f782d988 100644 --- a/juick-www/src/main/java/com/juick/www/User.java +++ b/juick-www/src/main/java/com/juick/www/User.java @@ -77,7 +77,7 @@ public class User { } int privacy = 0; - if (visitor != null) { + if (visitor.getUID() > 0) { if (user.getUID() == visitor.getUID() || visitor.getUID() == 1) { privacy = -3; } else if (UserQueries.isInWL(sql, user.getUID(), visitor.getUID())) { @@ -108,7 +108,7 @@ public class User { return; } - if (visitor == null) { + if (visitor.getUID() == 0) { pageUserRefCookie(request, response, user.getUID()); } @@ -131,7 +131,7 @@ public class User { out.println("

← Все записи с тегом " + Utils.encodeHTML(paramTag.Name) + "

"); } - PageTemplates.printMessages(out, sql, user, mids, visitor, visitor == null ? 4 : 5, 0); + PageTemplates.printMessages(out, sql, user, mids, visitor, visitor.getUID() == 0 ? 4 : 5, 0); if (mids.size() >= 20) { String nextpage = "?before=" + mids.get(mids.size() - 1); @@ -181,7 +181,7 @@ public class User { protected void doGetFriends(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - if (visitor == null) { + if (visitor.getUID() == 0) { pageUserRefCookie(request, response, user.getUID()); } @@ -216,7 +216,7 @@ public class User { protected void doGetReaders(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - if (visitor == null) { + if (visitor.getUID() == 0) { pageUserRefCookie(request, response, user.getUID()); } @@ -263,7 +263,7 @@ public class User { public static void pageUserColumn(PrintWriter out, JdbcTemplate sql, com.juick.User user, com.juick.User visitor) { out.println("