aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/http/www/VKontakteLogin.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-06-27 10:33:52 +0300
committerGravatar Vitaly Takmazov2016-06-27 10:33:52 +0300
commit53fb0b3e0e790df007a198deef21c115ed236b3e (patch)
tree7dcf33649f36b64d8240bf9a48242c7e5ceed24b /src/main/java/com/juick/http/www/VKontakteLogin.java
parent83a3c5f721411bc463fea4c209e6fc2537c50417 (diff)
merge with spring-jdbc
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;
}
}