aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/http/www/FacebookLogin.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-06-27 10:39:24 +0300
committerGravatar Vitaly Takmazov2016-06-27 10:39:24 +0300
commit0d93073c6988a22246db61a59b97c2fd7c9f462b (patch)
treed5f27cdb9a4fe51690f7af067608a9bee62087e3 /src/main/java/com/juick/http/www/FacebookLogin.java
parent2d7f61242de54b0c0670bac1953e45ee18d9ecec (diff)
parent53fb0b3e0e790df007a198deef21c115ed236b3e (diff)
merge
Diffstat (limited to 'src/main/java/com/juick/http/www/FacebookLogin.java')
-rw-r--r--src/main/java/com/juick/http/www/FacebookLogin.java80
1 files changed, 20 insertions, 60 deletions
diff --git a/src/main/java/com/juick/http/www/FacebookLogin.java b/src/main/java/com/juick/http/www/FacebookLogin.java
index fcb08d6c..cf444abc 100644
--- a/src/main/java/com/juick/http/www/FacebookLogin.java
+++ b/src/main/java/com/juick/http/www/FacebookLogin.java
@@ -18,20 +18,19 @@
package com.juick.http.www;
import com.juick.server.UserQueries;
+import org.json.JSONObject;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.servlet.ServletException;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.json.JSONObject;
/**
*
@@ -45,7 +44,7 @@ public class FacebookLogin {
private static final String FACEBOOK_SECRET = "95813bfb6ab8f473410c50d4f971649e";
private static final String FACEBOOK_REDIRECT = "http://juick.com/_fblogin";
- protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String fbstate;
String code = request.getParameter("code");
@@ -132,61 +131,22 @@ public class FacebookLogin {
}
}
- private int getUIDbyFBID(Connection sql, long fbID) {
- int uid = 0;
- PreparedStatement stmt = null;
- ResultSet rs = null;
+ private int getUIDbyFBID(JdbcTemplate sql, long fbID) {
try {
- stmt = sql.prepareStatement("SELECT user_id FROM facebook WHERE fb_id=? AND user_id IS NOT NULL");
- stmt.setLong(1, fbID);
- rs = stmt.executeQuery();
- if (rs.first()) {
- uid = rs.getInt(1);
- }
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
+ return sql.queryForObject("SELECT user_id FROM facebook WHERE fb_id=? AND user_id IS NOT NULL",
+ Integer.class, fbID);
+ } catch (EmptyResultDataAccessException e) {
+ return 0;
}
- return uid;
}
- private boolean insertDB(Connection sql, long fbID, String loginhash, String token, String fbName, String fbLink) {
- boolean ret = false;
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("INSERT INTO facebook(fb_id,loginhash,access_token,fb_name,fb_link) VALUES (?,?,?,?,?)");
- stmt.setLong(1, fbID);
- stmt.setString(2, loginhash);
- stmt.setString(3, token);
- stmt.setString(4, fbName);
- stmt.setString(5, fbLink);
- stmt.executeUpdate();
- ret = true;
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
- return ret;
+ private boolean insertDB(JdbcTemplate sql, long fbID, String loginhash, String token, String fbName, String fbLink) {
+ return sql.update("INSERT INTO facebook(fb_id,loginhash,access_token,fb_name,fb_link) VALUES (?,?,?,?,?)",
+ fbID, loginhash, token, fbName, fbLink) > 0;
}
- private boolean updateDB(Connection sql, long fbID, String token, String fbName, String fbLink) {
- boolean ret = false;
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("UPDATE facebook SET access_token=?,fb_name=?,fb_link=? WHERE fb_id=?");
- stmt.setString(1, token);
- stmt.setString(2, fbName);
- stmt.setString(3, fbLink);
- stmt.setLong(4, fbID);
- stmt.executeUpdate();
- ret = true;
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
- return ret;
+ private boolean updateDB(JdbcTemplate sql, long fbID, String token, String fbName, String fbLink) {
+ return sql.update("UPDATE facebook SET access_token=?,fb_name=?,fb_link=? WHERE fb_id=?",
+ token, fbName, fbLink, fbID) > 0;
}
}