diff options
author | Ugnich Anton | 2013-12-14 00:43:10 +0700 |
---|---|---|
committer | Ugnich Anton | 2013-12-14 00:43:10 +0700 |
commit | f4a45264cb8f0cfeacdb89ce9bf4c60474923f80 (patch) | |
tree | 47a7cfd203fff913c05bb83f8968e9be26c8c3b2 /src/java/com/juick/http/www/Utils.java | |
parent | 174f7d40d76ad138dbe2ffa81dd0e2d7cdaccd24 (diff) |
getVisitorUser sent X-Username header
Diffstat (limited to 'src/java/com/juick/http/www/Utils.java')
-rw-r--r-- | src/java/com/juick/http/www/Utils.java | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/src/java/com/juick/http/www/Utils.java b/src/java/com/juick/http/www/Utils.java index b2d9a999..35b918b8 100644 --- a/src/java/com/juick/http/www/Utils.java +++ b/src/java/com/juick/http/www/Utils.java @@ -48,28 +48,19 @@ public class Utils { return null; } - public static com.juick.User getVisitorUser(Connection sql, HttpServletRequest request) { + public static com.juick.User getVisitorUser(Connection sql, HttpServletRequest request, HttpServletResponse response) { String hash = getCookie(request, "hash"); if (hash != null) { - return com.juick.server.UserQueries.getUserByHash(sql, hash); + com.juick.User visitor = com.juick.server.UserQueries.getUserByHash(sql, hash); + if (response != null && visitor != null) { + response.setHeader("X-Username", visitor.UName); + } + return visitor; } else { return null; } } - public static int getVisitorUID(Connection sql, HttpServletRequest request) { - Cookie cookies[] = request.getCookies(); - if (cookies != null) { - for (int i = 0; i < cookies.length; i++) { - if (cookies[i].getName().equals("hash")) { - String hash = cookies[i].getValue(); - return com.juick.server.UserQueries.getUIDbyHash(sql, hash); - } - } - } - return 0; - } - public static void sendTemporaryRedirect(HttpServletResponse response, String location) { response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.setHeader("Location", location); |