From 29150ebc65d0d4cf90da3f437999395a86609504 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Wed, 10 Apr 2013 05:00:41 +0700 Subject: VKontakte login --- src/java/com/juick/http/www/Login.java | 18 ++++++++++++++++++ src/java/com/juick/http/www/VKontakteLogin.java | 7 ++++--- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'src/java/com') diff --git a/src/java/com/juick/http/www/Login.java b/src/java/com/juick/http/www/Login.java index 3a715870..7ad921e0 100644 --- a/src/java/com/juick/http/www/Login.java +++ b/src/java/com/juick/http/www/Login.java @@ -37,6 +37,11 @@ public class Login { protected void doGetLoginForm(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request); + if (visitor != null) { + Utils.sendTemporaryRedirect(response, "/"); + return; + } + Locale locale = request.getLocale(); ResourceBundle rb = ResourceBundle.getBundle("Login", locale); @@ -52,6 +57,9 @@ public class Login { out.println("

\"Facebook\"/" + rb.getString("Login Facebook") + "

"); out.println("

\"Connect

"); out.println("
"); + out.println("

\"VK\"/" + rb.getString("Login VK") + "

"); + out.println("

" + rb.getString("Login VK text") + "

"); + out.println("
"); out.println("

\"XMPP\"/" + rb.getString("Login XMPP") + "

"); out.println("

" + rb.getString("XMPP instructions") + "

"); out.println("
"); @@ -84,6 +92,11 @@ public class Login { c.setMaxAge(365 * 24 * 60 * 60); response.addCookie(c); + Cookie c2 = new Cookie("hash", "-"); + c2.setDomain(".juick.com"); + c2.setMaxAge(0); + response.addCookie(c2); + response.sendRedirect("/"); } else { response.sendError(403); @@ -105,6 +118,11 @@ public class Login { c.setMaxAge(365 * 24 * 60 * 60); response.addCookie(c); + Cookie c2 = new Cookie("hash", "-"); + c2.setDomain(".juick.com"); + c2.setMaxAge(0); + response.addCookie(c2); + String referer = request.getHeader("Referer"); if (referer != null && referer.startsWith("http://juick.com/") && !referer.equals("http://juick.com/login")) { response.sendRedirect(referer); diff --git a/src/java/com/juick/http/www/VKontakteLogin.java b/src/java/com/juick/http/www/VKontakteLogin.java index e7252b57..5f26fef1 100644 --- a/src/java/com/juick/http/www/VKontakteLogin.java +++ b/src/java/com/juick/http/www/VKontakteLogin.java @@ -38,8 +38,8 @@ import org.json.JSONObject; */ public class VKontakteLogin { - private static final String VK_APPID = "3531222"; - private static final String VK_SECRET = "EhgW6VJrl02oFPO0buiJ"; + private static final String VK_APPID = "3544101"; + private static final String VK_SECRET = "z2afNI8jA5lIpZ2jsTm1"; private static final String VK_REDIRECT = "http://juick.com/_vklogin"; protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -84,7 +84,7 @@ public class VKontakteLogin { } try { - JSONObject json = new JSONObject(graph); + JSONObject json = new JSONObject(graph).getJSONArray("response").getJSONObject(0); String vkName = json.getString("first_name") + " " + json.getString("last_name"); String vkLink = json.getString("screen_name"); @@ -108,6 +108,7 @@ public class VKontakteLogin { response.setHeader("Location", "/signup?type=vk&hash=" + loginhash); } } catch (Exception e) { + System.err.println("JSON ERROR: " + e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } -- cgit v1.2.3