aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/UserQueries.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-05-19 21:13:16 +0300
committerGravatar Vitaly Takmazov2016-05-19 21:13:46 +0300
commita41109795f6f6a3803d52606df9bd1a0da641f43 (patch)
tree30b14a32b533583b87b5cd884cb7673220ecf02a /src/main/java/com/juick/server/UserQueries.java
parent3fe5180ff7f2488966d3c940629ddefcfc84467f (diff)
fix hash query
Diffstat (limited to 'src/main/java/com/juick/server/UserQueries.java')
-rw-r--r--src/main/java/com/juick/server/UserQueries.java13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
index 1bab7c7f..af7997ea 100644
--- a/src/main/java/com/juick/server/UserQueries.java
+++ b/src/main/java/com/juick/server/UserQueries.java
@@ -184,19 +184,18 @@ public class UserQueries {
}
public static String getHashByUID(JdbcTemplate sql, int uid) {
- String hash = sql.queryForObject("SELECT hash FROM logins WHERE user_id=?", String.class, uid);
-
- if (hash == null) {
- hash = generateHash(16);
- final String finalHash = hash;
+ try {
+ return sql.queryForObject("SELECT hash FROM logins WHERE user_id=?", String.class, uid);
+ } catch (EmptyResultDataAccessException e){
+ String hash = generateHash(16);
sql.update(con -> {
PreparedStatement stmt = con.prepareStatement("INSERT INTO logins(user_id,hash) VALUES (?,?)");
stmt.setInt(1, uid);
- stmt.setString(2, finalHash);
+ stmt.setString(2, hash);
return stmt;
});
+ return hash;
}
- return hash;
}
public static String generateHash(int len) {