aboutsummaryrefslogtreecommitdiff
path: root/juick-www
diff options
context:
space:
mode:
Diffstat (limited to 'juick-www')
-rw-r--r--juick-www/src/main/java/com/juick/www/Discover.java6
-rw-r--r--juick-www/src/main/java/com/juick/www/Login.java4
-rw-r--r--juick-www/src/main/java/com/juick/www/Main.java10
-rw-r--r--juick-www/src/main/java/com/juick/www/SignUp.java2
-rw-r--r--juick-www/src/main/java/com/juick/www/User.java12
-rw-r--r--juick-www/src/main/java/com/juick/www/UserThread.java27
-rw-r--r--juick-www/src/main/java/com/juick/www/Utils.java2
7 files changed, 30 insertions, 33 deletions
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 238af0fbb..1811951bf 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<Integer> mids = MessagesQueries.getTag(sql, paramTag.TID, visitor_uid, paramBefore, (visitor == null) ? 40 : 20);
+ List<Integer> 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 155f58d54..0ec63a8e0 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 8602447a7..4d340cd81 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 bba1d34ec..7dbfb6dc4 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 ae1aee2ad..f782d988f 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("<p class=\"page\"><a href=\"/tag/" + URLEncoder.encode(paramTag.Name, "UTF-8") + "\">← Все записи с тегом <b>" + Utils.encodeHTML(paramTag.Name) + "</b></a></p>");
}
- 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("<aside id=\"column\">");
out.println(" <div id=\"ctitle\"><a href=\"./\"><img src=\"//i.juick.com/as/" + user.getUID() + ".png\" alt=\"\"/>" + user.getUName() + "</a></div>");
- if (visitor != null && visitor.getUID() > 0 && visitor.getUID() != user.getUID()) {
+ if (visitor.getUID() > 0 && visitor.getUID() != user.getUID()) {
out.println(" <ul id=\"ctoolbar\">");
if (UserQueries.isSubscribed(sql, visitor.getUID(), user.getUID())) {
out.println(" <li><a href=\"/post?body=U+%40" + user.getUName() + "\" title=\"Подписан\"><div style=\"background-position: -48px 0\"></div></a></li>");
diff --git a/juick-www/src/main/java/com/juick/www/UserThread.java b/juick-www/src/main/java/com/juick/www/UserThread.java
index 249cf3425..e3eb7186a 100644
--- a/juick-www/src/main/java/com/juick/www/UserThread.java
+++ b/juick-www/src/main/java/com/juick/www/UserThread.java
@@ -40,7 +40,7 @@ public class UserThread {
protected void doGetThread(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, int MID) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- if (!MessagesQueries.canViewThread(sql, MID, visitor != null ? visitor.getUID() : 0)) {
+ if (!MessagesQueries.canViewThread(sql, MID, visitor.getUID())) {
response.sendError(403);
return;
}
@@ -52,25 +52,24 @@ public class UserThread {
if (paramView != null) {
if (paramView.equals("list")) {
listview = true;
- if (visitor != null) {
+ if (visitor.getUID() > 0) {
UserQueries.setUserOptionInt(sql, visitor.getUID(), "repliesview", 1);
}
- } else if (paramView.equals("tree") && visitor != null) {
+ } else if (paramView.equals("tree") && visitor.getUID() > 0) {
UserQueries.setUserOptionInt(sql, visitor.getUID(), "repliesview", 0);
}
- } else if (visitor != null && UserQueries.getUserOptionInt(sql, visitor.getUID(), "repliesview", 0) == 1) {
+ } else if (visitor.getUID() > 0 && UserQueries.getUserOptionInt(sql, visitor.getUID(), "repliesview", 0) == 1) {
listview = true;
}
String title = msg.getUser().getUName() + ": " + msg.getTagsString();
- if (visitor == null) {
+ if (visitor.getUID() > 0) {
User.pageUserRefCookie(request, response, msg.getUser().getUID());
}
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
String headers = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"@" + msg.getUser().getUName() + "\" href=\"//rss.juick.com/" + msg.getUser().getUName() + "/blog\"/>";
if (paramView != null) {
headers += "<link rel=\"canonical\" href=\"http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "\"/>";
@@ -94,13 +93,11 @@ public class UserThread {
out.println("</script>");
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
public static com.juick.Message printMessage(PrintWriter out, JdbcTemplate sql, com.juick.Message msg, com.juick.User visitor) {
- msg.VisitorCanComment = visitor != null;
+ msg.VisitorCanComment = visitor.getUID() > 0;
List<Tag> tags = MessagesQueries.getMessageTags(sql, msg.getMID());
String tagsStr = PageTemplates.formatTags(tags);
@@ -137,7 +134,7 @@ public class UserThread {
}
boolean visitorInBL = false;
- if (visitor != null) {
+ if (visitor.getUID() > 0) {
if (visitor.getUID() == msg.getUser().getUID()) {
msg.VisitorCanComment = true;
} else {
@@ -170,7 +167,7 @@ public class UserThread {
out.println(" <li id=\"mtoolbar\"><ul>");
out.println(" <li><a href=\"/" + msg.getMID() + "\"><div style=\"background-position: -64px 0\"></div>" + msg.getMID() + "</a></li>");
- if (visitor != null) {
+ if (visitor.getUID() > 0) {
if (visitor.getUID() != msg.getUser().getUID()) {
if (MessagesQueries.isSubscribed(sql, visitor.getUID(), msg.getMID())) {
out.println(" <li><a href=\"/post?body=U+%23" + msg.getMID() + "\"><div style=\"background-position: -48px 0\"></div>Подписан</a></li>");
@@ -215,11 +212,11 @@ public class UserThread {
}
if (!replies.isEmpty()) {
- if (visitor != null && msg.getUser().getUID() == visitor.getUID()) {
+ if (visitor.getUID() > 0 && msg.getUser().getUID() == visitor.getUID()) {
for (Message reply : replies) {
reply.VisitorCanComment = true;
}
- } else if (visitor != null && msg.VisitorCanComment) {
+ } else if (visitor.getUID() > 0 && msg.VisitorCanComment) {
blUIDs = UserQueries.checkBL(sql, visitor.getUID(), blUIDs);
for (Message reply : replies) {
reply.VisitorCanComment = reply.getUser().getUID() == visitor.getUID() || !blUIDs.contains(reply.getUser().getUID());
@@ -354,7 +351,7 @@ public class UserThread {
if (msg.VisitorCanComment) {
out.println(" &#183; <a href=\"#\" onclick=\"return showCommentForm(" + msg.getMID() + "," + msg.getRID() + ")\">Ответить</a></div>");
out.println(" <div class=\"msg-comment\" style=\"display: none\"></div>");
- } else if (visitor == null) {
+ } else if (visitor.getUID() == 0) {
out.println(" <div class=\"msg-links\"><a href=\"#\" onclick=\"return openDialogLogin()\">Ответить</a></div>");
}
out.println(" </div>");
diff --git a/juick-www/src/main/java/com/juick/www/Utils.java b/juick-www/src/main/java/com/juick/www/Utils.java
index c98bddf94..e88e5b1b5 100644
--- a/juick-www/src/main/java/com/juick/www/Utils.java
+++ b/juick-www/src/main/java/com/juick/www/Utils.java
@@ -77,7 +77,7 @@ public class Utils {
String hash = getCookie(request, "hash");
if (hash != null) {
com.juick.User visitor = com.juick.server.UserQueries.getUserByHash(sql, hash);
- if (response != null && visitor != null) {
+ if (response != null && visitor.getUID() > 0) {
response.setHeader("X-Username", visitor.getUName());
}
return visitor;