aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/http/www/VKontakteLogin.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-07-07 11:25:23 +0300
committerGravatar Vitaly Takmazov2016-07-07 11:25:23 +0300
commita93c85c5ea1bf6683f604bef2608053957577ff0 (patch)
treef80998a4cf339a2b85cd5f095f4386de9d46597b /src/main/java/com/juick/http/www/VKontakteLogin.java
parent3e48ba7c9cae9027b0a045aa25ae40b533518865 (diff)
parent857a930d31c425185c9b9405f5a7820e6cec9491 (diff)
merge rebase_all
Diffstat (limited to 'src/main/java/com/juick/http/www/VKontakteLogin.java')
-rw-r--r--src/main/java/com/juick/http/www/VKontakteLogin.java59
1 files changed, 16 insertions, 43 deletions
diff --git a/src/main/java/com/juick/http/www/VKontakteLogin.java b/src/main/java/com/juick/http/www/VKontakteLogin.java
index 5f26fef1..8fad3b7a 100644
--- a/src/main/java/com/juick/http/www/VKontakteLogin.java
+++ b/src/main/java/com/juick/http/www/VKontakteLogin.java
@@ -18,19 +18,18 @@
package com.juick.http.www;
import com.juick.server.UserQueries;
-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 org.json.JSONException;
+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 org.json.JSONException;
-import org.json.JSONObject;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.UUID;
/**
*
@@ -42,7 +41,7 @@ public class VKontakteLogin {
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 {
+ protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String code = request.getParameter("code");
if (code == null || code.equals("")) {
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
@@ -114,42 +113,16 @@ public class VKontakteLogin {
}
}
- private int getUIDbyVKID(Connection sql, long vkID) {
- int uid = 0;
- PreparedStatement stmt = null;
- ResultSet rs = null;
+ private int getUIDbyVKID(JdbcTemplate sql, long vkID) {
try {
- stmt = sql.prepareStatement("SELECT user_id FROM vk WHERE vk_id=? AND user_id IS NOT NULL");
- stmt.setLong(1, vkID);
- 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 vk WHERE vk_id=? AND user_id IS NOT NULL", Integer.class, vkID);
+ } catch (EmptyResultDataAccessException e) {
+ return 0;
}
- return uid;
}
- private boolean insertDB(Connection sql, long vkID, String loginhash, String token, String vkName, String vkLink) {
- boolean ret = false;
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("INSERT INTO vk(vk_id,loginhash,access_token,vk_name,vk_link) VALUES (?,?,?,?,?)");
- stmt.setLong(1, vkID);
- stmt.setString(2, loginhash);
- stmt.setString(3, token);
- stmt.setString(4, vkName);
- stmt.setString(5, vkLink);
- stmt.executeUpdate();
- ret = true;
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
- return ret;
+ private boolean insertDB(JdbcTemplate sql, long vkID, String loginhash, String token, String vkName, String vkLink) {
+ return sql.update("INSERT INTO vk(vk_id,loginhash,access_token,vk_name,vk_link) VALUES (?,?,?,?,?)",
+ vkID, loginhash, token, vkName, vkLink) > 0;
}
}