aboutsummaryrefslogtreecommitdiff
path: root/juick-common/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-05-18 15:33:38 +0300
committerGravatar Vitaly Takmazov2018-07-24 14:35:02 +0300
commit8a0fbbd35c13054a947ea0d27ca117542bc452b9 (patch)
tree4266fbfaac3f1e268e780bc1cfa3cdc23ccd955c /juick-common/src/main/java/com
parent3fa18888d5ca53b59c778de3f829870614d05c27 (diff)
JPA WIP
Diffstat (limited to 'juick-common/src/main/java/com')
-rw-r--r--juick-common/src/main/java/com/juick/server/CommandsManager.java11
-rw-r--r--juick-common/src/main/java/com/juick/service/CrosspostService.java33
-rw-r--r--juick-common/src/main/java/com/juick/service/EmailService.java16
-rw-r--r--juick-common/src/main/java/com/juick/service/MessagesService.java3
-rw-r--r--juick-common/src/main/java/com/juick/service/PMQueriesService.java18
-rw-r--r--juick-common/src/main/java/com/juick/service/TelegramService.java2
-rw-r--r--juick-common/src/main/java/com/juick/service/UserService.java18
-rw-r--r--juick-common/src/main/java/com/juick/service/security/HashParamAuthenticationFilter.java2
-rw-r--r--juick-common/src/main/java/com/juick/service/security/JuickUserDetailsService.java2
-rw-r--r--juick-common/src/main/java/com/juick/service/security/deprecated/CookieSimpleHashRememberMeServices.java12
10 files changed, 54 insertions, 63 deletions
diff --git a/juick-common/src/main/java/com/juick/server/CommandsManager.java b/juick-common/src/main/java/com/juick/server/CommandsManager.java
index 7dd372b1..a5484f75 100644
--- a/juick-common/src/main/java/com/juick/server/CommandsManager.java
+++ b/juick-common/src/main/java/com/juick/server/CommandsManager.java
@@ -114,13 +114,12 @@ public class CommandsManager {
: HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost();
attachmentType = attachmentFName.substring(attachmentFName.length() - 3);
}
- int mid = messagesService.createMessage(user.getUid(), body, attachmentType, tags);
- subscriptionService.subscribeMessage(messagesService.getMessage(mid), user);
+ com.juick.Message msg = messagesService.createMessage(user, body, attachmentType, tags);
+ subscriptionService.subscribeMessage(msg, user);
if (haveAttachment) {
- String fname = String.format("%d.%s", mid, attachmentType);
+ String fname = String.format("%d.%s", msg.getMid(), attachmentType);
imagesService.saveImageWithPreviews(attachmentFName, fname);
}
- com.juick.Message msg = messagesService.getMessage(mid);
applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, msg));
applicationEventPublisher.publishEvent(new MessageEvent(this, msg, subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg.getMid())));
return CommandResult.build(msg, "New message posted.\n#" + msg.getMid() + " https://juick.com/m/" + msg.getMid(), String.format("[New message](%s) posted", PlainTextFormatter.formatUrl(msg)));
@@ -145,7 +144,7 @@ public class CommandsManager {
@UserCommand(pattern = "^login$", patternFlags = Pattern.CASE_INSENSITIVE,
help = "LOGIN - log in to Juick website")
public CommandResult commandLogin(User user_from, URI attachment, String[] input) {
- return CommandResult.fromString("http://juick.com/login?hash=" + userService.getHashByUID(user_from.getUid()));
+ return CommandResult.fromString("http://juick.com/login?hash=" + userService.getHashForUser(user_from));
}
@UserCommand(pattern = "^\\@(\\S+)\\s+([\\s\\S]+)$", help = "@username message - send PM to username")
public CommandResult commandPM(User user_from, URI attachment, String... arguments) {
@@ -155,7 +154,7 @@ public class CommandsManager {
if (!user_to.isAnonymous()) {
if (!userService.isInBLAny(user_to.getUid(), user_from.getUid())) {
- if (pmQueriesService.createPM(user_from.getUid(), user_to.getUid(), body)) {
+ if (pmQueriesService.createPM(user_from, user_to, body)) {
com.juick.Message jmsg = new com.juick.Message();
jmsg.setUser(user_from);
jmsg.setTo(user_to);
diff --git a/juick-common/src/main/java/com/juick/service/CrosspostService.java b/juick-common/src/main/java/com/juick/service/CrosspostService.java
index 38481d72..20f12681 100644
--- a/juick-common/src/main/java/com/juick/service/CrosspostService.java
+++ b/juick-common/src/main/java/com/juick/service/CrosspostService.java
@@ -18,6 +18,7 @@
package com.juick.service;
import com.juick.ExternalToken;
+import com.juick.User;
import com.juick.server.helpers.ApplicationStatus;
import org.apache.commons.lang3.tuple.Pair;
@@ -29,9 +30,9 @@ import java.util.Optional;
*/
public interface CrosspostService {
- Optional<ExternalToken> getTwitterToken(int uid);
+ Optional<ExternalToken> getTwitterToken(User user);
- boolean deleteTwitterToken(Integer uid);
+ boolean deleteTwitterToken(User user);
void addFacebookState(String state, String redirectUri);
@@ -41,30 +42,30 @@ public interface CrosspostService {
String verifyVKState(String state);
- Optional<Pair<String, String>> getFacebookTokens(int uid);
+ Optional<Pair<String, String>> getFacebookTokens(User user);
- ApplicationStatus getFbCrossPostStatus(int uid);
+ ApplicationStatus getFbCrossPostStatus(User user);
- boolean enableFBCrosspost(Integer uid);
+ boolean enableFBCrosspost(User user);
- void disableFBCrosspost(Integer uid);
+ void disableFBCrosspost(User user);
@Nonnull
- String getTwitterName(int uid);
+ String getTwitterName(User user);
- String getTelegramName(int uid);
+ String getTelegramName(User user);
- Optional<Pair<String, String>> getVkTokens(int uid);
+ Optional<Pair<String, String>> getVkTokens(User user);
- void deleteVKUser(Integer uid);
+ void deleteVKUser(User user);
- int getUIDbyFBID(long fbID);
+ Optional<User> getUserByFBID(long fbID);
boolean createFacebookUser(long fbID, String loginhash, String token, String fbName, String fbLink);
boolean updateFacebookUser(long fbID, String token, String fbName, String fbLink);
- int getUIDbyVKID(long vkID);
+ Optional<User> getUserByVKID(long vkID);
boolean createVKUser(long vkID, String loginhash, String token, String vkName, String vkLink);
@@ -72,15 +73,15 @@ public interface CrosspostService {
String getTelegramNameByHash(String hash);
- boolean setFacebookUser(String hash, int uid);
+ boolean setFacebookUser(String hash, User user);
String getVKNameByHash(String hash);
- boolean setVKUser(String hash, int uid);
+ boolean setVKUser(String hash, User user);
- boolean setTelegramUser(String hash, int uid);
+ boolean setTelegramUser(String hash, User user);
String getJIDByHash(String hash);
- boolean setJIDUser(String hash, int uid);
+ boolean setJIDUser(String hash, User user);
}
diff --git a/juick-common/src/main/java/com/juick/service/EmailService.java b/juick-common/src/main/java/com/juick/service/EmailService.java
index 2440bcb4..74ca7c71 100644
--- a/juick-common/src/main/java/com/juick/service/EmailService.java
+++ b/juick-common/src/main/java/com/juick/service/EmailService.java
@@ -17,17 +17,19 @@
package com.juick.service;
+import com.juick.User;
+
import java.util.List;
/**
* Created by vitalyster on 09.12.2016.
*/
public interface EmailService {
- boolean verifyAddressByCode(Integer userId, String code);
- boolean addVerificationCode(Integer userId, String account, String code);
- boolean addEmail(Integer userId, String email);
- boolean deleteEmail(Integer userId, String account);
- String getNotificationsEmail(Integer userId);
- boolean setNotificationsEmail(Integer userId, String account);
- List<String> getEmails(Integer userId, boolean active);
+ boolean verifyAddressByCode(User user, String code);
+ boolean addVerificationCode(User user, String account, String code);
+ boolean addEmail(User user, String email);
+ boolean deleteEmail(User user, String account);
+ String getNotificationsEmail(User user);
+ boolean setNotificationsEmail(User user, String account);
+ List<String> getEmails(User user, boolean active);
}
diff --git a/juick-common/src/main/java/com/juick/service/MessagesService.java b/juick-common/src/main/java/com/juick/service/MessagesService.java
index 30719cc6..4e6477d3 100644
--- a/juick-common/src/main/java/com/juick/service/MessagesService.java
+++ b/juick-common/src/main/java/com/juick/service/MessagesService.java
@@ -17,6 +17,7 @@
package com.juick.service;
+import com.juick.Message;
import com.juick.Reaction;
import com.juick.User;
import com.juick.server.helpers.ResponseReply;
@@ -30,7 +31,7 @@ import java.util.Set;
* Created by aalexeev on 11/13/16.
*/
public interface MessagesService {
- int createMessage(int uid, String txt, String attachment, Collection<com.juick.Tag> tags);
+ Message createMessage(User user, String txt, String attachment, Collection<com.juick.Tag> tags);
int createReply(int mid, int rid, User user, String txt, String attachment);
diff --git a/juick-common/src/main/java/com/juick/service/PMQueriesService.java b/juick-common/src/main/java/com/juick/service/PMQueriesService.java
index 4c70eece..45d6754e 100644
--- a/juick-common/src/main/java/com/juick/service/PMQueriesService.java
+++ b/juick-common/src/main/java/com/juick/service/PMQueriesService.java
@@ -25,21 +25,19 @@ import java.util.List;
* Created by aalexeev on 11/13/16.
*/
public interface PMQueriesService {
- boolean createPM(int uidFrom, int uid_to, String body);
+ boolean createPM(User me, User to, String body);
- boolean addPMinRoster(int uid, String jid);
+ boolean addPMinRoster(User me, String jid);
- boolean removePMinRoster(int uid, String jid);
+ boolean removePMinRoster(User me, String jid);
- boolean havePMinRoster(int uid, String jid);
+ boolean havePMinRoster(User me, String jid);
- String getLastView(int uidFrom, int uidTo);
+ List<User> getPMLastConversationsUsers(User me, int cnt);
- List<User> getPMLastConversationsUsers(int uid, int cnt);
+ List<com.juick.Message> getPMMessages(User me, User to);
- List<com.juick.Message> getPMMessages(int uid, int uidTo);
+ List<com.juick.Message> getLastPMInbox(User me);
- List<com.juick.Message> getLastPMInbox(int uid);
-
- List<com.juick.Message> getLastPMSent(int uid);
+ List<com.juick.Message> getLastPMSent(User me);
}
diff --git a/juick-common/src/main/java/com/juick/service/TelegramService.java b/juick-common/src/main/java/com/juick/service/TelegramService.java
index 7786ca9f..4323df35 100644
--- a/juick-common/src/main/java/com/juick/service/TelegramService.java
+++ b/juick-common/src/main/java/com/juick/service/TelegramService.java
@@ -31,7 +31,7 @@ public interface TelegramService {
List<Long> getChats();
- int getUser(long tgId);
+ User getUser(long tgId);
boolean createTelegramUser(long tgID, String tgName);
diff --git a/juick-common/src/main/java/com/juick/service/UserService.java b/juick-common/src/main/java/com/juick/service/UserService.java
index df62f0ef..de856adf 100644
--- a/juick-common/src/main/java/com/juick/service/UserService.java
+++ b/juick-common/src/main/java/com/juick/service/UserService.java
@@ -39,7 +39,7 @@ public interface UserService {
String getSignUpHashByTelegramID(Long telegramId, String username);
- int createUser(String username, String password);
+ User createUser(String username, String password);
Optional<User> getUserByUID(int uid);
@@ -49,8 +49,6 @@ public interface UserService {
User getUserByEmail(String email);
- List<User> getFullyUsersByNames(Collection<String> usernames);
-
User getUserByJID(String jid);
List<User> getUsersByName(Collection<String> unames);
@@ -59,17 +57,11 @@ public interface UserService {
List<String> getJIDsbyUID(int uid);
- int getUIDbyJID(String jid);
-
- int getUIDbyName(String uname);
-
- int getUIDbyHash(String hash);
-
com.juick.User getUserByHash(String hash);
- String getHashByUID(int uid);
+ String getHashForUser(User user);
- int checkPassword(String username, String password);
+ User checkPassword(String username, String password);
boolean updatePassword(User user, String newPassword);
@@ -81,8 +73,6 @@ public interface UserService {
boolean updateUserInfo(User user, UserInfo info);
- boolean getCanMedia(int uid);
-
boolean isInWL(int uid, int check);
boolean isInBL(int uid, int check);
@@ -117,7 +107,7 @@ public interface UserService {
List<Auth> getAuthCodes(User user);
- List<String> getEmails(User user);
+ Collection<String> getEmails(User user);
String getEmailHash(User user);
diff --git a/juick-common/src/main/java/com/juick/service/security/HashParamAuthenticationFilter.java b/juick-common/src/main/java/com/juick/service/security/HashParamAuthenticationFilter.java
index b56b98c8..9bf83f86 100644
--- a/juick-common/src/main/java/com/juick/service/security/HashParamAuthenticationFilter.java
+++ b/juick-common/src/main/java/com/juick/service/security/HashParamAuthenticationFilter.java
@@ -70,7 +70,7 @@ public class HashParamAuthenticationFilter extends OncePerRequestFilter {
if (!user.isAnonymous()) {
User userWithPassword = userService.getFullyUserByName(user.getName());
- userWithPassword.setAuthHash(userService.getHashByUID(userWithPassword.getUid()));
+ userWithPassword.setAuthHash(userService.getHashForUser(userWithPassword));
Authentication authentication = new RememberMeAuthenticationToken(
((AbstractRememberMeServices)rememberMeServices).getKey(), new JuickUser(userWithPassword), JuickUser.USER_AUTHORITY);
diff --git a/juick-common/src/main/java/com/juick/service/security/JuickUserDetailsService.java b/juick-common/src/main/java/com/juick/service/security/JuickUserDetailsService.java
index f6ae8909..78293f38 100644
--- a/juick-common/src/main/java/com/juick/service/security/JuickUserDetailsService.java
+++ b/juick-common/src/main/java/com/juick/service/security/JuickUserDetailsService.java
@@ -44,7 +44,7 @@ public class JuickUserDetailsService implements UserDetailsService {
com.juick.User user = userService.getFullyUserByName(username);
if (user != null) {
- user.setAuthHash(userService.getHashByUID(user.getUid()));
+ user.setAuthHash(userService.getHashForUser(user));
return new JuickUser(user);
}
diff --git a/juick-common/src/main/java/com/juick/service/security/deprecated/CookieSimpleHashRememberMeServices.java b/juick-common/src/main/java/com/juick/service/security/deprecated/CookieSimpleHashRememberMeServices.java
index b658e16f..019ee502 100644
--- a/juick-common/src/main/java/com/juick/service/security/deprecated/CookieSimpleHashRememberMeServices.java
+++ b/juick-common/src/main/java/com/juick/service/security/deprecated/CookieSimpleHashRememberMeServices.java
@@ -80,13 +80,13 @@ public class CookieSimpleHashRememberMeServices extends AbstractRememberMeServic
logger.debug("Creating new persistent login for user {}", username);
try {
- int uid = userService.getUIDbyName(username);
+ User user = userService.getUserByName(username);
- Assert.isTrue(uid > 0);
+ Assert.isTrue(user.getUid() > 0);
String hash = RandomStringUtils.randomAlphanumeric(16).toUpperCase();
- userService.setLoginForUser(uid, hash);
+ userService.setLoginForUser(user.getUid(), hash);
setCookie(new String[]{hash}, getTokenValiditySeconds(), request, response);
} catch (Exception e) {
@@ -107,11 +107,11 @@ public class CookieSimpleHashRememberMeServices extends AbstractRememberMeServic
throw new InvalidCookieException("Cookie is invalid and hash parameter not found");
}
- int uid = userService.getUIDbyHash(hash);
- if (uid <= 0)
+ User user = userService.getUserByHash(hash);
+ if (user.getUid() <= 0)
throw new UsernameNotFoundException("User not found by hash, cookies" + cookieTokens);
- Optional<User> userOptional = userService.getUserByUID(uid);
+ Optional<User> userOptional = userService.getUserByUID(user.getUid());
Assert.isTrue(userOptional.isPresent());