aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com/juick/service/UserServiceImpl.java')
-rw-r--r--juick-server/src/main/java/com/juick/service/UserServiceImpl.java33
1 files changed, 24 insertions, 9 deletions
diff --git a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
index 0eae1ae3..fdc4f28c 100644
--- a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
@@ -39,7 +39,13 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.*;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.UUID;
/**
* Created by aalexeev on 11/13/16.
@@ -56,6 +62,10 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
user.setName(rs.getString(2));
user.setCredentials(rs.getString(3));
user.setBanned(rs.getBoolean(4));
+ Timestamp seen = rs.getTimestamp(5);
+ if (seen != null) {
+ user.setSeen(seen.toInstant());
+ }
return user;
}
}
@@ -122,7 +132,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@Override
public Optional<User> getUserByUID(final int uid) {
List<User> list = getJdbcTemplate().query(
- "SELECT id, nick, passw, banned FROM users WHERE id = ?", new UserMapper(), uid);
+ "SELECT id, nick, passw, banned, last_seen FROM users WHERE id = ?", new UserMapper(), uid);
return list.isEmpty() ? Optional.empty() : Optional.of(list.get(0));
}
@@ -133,7 +143,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
public User getUserByName(final String username) {
if (StringUtils.isNotBlank(username)) {
List<User> list = getJdbcTemplate().query(
- "SELECT id, nick, passw, banned FROM users WHERE nick = ?", new UserMapper(), username);
+ "SELECT id, nick, passw, banned, last_seen FROM users WHERE nick = ?", new UserMapper(), username);
if (!list.isEmpty())
return list.get(0);
@@ -147,7 +157,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
public User getUserByEmail(String email) {
if (StringUtils.isNotBlank(email)) {
List<User> list = getJdbcTemplate().query(
- "SELECT id, nick, passw, banned FROM users WHERE id = (SELECT DISTINCT user_id FROM emails WHERE email = ?)",
+ "SELECT id, nick, passw, banned, last_seen FROM users WHERE id = (SELECT DISTINCT user_id FROM emails WHERE email = ?)",
new UserMapper(),
email);
@@ -164,7 +174,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
if (StringUtils.isNotBlank(jid)) {
List<User> list = getJdbcTemplate().query(
- "SELECT id, nick, passw, banned FROM users WHERE id = (SELECT user_id FROM jids WHERE jid = ?)",
+ "SELECT id, nick, passw, banned, last_seen FROM users WHERE id = (SELECT user_id FROM jids WHERE jid = ?)",
new UserMapper(),
jid);
@@ -181,7 +191,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
return Collections.emptyList();
return getNamedParameterJdbcTemplate().query(
- "SELECT id, nick, passw, banned FROM users WHERE nick IN (:unames)",
+ "SELECT id, nick, passw, banned, last_seen FROM users WHERE nick IN (:unames)",
new MapSqlParameterSource("unames", unames),
new UserMapper());
}
@@ -193,7 +203,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
return Collections.emptyList();
return getNamedParameterJdbcTemplate().query(
- "SELECT id, nick, passw, banned FROM users WHERE id IN (:ids)",
+ "SELECT id, nick, passw, banned, last_seen FROM users WHERE id IN (:ids)",
new MapSqlParameterSource("ids", uids),
new UserMapper());
}
@@ -248,7 +258,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
public com.juick.User getUserByHash(final String hash) {
if (StringUtils.isNotBlank(hash)) {
List<User> list = getJdbcTemplate().query(
- "SELECT logins.user_id, users.nick, users.passw, users.banned FROM logins " +
+ "SELECT logins.user_id, users.nick, users.passw, users.banned, last_seen FROM logins " +
"INNER JOIN users ON logins.user_id = users.id WHERE logins.hash = ?",
new UserMapper(),
hash);
@@ -281,7 +291,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
public int checkPassword(final String username, final String password) {
if (StringUtils.isNotBlank(username)) {
List<User> list = getJdbcTemplate().query(
- "SELECT id, nick, passw, banned FROM users WHERE nick = ?",
+ "SELECT id, nick, passw, banned, last_seen FROM users WHERE nick = ?",
new UserMapper(),
username);
@@ -650,4 +660,9 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
public List<String> getActiveJIDs() {
return getJdbcTemplate().queryForList("SELECT jid FROM jids WHERE active=1 AND loginhash IS NULL", String.class);
}
+
+ @Override
+ public void updateLastSeen(User user) {
+ getJdbcTemplate().update("UPDATE users SET last_seen=now() WHERE id=?", user.getUid());
+ }
}