diff options
author | Vitaly Takmazov | 2018-05-18 15:33:38 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-07-24 14:35:02 +0300 |
commit | 8a0fbbd35c13054a947ea0d27ca117542bc452b9 (patch) | |
tree | 4266fbfaac3f1e268e780bc1cfa3cdc23ccd955c /juick-common/src/main/java/com/juick/service | |
parent | 3fa18888d5ca53b59c778de3f829870614d05c27 (diff) |
JPA WIP
Diffstat (limited to 'juick-common/src/main/java/com/juick/service')
9 files changed, 49 insertions, 57 deletions
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()); |