aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick/www/VKontakteLogin.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-28 14:37:02 +0300
committerGravatar Vitaly Takmazov2016-11-28 14:37:02 +0300
commit5b2bd7f928bbf9d3233ff029ed5c09ac46daf0de (patch)
treecfad7f15e35c51d11a488df5a9b2be5300b9af54 /juick-www/src/main/java/com/juick/www/VKontakteLogin.java
parentc252087c54e91e63f89775eba4c65cf87ae21e5d (diff)
all components using jackson now, org.json serializer moved to compatibility tests package
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.java24
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();