aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/service')
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java2
-rw-r--r--src/main/java/com/juick/service/TagServiceImpl.java3
-rw-r--r--src/main/java/com/juick/service/UserService.java5
-rw-r--r--src/main/java/com/juick/service/UserServiceImpl.java49
-rw-r--r--src/main/java/com/juick/service/VKService.java8
5 files changed, 38 insertions, 29 deletions
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java
index bad080a0..de342977 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -38,8 +38,6 @@ import org.springframework.jdbc.core.ConnectionCallback;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
-import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
-import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
diff --git a/src/main/java/com/juick/service/TagServiceImpl.java b/src/main/java/com/juick/service/TagServiceImpl.java
index 9f5c9356..1eea6812 100644
--- a/src/main/java/com/juick/service/TagServiceImpl.java
+++ b/src/main/java/com/juick/service/TagServiceImpl.java
@@ -27,15 +27,12 @@ import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-import org.springframework.jdbc.support.GeneratedKeyHolder;
-import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Statement;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java
index 6f7cb58f..845028f7 100644
--- a/src/main/java/com/juick/service/UserService.java
+++ b/src/main/java/com/juick/service/UserService.java
@@ -32,7 +32,6 @@ import org.springframework.cache.annotation.Cacheable;
import java.util.Collection;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
/**
@@ -83,6 +82,8 @@ public interface UserService {
boolean updateUserInfo(User info);
+ boolean updateLanguage(User user);
+
boolean isInWL(int uid, int check);
boolean isInBL(int uid, int check);
@@ -170,7 +171,7 @@ public interface UserService {
boolean updateFacebookUser(long fbID, String token, String fbName);
- int getUIDbyVKID(long vkID);
+ Optional<User> getUserByVKID(long vkID);
boolean createVKUser(long vkID, String loginhash, String token, String vkName, String vkLink);
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java
index 0bbeea91..bad1378a 100644
--- a/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/src/main/java/com/juick/service/UserServiceImpl.java
@@ -27,16 +27,10 @@ import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.jdbc.UncategorizedSQLException;
-import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
-import org.springframework.jdbc.support.GeneratedKeyHolder;
-import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@@ -71,6 +65,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
user.setVerified(rs.getLong(6) > 0);
user.setPremium(rs.getInt(7) > 0);
user.setAdmin(adminUsers.contains(user.getName()));
+ user.setLanguage(rs.getString("lang"));
return user;
}
}
@@ -125,7 +120,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
public Optional<User> getUserByUID(final int uid) {
var list = getJdbcTemplate().query("""
SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen,
- COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium
+ COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium, lang
FROM users u LEFT JOIN facebook f ON f.user_id = u.id
LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id
LEFT JOIN emails e ON e.user_id = u.id WHERE u.id = ?""", userMapper, uid);
@@ -139,7 +134,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
if (StringUtils.isNotBlank(username)) {
var list = getJdbcTemplate().query("""
SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen,
- COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium
+ COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium, lang
FROM users u LEFT JOIN facebook f ON f.user_id = u.id
LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id
LEFT JOIN emails e ON e.user_id = u.id
@@ -164,7 +159,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
try {
List<User> list = getJdbcTemplate().query(
"SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen, " +
- "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium " +
+ "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium, lang " +
"FROM users u LEFT JOIN facebook f ON f.user_id = u.id " +
"LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id " +
"LEFT JOIN emails e ON e.user_id = u.id " +
@@ -190,7 +185,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
if (StringUtils.isNotBlank(jid)) {
List<User> list = getJdbcTemplate().query(
"SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen," +
- "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium " +
+ "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium, lang " +
"FROM users u LEFT JOIN facebook f ON f.user_id = u.id " +
"LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id " +
"LEFT JOIN emails e ON e.user_id = u.id " +
@@ -212,7 +207,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
return getNamedParameterJdbcTemplate().query(
"SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen," +
- "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium " +
+ "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium, lang " +
"FROM users u LEFT JOIN facebook f ON f.user_id = u.id " +
"LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id " +
"LEFT JOIN emails e ON e.user_id = u.id " +
@@ -229,7 +224,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
return getNamedParameterJdbcTemplate().query(
"SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen," +
- "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium " +
+ "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium, lang " +
"FROM users u LEFT JOIN facebook f ON f.user_id = u.id " +
"LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id " +
"LEFT JOIN emails e ON e.user_id = u.id " +
@@ -264,7 +259,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
if (StringUtils.isNotBlank(hash)) {
List<User> list = getJdbcTemplate().query(
"SELECT DISTINCT logins.user_id, u.nick, u.passw, u.banned, u.last_seen," +
- "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium " +
+ "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium, lang " +
"FROM logins INNER JOIN users u ON logins.user_id = u.id " +
"LEFT JOIN facebook f ON f.user_id = u.id " +
"LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id " +
@@ -302,7 +297,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
if (StringUtils.isNotBlank(username)) {
List<User> list = getJdbcTemplate().query(
"SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen," +
- "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium " +
+ "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium, lang " +
"FROM users u LEFT JOIN facebook f ON f.user_id = u.id " +
"LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id " +
"LEFT JOIN emails e ON e.user_id = u.id " +
@@ -368,6 +363,15 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
}
}
+ @Transactional
+ @Override
+ public boolean updateLanguage(final User user) {
+ return getJdbcTemplate().update(
+ "UPDATE users SET lang=? WHERE id=?",
+ user.getLanguage(),
+ user.getUid()) > 0;
+ }
+
@Transactional(readOnly = true)
@Override
public boolean isInWL(final int uid, final int check) {
@@ -758,7 +762,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
List<User> list = getJdbcTemplate().query(
"""
SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen,
- COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium
+ COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium, lang
FROM users u LEFT JOIN facebook f ON f.user_id = u.id
LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id
LEFT JOIN emails e ON e.user_id = u.id
@@ -791,7 +795,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
public Optional<User> getUserByFacebookId(long facebookId) {
List<User> list = getJdbcTemplate().query(
"SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen, " +
- "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium " +
+ "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium, lang " +
"FROM users u LEFT JOIN facebook f ON f.user_id = u.id " +
"LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id " +
"LEFT JOIN emails e ON e.user_id = u.id WHERE f.fb_id = ?", new UserMapper(), facebookId);
@@ -815,10 +819,15 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@Transactional(readOnly = true)
@Override
- public int getUIDbyVKID(long vkID) {
- var users = getJdbcTemplate().queryForList("""
- SELECT user_id FROM vk WHERE vk_id=? AND user_id IS NOT NULL""", Integer.class, vkID);
- return users.isEmpty() ? 0 : users.get(0);
+ public Optional<User> getUserByVKID(long vkID) {
+ List<User> list = getJdbcTemplate().query(
+ "SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen, " +
+ "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium, lang " +
+ "FROM users u LEFT JOIN facebook f ON f.user_id = u.id " +
+ "LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id " +
+ "LEFT JOIN emails e ON e.user_id = u.id WHERE vk.vk_id = ?", new UserMapper(), vkID);
+
+ return list.isEmpty() ? Optional.empty() : Optional.of(list.get(0));
}
@Transactional
diff --git a/src/main/java/com/juick/service/VKService.java b/src/main/java/com/juick/service/VKService.java
index b9b2483f..7f6b2516 100644
--- a/src/main/java/com/juick/service/VKService.java
+++ b/src/main/java/com/juick/service/VKService.java
@@ -30,6 +30,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
+import org.springframework.web.util.UriComponentsBuilder;
import jakarta.inject.Inject;
@@ -40,7 +41,8 @@ public class VKService {
private String VK_APPID;
@Value("${vk_secret:secret}")
private String VK_SECRET;
- private static final String VK_REDIRECT = "https://juick.com/_vklogin";
+ @Value("${ap_base_uri:http://localhost:8080/}")
+ private String baseUri;
@Inject
private ObjectMapper jsonMapper;
@Inject
@@ -49,10 +51,12 @@ public class VKService {
@PostConstruct
public void init() {
+ UriComponentsBuilder redirectBuilder = UriComponentsBuilder.fromUriString(baseUri);
+ String redirectUri = redirectBuilder.replacePath("/_vklogin").build().toUriString();
ServiceBuilder vkBuilder = new ServiceBuilder(VK_APPID);
setVkAuthService(vkBuilder.apiSecret(VK_SECRET)
.defaultScope("friends,wall,offline,groups")
- .callback(VK_REDIRECT)
+ .callback(redirectUri)
.build(VkontakteApi.instance()));
}