aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/service
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com/juick/service')
-rw-r--r--juick-server/src/main/java/com/juick/service/UserServiceImpl.java56
1 files changed, 35 insertions, 21 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 a84f2fc3..2bdc4d41 100644
--- a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
@@ -1,7 +1,6 @@
package com.juick.service;
import com.juick.User;
-import com.juick.server.UserQueries;
import com.juick.server.helpers.Auth;
import com.juick.server.helpers.EmailOpts;
import com.juick.server.helpers.UserInfo;
@@ -112,30 +111,39 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
List<User> list = getJdbcTemplate().query(
"SELECT id, nick,banned FROM users WHERE id = ?", new UserMapper(), uid);
- return list.isEmpty() ?
- Optional.empty() : Optional.of(list.get(0));
+ return list.isEmpty() ? Optional.empty() : Optional.of(list.get(0));
}
@Transactional(readOnly = true)
@Override
public User getUserByName(final String username) {
- List<User> list = getJdbcTemplate().query(
- "SELECT id, nick, banned FROM users WHERE nick = ?", new UserMapper(), username);
+ User result = null;
+
+ if (StringUtils.isNotBlank(username)) {
+ List<User> list = getJdbcTemplate().query(
+ "SELECT id, nick, banned FROM users WHERE nick = ?", new UserMapper(), username);
- return list.isEmpty() ?
- null : list.get(0);
+ if (!list.isEmpty())
+ result = list.get(0);
+ }
+ return result;
}
@Transactional(readOnly = true)
@Override
public User getUserByJID(final String jid) {
- List<User> list = getJdbcTemplate().query(
- "SELECT id, nick, banned FROM users WHERE id = (SELECT user_id FROM jids WHERE jid = ?)",
- new UserMapper(),
- jid);
+ User result = null;
+
+ if (StringUtils.isNotBlank(jid)) {
+ List<User> list = getJdbcTemplate().query(
+ "SELECT id, nick, banned FROM users WHERE id = (SELECT user_id FROM jids WHERE jid = ?)",
+ new UserMapper(),
+ jid);
- return list.isEmpty() ?
- null : list.get(0);
+ if (!list.isEmpty())
+ result = list.get(0);
+ }
+ return result;
}
@Transactional(readOnly = true)
@@ -276,16 +284,22 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@Override
public int checkPassword(final String username, final String password) {
if (StringUtils.isNotBlank(username)) {
- List<String> list = getJdbcTemplate().queryForList(
- "SELECT passw FROM users WHERE nick = ?", String.class, username);
+ List<User> list = getJdbcTemplate().query(
+ "SELECT id, nick, banned, passw FROM users WHERE nick = ?",
+ (rs, rowNum) -> {
+ User user = new User();
+ user.setUid(rs.getInt(1));
+ user.setName(rs.getString(2));
+ user.setBanned(rs.getBoolean(3));
+ user.setCredentials(rs.getString(4));
+ return user;
+ },
+ username);
if (!list.isEmpty()) {
- String realPassword = list.get(0);
- if (realPassword.equals(password)) {
- User user = getUserByName(username);
- if (user != null)
- return user.getUid();
- }
+ User user = list.get(0);
+ if (Objects.equals(password, user.getCredentials()))
+ return user.getUid();
}
}
return -1;