From 5b2bd7f928bbf9d3233ff029ed5c09ac46daf0de Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 28 Nov 2016 14:37:02 +0300 Subject: all components using jackson now, org.json serializer moved to compatibility tests package --- .../src/main/java/com/juick/www/FacebookLogin.java | 27 ++++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'juick-www/src/main/java/com/juick/www/FacebookLogin.java') diff --git a/juick-www/src/main/java/com/juick/www/FacebookLogin.java b/juick-www/src/main/java/com/juick/www/FacebookLogin.java index 2b67dd5c..b42bb23b 100644 --- a/juick-www/src/main/java/com/juick/www/FacebookLogin.java +++ b/juick-www/src/main/java/com/juick/www/FacebookLogin.java @@ -17,8 +17,11 @@ */ package com.juick.www; +import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.server.UserQueries; -import org.json.JSONObject; +import com.juick.www.facebook.Graph; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.dao.EmptyResultDataAccessException; @@ -43,10 +46,12 @@ public class FacebookLogin { private final String FACEBOOK_APPID; private final String FACEBOOK_SECRET; private final String FACEBOOK_REDIRECT = "http://juick.com/_fblogin"; + private final ObjectMapper mapper; public FacebookLogin(String ApplicationID, String secret) { this.FACEBOOK_APPID = ApplicationID; this.FACEBOOK_SECRET = secret; + mapper = new ObjectMapper(); } protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -94,24 +99,16 @@ public class FacebookLogin { } try { - JSONObject json = new JSONObject(graph); - String fbIDStr = json.getString("id"); - String fbName = json.getString("name"); - String fbLink = json.getString("link"); - boolean fbVerified = json.getBoolean("verified"); - - long fbID = 0; - if (fbIDStr != null && !fbIDStr.isEmpty()) { - fbID = Long.parseLong(fbIDStr); - } + Graph fb = mapper.readValue(graph, Graph.class); - if (fbID == 0 || fbName == null || fbLink == null || fbName.isEmpty() || fbLink.isEmpty()) { + long fbID = NumberUtils.toLong(fb.getId(), 0); + if (fbID == 0 || StringUtils.isBlank(fb.getName()) || StringUtils.isBlank(fb.getLink())) { throw new Exception(); } int uid = getUIDbyFBID(sql, fbID); if (uid > 0) { - if (!updateDB(sql, fbID, token, fbName, fbLink)) { + if (!updateDB(sql, fbID, token, fb.getName(), fb.getLink())) { throw new Exception(); } Cookie c = new Cookie("hash", UserQueries.getHashByUID(sql, uid)); @@ -119,9 +116,9 @@ public class FacebookLogin { response.addCookie(c); response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.setHeader("Location", "/"); - } else if (fbVerified) { + } else if (fb.getVerified()) { String loginhash = UUID.randomUUID().toString(); - if (!insertDB(sql, fbID, loginhash, token, fbName, fbLink)) { + if (!insertDB(sql, fbID, loginhash, token, fb.getName(), fb.getLink())) { throw new Exception(); } response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); -- cgit v1.2.3