diff options
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/VKontakteLogin.java')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/VKontakteLogin.java | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/juick-www/src/main/java/com/juick/www/VKontakteLogin.java b/juick-www/src/main/java/com/juick/www/VKontakteLogin.java index f0010ac8..83619b2a 100644 --- a/juick-www/src/main/java/com/juick/www/VKontakteLogin.java +++ b/juick-www/src/main/java/com/juick/www/VKontakteLogin.java @@ -17,9 +17,9 @@ */ package com.juick.www; +import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.server.UserQueries; -import org.json.JSONException; -import org.json.JSONObject; +import com.juick.www.vk.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.dao.EmptyResultDataAccessException; @@ -43,6 +43,8 @@ public class VKontakteLogin { private static final String VK_SECRET = "z2afNI8jA5lIpZ2jsTm1"; private static final String VK_REDIRECT = "http://juick.com/_vklogin"; + private final ObjectMapper mapper = new ObjectMapper(); + protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String code = request.getParameter("code"); if (code == null || code.equals("")) { @@ -60,15 +62,9 @@ public class VKontakteLogin { } String token = null; long vkID = 0; - try { - JSONObject json = new JSONObject(tokenjson); - token = json.getString("access_token"); - vkID = json.getLong("user_id"); - } catch (JSONException e) { - logger.error("VK TOKEN EXCEPTION: ", e); - response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - return; - } + Token json = mapper.readValue(tokenjson, Token.class); + token = json.getAccessToken(); + vkID = json.getUserId(); if (token == null || vkID == 0) { logger.error("VK TOKEN EMPTY: " + tokenjson); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); @@ -85,9 +81,9 @@ public class VKontakteLogin { } try { - 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"); + com.juick.www.vk.User jsonUser = mapper.readValue(graph, GraphResponse.class).getUser(); + String vkName = jsonUser.getFirstName() + " " + jsonUser.getLastName(); + String vkLink = jsonUser.getScreenName(); if (vkName == null || vkLink == null || vkName.isEmpty() || vkName.length() == 1 || vkLink.isEmpty()) { throw new Exception(); |