diff options
Diffstat (limited to 'src/java/com/juick/http/www/User.java')
-rw-r--r-- | src/java/com/juick/http/www/User.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/java/com/juick/http/www/User.java b/src/java/com/juick/http/www/User.java index 90a558cc..b517af8e 100644 --- a/src/java/com/juick/http/www/User.java +++ b/src/java/com/juick/http/www/User.java @@ -31,6 +31,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import javax.servlet.ServletException; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -105,6 +106,10 @@ public class User { return; } + if (visitor == null) { + pageUserRefCookie(request, response, user.UID); + } + response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { @@ -151,6 +156,10 @@ public class User { protected void doGetTags(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); + if (visitor == null) { + pageUserRefCookie(request, response, user.UID); + } + response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { @@ -180,6 +189,10 @@ public class User { protected void doGetFriends(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); + if (visitor == null) { + pageUserRefCookie(request, response, user.UID); + } + response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { @@ -232,6 +245,10 @@ public class User { protected void doGetReaders(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); + if (visitor == null) { + pageUserRefCookie(request, response, user.UID); + } + response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { @@ -281,6 +298,18 @@ public class User { } } + public static void pageUserRefCookie(HttpServletRequest request, HttpServletResponse response, int uid) { + String hReferer = request.getHeader("Referer"); + String ref = Utils.getCookie(request, "ref"); + + if (ref == null && (hReferer == null || !(hReferer.startsWith("http://juick.com/") || hReferer.startsWith("https://juick.com/")))) { + Cookie c = new Cookie("ref", Integer.toString(uid)); + c.setMaxAge(7 * 24 * 60 * 60); + c.setPath("/"); + response.addCookie(c); + } + } + public static void pageUserColumn(PrintWriter out, Connection 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.UID + ".png\" alt=\"\"/>" + user.UName + "</a></div>"); |