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.java36
1 files changed, 30 insertions, 6 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 d1e4eff5..a00eab3f 100644
--- a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
@@ -37,6 +37,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
user.setUid(rs.getInt(1));
user.setName(rs.getString(2));
user.setBanned(rs.getBoolean(3));
+ user.setLang(rs.getString(4));
return user;
}
@@ -109,7 +110,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@Override
public Optional<User> getUserByUID(final int uid) {
List<User> list = getJdbcTemplate().query(
- "SELECT id, nick,banned FROM users WHERE id = ?", new UserMapper(), uid);
+ "SELECT id, nick, banned, lang FROM users WHERE id = ?", new UserMapper(), uid);
return list.isEmpty() ? Optional.empty() : Optional.of(list.get(0));
}
@@ -121,7 +122,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
if (StringUtils.isNotBlank(username)) {
List<User> list = getJdbcTemplate().query(
- "SELECT id, nick, banned FROM users WHERE nick = ?", new UserMapper(), username);
+ "SELECT id, nick, banned, lang FROM users WHERE nick = ?", new UserMapper(), username);
if (!list.isEmpty())
result = list.get(0);
@@ -169,7 +170,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
if (StringUtils.isNotBlank(jid)) {
List<User> list = getJdbcTemplate().query(
- "SELECT id, nick, banned FROM users WHERE id = (SELECT user_id FROM jids WHERE jid = ?)",
+ "SELECT id, nick, banned, lang FROM users WHERE id = (SELECT user_id FROM jids WHERE jid = ?)",
new UserMapper(),
jid);
@@ -186,7 +187,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
return Collections.emptyList();
return getNamedParameterJdbcTemplate().query(
- "SELECT id, nick, banned FROM users WHERE nick IN (:unames)",
+ "SELECT id, nick, banned, lang FROM users WHERE nick IN (:unames)",
new MapSqlParameterSource("unames", unames),
new UserMapper());
}
@@ -198,7 +199,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
return Collections.emptyList();
return getNamedParameterJdbcTemplate().query(
- "SELECT id, nick, banned FROM users WHERE id IN (:ids)",
+ "SELECT id, nick, banned, lang FROM users WHERE id IN (:ids)",
new MapSqlParameterSource("ids", uids),
new UserMapper());
}
@@ -273,7 +274,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.banned FROM logins " +
+ "SELECT logins.user_id, users.nick, users.banned, users.lang FROM logins " +
"INNER JOIN users ON logins.user_id = users.id WHERE logins.hash = ?",
new UserMapper(),
hash);
@@ -651,4 +652,27 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
user.getUid());
return list.isEmpty() ? "" : list.get(0) + "@mail.juick.com";
}
+
+ @Transactional
+ @Override
+ public int deleteLoginForUser(final String name) {
+ if (StringUtils.isBlank(name))
+ return 0;
+
+ return getJdbcTemplate().update(
+ "delete from logins where user_id in (select id from users where nick = ?)", name);
+ }
+
+ @Transactional
+ @Override
+ public int setLoginForUser(final int uid, final String loginHash) {
+ if (StringUtils.isEmpty(loginHash))
+ return 0;
+
+ return getNamedParameterJdbcTemplate().update(
+ "INSERT INTO logins (user_id, hash) VALUES(:uid, :hash) ON DUPLICATE KEY UPDATE hash = :hash",
+ new MapSqlParameterSource()
+ .addValue("hash", loginHash)
+ .addValue("uid", uid));
+ }
}