aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-01-10 15:10:42 +0300
committerGravatar Vitaly Takmazov2016-01-10 15:10:42 +0300
commitcb833cdc7ed8d14b779496e8bd3a09448816c727 (patch)
treea0bb11dd9f7f5f1a85e00c073c8fe7e638908b11 /src
parent98b91289a497989e2c776c7e4e333ce6df719211 (diff)
parent03316e2af6989e026318e6860f27d26e6e805d4d (diff)
Merge branch 'develop' of ssh://den.jabber.ru:2205/var/lib/git/com.juick.server into develop
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/server/MessagesQueries.java12
-rw-r--r--src/main/java/com/juick/server/UserQueries.java35
2 files changed, 39 insertions, 8 deletions
diff --git a/src/main/java/com/juick/server/MessagesQueries.java b/src/main/java/com/juick/server/MessagesQueries.java
index b6e722f3..82fef672 100644
--- a/src/main/java/com/juick/server/MessagesQueries.java
+++ b/src/main/java/com/juick/server/MessagesQueries.java
@@ -719,14 +719,12 @@ public class MessagesQueries {
ResultSet rs = null;
try {
if (before > 0) {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id<? AND (privacy>0 OR user_id=?) AND attach IS NOT NULL AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id<? AND (privacy>0 OR user_id=?) AND attach IS NOT NULL AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, before);
stmt.setInt(2, visitor_uid);
- stmt.setInt(3, visitor_uid);
} else {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND attach IS NOT NULL AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND attach IS NOT NULL AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, visitor_uid);
- stmt.setInt(2, visitor_uid);
}
rs = stmt.executeQuery();
rs.beforeFirst();
@@ -749,11 +747,11 @@ public class MessagesQueries {
try {
if (before > 0) {
- stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) AND id<? AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY id DESC LIMIT 25");
+ stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) AND id<? ORDER BY id DESC LIMIT 25");
stmt.setString(1, search);
stmt.setInt(2, before);
} else {
- stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY id DESC LIMIT 25");
+ stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) ORDER BY id DESC LIMIT 25");
stmt.setString(1, search);
}
rs = stmt.executeQuery();
@@ -770,7 +768,7 @@ public class MessagesQueries {
ArrayList<Integer> mids = new ArrayList<Integer>(20);
if (mids0.size() > 0) {
try {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id IN (" + Utils.convertArrayInt2String(mids0) + ") AND privacy>0 AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id IN (" + Utils.convertArrayInt2String(mids0) + ") AND privacy>0 ORDER BY message_id DESC LIMIT 20");
rs = stmt.executeQuery();
rs.beforeFirst();
while (rs.next()) {
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
index 9140e8ea..ff819629 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;
@@ -25,6 +27,7 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.Random;
import java.util.UUID;
+import java.util.logging.Logger;
/**
*
@@ -34,6 +37,8 @@ public class UserQueries {
static final String ABCDEF = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ private static Logger logger = Logger.getLogger(UserQueries.class.getName());
+
public static String getSignUpHashByJID(Connection sql, String jid) {
String hash = SQLHelpers.getString(sql, "SELECT loginhash FROM jids WHERE jid=? AND user_id IS NULL", jid);
@@ -279,13 +284,14 @@ public class UserQueries {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
- stmt = sql.prepareStatement("SELECT logins.user_id,users.nick FROM logins INNER JOIN users ON logins.user_id=users.id WHERE logins.hash=?");
+ stmt = sql.prepareStatement("SELECT logins.user_id,users.nick, users.banned FROM logins INNER JOIN users ON logins.user_id=users.id WHERE logins.hash=?");
stmt.setString(1, hash);
rs = stmt.executeQuery();
if (rs.first()) {
user = new com.juick.User();
user.UID = rs.getInt(1);
user.UName = rs.getString(2);
+ user.Banned = rs.getBoolean(3);
user.AuthHash = hash;
}
} catch (SQLException e) {
@@ -574,6 +580,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) {
+ logger.throwing(UserQueries.class.getName(), "linkTwitterAccount", 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);
}