diff options
author | Vitaly Takmazov | 2016-01-26 02:04:46 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-01-26 02:04:46 +0300 |
commit | 8a77f7d91311f8c4d8ef026dacb4abbe0fa764d1 (patch) | |
tree | 49ca57fb5669e75809bd3c3c80065a8d55be7e08 /src/main/java/com/juick/server/UserQueries.java | |
parent | 8ae5d9e3ce643bf0b8488c4566eff133b2cb2f11 (diff) |
refactoring
Diffstat (limited to 'src/main/java/com/juick/server/UserQueries.java')
-rw-r--r-- | src/main/java/com/juick/server/UserQueries.java | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java index 948b42d4..226e21b1 100644 --- a/src/main/java/com/juick/server/UserQueries.java +++ b/src/main/java/com/juick/server/UserQueries.java @@ -100,14 +100,12 @@ public class UserQueries { public static User getUserByJID(JdbcTemplate sql, String jid) { return sql.queryForObject("SELECT id,nick,banned FROM users WHERE id=(SELECT user_id FROM jids WHERE jid=?)", - new Object[] {jid}, - new UserMapper()); + new UserMapper(), jid); } public static List<User> getUsersByName(JdbcTemplate sql, List<String> unames) { - return sql.query("SELECT id,nick,banned FROM users WHERE id=(SELECT user_id FROM jids WHERE jid=?)", - new UserMapper(), - unames.toArray()); + return sql.query("SELECT id,nick FROM users WHERE nick IN (" + Utils.convertArrayString2String(unames) + ")", + new UserMapper()); } public static List<User> getUsersByID(JdbcTemplate sql, List<Integer> uids) { @@ -204,10 +202,19 @@ public class UserQueries { } public static int checkPassword(JdbcTemplate sql, String username, String password) { - String realPassword = sql.queryForObject("SELECT passw FROM users WHERE nick=?", String.class, username); - if (realPassword.equals(password)) { - return UserQueries.getUserByName(sql, username).getUID(); - } else { + try { + String realPassword = sql.queryForObject("SELECT passw FROM users WHERE nick=?", String.class, username); + if (realPassword.equals(password)) { + User user = UserQueries.getUserByName(sql, username); + if (user != null) { + return user.getUID(); + } else { + return -1; + } + } else { + return -1; + } + } catch (EmptyResultDataAccessException e) { return -1; } } |