From 79e48598873f6a2b4ec1aa850e310a689d862afa Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 1 Dec 2015 16:27:32 +0300 Subject: link twitter account query --- src/main/java/com/juick/server/UserQueries.java | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/main/java') diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java index d1313715..470f3c8e 100644 --- a/src/main/java/com/juick/server/UserQueries.java +++ b/src/main/java/com/juick/server/UserQueries.java @@ -17,6 +17,8 @@ */ package com.juick.server; +import com.juick.User; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -574,6 +576,33 @@ public class UserQueries { return users; } + public static boolean linkTwitterAccount(Connection sql, User user, String accessToken, + String accessTokenSecret, String screenName) { + try { + PreparedStatement stmt = + sql.prepareStatement("INSERT INTO twitter(user_id,access_token,access_token_secret,uname) " + + "VALUES (?,?,?,?)" + + " ON DUPLICATE KEY UPDATE access_token=?,access_token_secret=?,uname=?;"); + stmt.setInt(1, user.UID); + stmt.setString(2, accessToken); + stmt.setString(3, accessTokenSecret); + stmt.setString(4, screenName); + stmt.setString(5, accessToken); + stmt.setString(6, accessTokenSecret); + stmt.setString(7, screenName); + if (stmt.execute()) { + PreparedStatement stmt2 = + sql.prepareStatement("INSERT INTO subscr_users(user_id,suser_id,jid) " + + "VALUES (?,1741,'juick\\@twitter.juick.com')"); + stmt2.setInt(1, user.UID); + return stmt2.execute(); + } + } catch (SQLException e) { + + } + return false; + } + public static int getStatsIRead(Connection sql, int uid) { return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM subscr_users WHERE suser_id=?", uid, 0); } -- cgit v1.2.3