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/ActivityPubService.java4
-rw-r--r--src/main/java/com/juick/service/BaseJdbcService.java2
-rw-r--r--src/main/java/com/juick/service/EmailService.java3
-rw-r--r--src/main/java/com/juick/service/EmailServiceImpl.java36
-rw-r--r--src/main/java/com/juick/service/InfoService.java2
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java6
-rw-r--r--src/main/java/com/juick/service/PatreonService.java35
-rw-r--r--src/main/java/com/juick/service/PostgresSearchService.java2
-rw-r--r--src/main/java/com/juick/service/SocialService.java2
-rw-r--r--src/main/java/com/juick/service/SphinxSearchService.java2
-rw-r--r--src/main/java/com/juick/service/SubscriptionServiceImpl.java4
-rw-r--r--src/main/java/com/juick/service/TagServiceImpl.java3
-rw-r--r--src/main/java/com/juick/service/TelegramService.java2
-rw-r--r--src/main/java/com/juick/service/TwitterService.java8
-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.java20
-rw-r--r--src/main/java/com/juick/service/WebfingerService.java2
-rw-r--r--src/main/java/com/juick/service/component/SystemEvent.java2
19 files changed, 134 insertions, 55 deletions
diff --git a/src/main/java/com/juick/service/ActivityPubService.java b/src/main/java/com/juick/service/ActivityPubService.java
index 75a3b488..a63de1b6 100644
--- a/src/main/java/com/juick/service/ActivityPubService.java
+++ b/src/main/java/com/juick/service/ActivityPubService.java
@@ -41,8 +41,8 @@ import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import org.tomitribe.auth.signatures.Base64;
-import javax.annotation.Nonnull;
-import javax.inject.Inject;
+import jakarta.annotation.Nonnull;
+import jakarta.inject.Inject;
import java.io.IOException;
import java.net.URI;
import java.security.MessageDigest;
diff --git a/src/main/java/com/juick/service/BaseJdbcService.java b/src/main/java/com/juick/service/BaseJdbcService.java
index b51cbdc7..415efa89 100644
--- a/src/main/java/com/juick/service/BaseJdbcService.java
+++ b/src/main/java/com/juick/service/BaseJdbcService.java
@@ -21,7 +21,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
-import javax.inject.Inject;
+import jakarta.inject.Inject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
diff --git a/src/main/java/com/juick/service/EmailService.java b/src/main/java/com/juick/service/EmailService.java
index 614cf412..7d8126c5 100644
--- a/src/main/java/com/juick/service/EmailService.java
+++ b/src/main/java/com/juick/service/EmailService.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2023, Juick
+ * Copyright (C) 2008-2024, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -39,4 +39,5 @@ public interface EmailService {
String getEmailByAuthCode(String code);
void deleteAuthCode(String code);
Integer cleanupAuthCodes();
+ boolean isValidEmail(String email);
}
diff --git a/src/main/java/com/juick/service/EmailServiceImpl.java b/src/main/java/com/juick/service/EmailServiceImpl.java
index 383dbdaf..08aaf1b9 100644
--- a/src/main/java/com/juick/service/EmailServiceImpl.java
+++ b/src/main/java/com/juick/service/EmailServiceImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2020, Juick
+ * Copyright (C) 2008-2024, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -17,13 +17,21 @@
package com.juick.service;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.juick.model.User;
+import jakarta.inject.Inject;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
+import java.io.IOException;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
@@ -36,6 +44,13 @@ import java.util.List;
@Transactional
public class EmailServiceImpl extends BaseJdbcService implements EmailService {
+ @Inject
+ private OkHttpClient httpClient;
+ @Inject
+ private ObjectMapper jsonMapper;
+
+ @Value("${email_validation_service_url:http://localhost:8080}")
+ private String emailValidationServiceUrl;
@Override
public boolean verifyAddressByCode(Integer userId, String code) {
try {
@@ -120,4 +135,23 @@ public class EmailServiceImpl extends BaseJdbcService implements EmailService {
new MapSqlParameterSource()
.addValue("day", toDateTime(day.atOffset(ZoneOffset.UTC)), dateTimeType()));
}
+
+ @Override
+ public boolean isValidEmail(String email) {
+ var request = new Request.Builder()
+ .url(emailValidationServiceUrl + "/?email=" + email)
+ .addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
+ .build();
+ try {
+ try(var response = httpClient.newCall(request).execute()) {
+ if (response.isSuccessful() && response.body() != null) {
+ var account = jsonMapper.readTree(response.body().string());
+ return account.has("disposable") && account.get("disposable").textValue().equals("false");
+ }
+ }
+ } catch (IOException e) {
+ return false;
+ }
+ return false;
+ }
}
diff --git a/src/main/java/com/juick/service/InfoService.java b/src/main/java/com/juick/service/InfoService.java
index 9540243e..f6b3cfe1 100644
--- a/src/main/java/com/juick/service/InfoService.java
+++ b/src/main/java/com/juick/service/InfoService.java
@@ -23,7 +23,7 @@ import org.springframework.cache.annotation.Cacheable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
-import javax.inject.Inject;
+import jakarta.inject.Inject;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java
index 940cdaba..de342977 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -38,13 +38,11 @@ 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;
-import javax.inject.Inject;
+import jakarta.inject.Inject;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
@@ -522,7 +520,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
user.setUri(uri);
String path = uri.getPath();
String name = path.substring(path.lastIndexOf('/') + 1);
- user.setName(name + "@" + uri.getHost());
+ user.setName(name);
}
return new ImmutablePair<>(rs.getInt(1), user);
});
diff --git a/src/main/java/com/juick/service/PatreonService.java b/src/main/java/com/juick/service/PatreonService.java
index fdd6d3dd..8f21f389 100644
--- a/src/main/java/com/juick/service/PatreonService.java
+++ b/src/main/java/com/juick/service/PatreonService.java
@@ -20,20 +20,27 @@ package com.juick.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.OkHttpClient;
import okhttp3.Request;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;
-import javax.inject.Inject;
+import jakarta.inject.Inject;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
import java.util.stream.StreamSupport;
@Component
public class PatreonService {
+ private static final Logger logger = LoggerFactory.getLogger("Patreon");
+
+ @Inject
+ private UserService userService;
@Inject
private OkHttpClient httpClient;
@Inject
@@ -89,4 +96,30 @@ public class PatreonService {
}
return List.of();
}
+
+ public void updateStatus(List<String> updatedEmails) {
+ var campainsResponse = fetchCampaigns();
+ List<String> activeEmails = new ArrayList<>();
+ campainsResponse.forEach(campaign -> {
+ var pledgesResponse = fetchPledges(campaign);
+ pledgesResponse.forEach(pledge -> {
+ logger.debug("Pledge email: {}", pledge);
+ activeEmails.add(pledge);
+ });
+ });
+ activeEmails.forEach(email -> {
+ var user = userService.getUserByEmail(email);
+ if (!user.isAnonymous()) {
+ userService.setPremium(user.getUid(), true);
+ }
+ });
+ updatedEmails.stream().filter(email -> !activeEmails.contains(email))
+ .forEach(deleted -> {
+ var user = userService.getUserByEmail(deleted);
+ if (!user.isAnonymous() && user.isPremium()) {
+ logger.debug("User is not a patron anymore: {}", deleted);
+ userService.setPremium(user.getUid(), false);
+ }
+ });
+ }
}
diff --git a/src/main/java/com/juick/service/PostgresSearchService.java b/src/main/java/com/juick/service/PostgresSearchService.java
index a243b3f3..2becf64c 100644
--- a/src/main/java/com/juick/service/PostgresSearchService.java
+++ b/src/main/java/com/juick/service/PostgresSearchService.java
@@ -25,7 +25,7 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
-import javax.inject.Inject;
+import jakarta.inject.Inject;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Collections;
diff --git a/src/main/java/com/juick/service/SocialService.java b/src/main/java/com/juick/service/SocialService.java
index 2dbef8e5..fa280555 100644
--- a/src/main/java/com/juick/service/SocialService.java
+++ b/src/main/java/com/juick/service/SocialService.java
@@ -19,7 +19,7 @@ package com.juick.service;
import com.juick.model.User;
-import javax.annotation.Nonnull;
+import jakarta.annotation.Nonnull;
import java.util.List;
public interface SocialService {
diff --git a/src/main/java/com/juick/service/SphinxSearchService.java b/src/main/java/com/juick/service/SphinxSearchService.java
index 8a608b44..4171b7f3 100644
--- a/src/main/java/com/juick/service/SphinxSearchService.java
+++ b/src/main/java/com/juick/service/SphinxSearchService.java
@@ -24,7 +24,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
-import javax.inject.Inject;
+import jakarta.inject.Inject;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
diff --git a/src/main/java/com/juick/service/SubscriptionServiceImpl.java b/src/main/java/com/juick/service/SubscriptionServiceImpl.java
index 4aa5b5ac..057490f8 100644
--- a/src/main/java/com/juick/service/SubscriptionServiceImpl.java
+++ b/src/main/java/com/juick/service/SubscriptionServiceImpl.java
@@ -30,8 +30,8 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
-import javax.annotation.Nonnull;
-import javax.inject.Inject;
+import jakarta.annotation.Nonnull;
+import jakarta.inject.Inject;
import java.util.Collections;
import java.util.List;
import java.util.Set;
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/TelegramService.java b/src/main/java/com/juick/service/TelegramService.java
index 16ba531d..71c9b9e3 100644
--- a/src/main/java/com/juick/service/TelegramService.java
+++ b/src/main/java/com/juick/service/TelegramService.java
@@ -18,6 +18,7 @@
package com.juick.service;
import com.juick.model.User;
+import org.springframework.cache.annotation.CacheEvict;
import java.util.List;
@@ -32,6 +33,7 @@ public interface TelegramService {
boolean createTelegramUser(long tgID, String tgName);
+ @CacheEvict(value = "users_by_name", allEntries = true)
boolean deleteTelegramUser(Integer uid);
List<Long> getTelegramIdentifiers(List<User> users);
diff --git a/src/main/java/com/juick/service/TwitterService.java b/src/main/java/com/juick/service/TwitterService.java
index ffcaca13..41e73876 100644
--- a/src/main/java/com/juick/service/TwitterService.java
+++ b/src/main/java/com/juick/service/TwitterService.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2023, Juick
+ * Copyright (C) 2008-2024, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -17,7 +17,6 @@
package com.juick.service;
-import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.scribejava.apis.TwitterApi20;
import com.github.scribejava.core.builder.ServiceBuilder;
@@ -27,7 +26,6 @@ import com.github.scribejava.core.model.Verb;
import com.github.scribejava.core.oauth.OAuth20Service;
import com.juick.model.Message;
import com.juick.util.MessageUtils;
-import com.juick.util.formatters.PlainTextFormatter;
import jakarta.annotation.PostConstruct;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -36,7 +34,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
-import javax.inject.Inject;
+import jakarta.inject.Inject;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
@@ -68,7 +66,7 @@ public class TwitterService {
userService.getTwitterToken(jmsg.getUser().getUid()).ifPresent(t -> {
String status = MessageUtils.getMessageHashTags(jmsg) + StringUtils.defaultString(jmsg.getText());
if (status.length() > 253) {
- status = PlainTextFormatter.truncateText(status, 252) + "…";
+ status = StringUtils.abbreviate(status, "…", 252);
}
status += " http://juick.com/" + jmsg.getMid();
try {
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 14d7e3e9..7f6b2516 100644
--- a/src/main/java/com/juick/service/VKService.java
+++ b/src/main/java/com/juick/service/VKService.java
@@ -30,8 +30,9 @@ 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 javax.inject.Inject;
+import jakarta.inject.Inject;
@Service
public class VKService {
@@ -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,14 +51,16 @@ 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()));
}
- public void updatePremiumStatus(Integer userId) {
+ public boolean updatePremiumStatus(Integer userId) {
var vkUser = userService.getVkTokens(userId);
if (vkUser != null) {
OAuth2AccessToken token = new OAuth2AccessToken(vkUser.getRight());
@@ -65,12 +69,13 @@ public class VKService {
getVkAuthService().signRequest(token, donRequest);
try (Response vkResponse = getVkAuthService().execute(donRequest)) {
if (vkResponse.isSuccessful()) {
- logger.info(vkResponse.getBody());
+ logger.debug(vkResponse.getBody());
var response = jsonMapper.readTree(vkResponse.getBody());
if (response.has("response")) {
var isDon = response.get("response").intValue() > 0;
- logger.info("{} is Don: {}", vkUser.getLeft(), isDon);
+ logger.debug("{} is Don: {}", vkUser.getLeft(), isDon);
userService.setPremium(userId, isDon);
+ return isDon;
} else {
// token is expired or does not have "groups" permissions
userService.updateVkToken(userId, "");
@@ -80,8 +85,9 @@ public class VKService {
logger.error("Don request error", e);
}
} else {
- logger.warn("User is not connected to VK: {}", userId);
+ logger.debug("User is not connected to VK: {}", userId);
}
+ return false;
}
public OAuth20Service getVkAuthService() {
diff --git a/src/main/java/com/juick/service/WebfingerService.java b/src/main/java/com/juick/service/WebfingerService.java
index 4accfc94..89ffc230 100644
--- a/src/main/java/com/juick/service/WebfingerService.java
+++ b/src/main/java/com/juick/service/WebfingerService.java
@@ -30,7 +30,7 @@ import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;
import rocks.xmpp.addr.Jid;
-import javax.inject.Inject;
+import jakarta.inject.Inject;
import java.io.IOException;
import java.net.URI;
diff --git a/src/main/java/com/juick/service/component/SystemEvent.java b/src/main/java/com/juick/service/component/SystemEvent.java
index 830813ad..9acd7a2b 100644
--- a/src/main/java/com/juick/service/component/SystemEvent.java
+++ b/src/main/java/com/juick/service/component/SystemEvent.java
@@ -17,7 +17,7 @@
package com.juick.service.component;
-import javax.annotation.Nonnull;
+import jakarta.annotation.Nonnull;
import com.juick.www.api.SystemActivity;
import org.springframework.context.ApplicationEvent;