diff options
Diffstat (limited to 'juick-server/src')
6 files changed, 74 insertions, 1 deletions
diff --git a/juick-server/src/main/java/com/juick/service/CrosspostService.java b/juick-server/src/main/java/com/juick/service/CrosspostService.java index 88821b606..725ef2973 100644 --- a/juick-server/src/main/java/com/juick/service/CrosspostService.java +++ b/juick-server/src/main/java/com/juick/service/CrosspostService.java @@ -12,13 +12,21 @@ public interface CrosspostService { Optional<Pair<String, String>> getTwitterTokens(int uid); + boolean deleteTwitterToken(Integer uid); + Optional<String> getFacebookToken(int uid); ApplicationStatus getFbCrossPostStatus(int uid); + boolean enableFBCrosspost(Integer uid); + + void disableFBCrosspost(Integer uid); + String getTwitterName(int uid); String getTelegramName(int uid); Optional<Pair<String, String>> getVkTokens(int uid); + + void deleteVKUser(Integer uid); } diff --git a/juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java b/juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java index ed1cd6762..0f043292e 100644 --- a/juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java @@ -14,7 +14,6 @@ import java.util.Optional; * Created by aalexeev on 11/13/16. */ @Repository -@Transactional(readOnly = true) public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostService { @Inject @@ -22,6 +21,7 @@ public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostSe super(jdbcTemplate, null); } + @Transactional(readOnly = true) @Override public Optional<Pair<String, String>> getTwitterTokens(final int uid) { List<Optional<Pair<String, String>>> list = getJdbcTemplate().query( @@ -33,6 +33,14 @@ public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostSe Optional.empty() : list.get(0); } + @Transactional + @Override + public boolean deleteTwitterToken(Integer uid) { + return getJdbcTemplate().update("DELETE FROM twitter WHERE user_id=?", uid) > 0 + && getJdbcTemplate().update("DELETE FROM subscr_users WHERE user_id=? AND suser_id=1741", uid) > 0; + } + + @Transactional(readOnly = true) @Override public Optional<String> getFacebookToken(final int uid) { List<String> list = getJdbcTemplate().queryForList( @@ -43,6 +51,7 @@ public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostSe Optional.empty() : Optional.of(list.get(0)); } + @Transactional(readOnly = true) @Override public ApplicationStatus getFbCrossPostStatus(final int uid) { List<ApplicationStatus> list = getJdbcTemplate().query( @@ -61,6 +70,24 @@ public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostSe new ApplicationStatus() : list.get(0); } + @Transactional + @Override + public boolean enableFBCrosspost(Integer uid) { + return getJdbcTemplate().update("UPDATE facebook SET crosspost=1 WHERE user_id=?", uid) > 0 + && getJdbcTemplate().update( + "INSERT INTO subscr_users(user_id,suser_id,jid,active) VALUES (?,5863,'juick@facebook.juick.com',1)", + uid) > 0; + } + + @Transactional + @Override + public void disableFBCrosspost(Integer uid) { + getJdbcTemplate().update("UPDATE facebook SET crosspost=0 WHERE user_id=?", uid); + // TODO: stop using magic numbers for system users + getJdbcTemplate().update("DELETE FROM subscr_users WHERE user_id=? AND suser_id=5863", uid); + } + + @Transactional(readOnly = true) @Override public String getTwitterName(final int uid) { List<String> list = getJdbcTemplate().queryForList( @@ -72,6 +99,7 @@ public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostSe "" : list.get(0); } + @Transactional(readOnly = true) @Override public String getTelegramName(final int uid) { List<String> list = getJdbcTemplate().queryForList( @@ -83,6 +111,7 @@ public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostSe "" : list.get(0); } + @Transactional(readOnly = true) @Override public Optional<Pair<String, String>> getVkTokens(final int uid) { List<Optional<Pair<String, String>>> list = getJdbcTemplate().query( @@ -93,4 +122,10 @@ public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostSe return list.isEmpty() ? Optional.empty() : list.get(0); } + + @Transactional + @Override + public void deleteVKUser(Integer uid) { + getJdbcTemplate().update("DELETE FROM vk WHERE user_id=?", uid); + } } diff --git a/juick-server/src/main/java/com/juick/service/EmailService.java b/juick-server/src/main/java/com/juick/service/EmailService.java index f62f4b32a..67925ec14 100644 --- a/juick-server/src/main/java/com/juick/service/EmailService.java +++ b/juick-server/src/main/java/com/juick/service/EmailService.java @@ -5,4 +5,7 @@ package com.juick.service; */ public interface EmailService { boolean verifyAddressByCode(Integer userId, String code); + boolean addVerificationCode(Integer userId, String account, String code); + boolean deleteEmail(Integer userId, String account); + boolean setSubscriptionHour(Integer userId, String account, String hour); } diff --git a/juick-server/src/main/java/com/juick/service/EmailServiceImpl.java b/juick-server/src/main/java/com/juick/service/EmailServiceImpl.java index bdd786091..b0bf9e20b 100644 --- a/juick-server/src/main/java/com/juick/service/EmailServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/EmailServiceImpl.java @@ -1,5 +1,6 @@ package com.juick.service; +import org.apache.commons.lang3.StringUtils; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -30,4 +31,22 @@ public class EmailServiceImpl extends BaseJdbcService implements EmailService { } return true; } + + @Override + public boolean addVerificationCode(Integer userId, String account, String code) { + return getJdbcTemplate().update("INSERT INTO auth(user_id,protocol,account,authcode) VALUES (?,'email',?,?)", + userId, account, code) > 0; + } + + @Override + public boolean deleteEmail(Integer userId, String account) { + return getJdbcTemplate().update("DELETE FROM emails WHERE user_id=? AND email=?", userId, account) > 0; + } + + @Override + public boolean setSubscriptionHour(Integer userId, String account, String hour) { + getJdbcTemplate().update("UPDATE emails SET subscr_hour=NULL WHERE user_id=?", userId); + return StringUtils.isNotEmpty(account) && getJdbcTemplate().update( + "UPDATE emails SET subscr_hour=? WHERE user_id=? AND email=?", hour, userId, account) > 0; + } } diff --git a/juick-server/src/main/java/com/juick/service/TelegramService.java b/juick-server/src/main/java/com/juick/service/TelegramService.java index 259ab367b..b23e34050 100644 --- a/juick-server/src/main/java/com/juick/service/TelegramService.java +++ b/juick-server/src/main/java/com/juick/service/TelegramService.java @@ -14,6 +14,8 @@ public interface TelegramService { boolean createTelegramUser(long tgID, String tgName); + boolean deleteTelegramUser(Integer uid); + List<Long> getSubscribers(int uid); List<Long> getSubscribersToComments(int mid, int ignore_uid); diff --git a/juick-server/src/main/java/com/juick/service/TelegramServiceImpl.java b/juick-server/src/main/java/com/juick/service/TelegramServiceImpl.java index 89954944c..a698e2e85 100644 --- a/juick-server/src/main/java/com/juick/service/TelegramServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/TelegramServiceImpl.java @@ -49,6 +49,12 @@ public class TelegramServiceImpl extends BaseJdbcService implements TelegramServ tgID, tgName, UUID.randomUUID().toString()) > 0; } + @Transactional + @Override + public boolean deleteTelegramUser(Integer uid) { + return getJdbcTemplate().update("DELETE FROM telegram WHERE user_id=?", uid) > 0; + } + @Transactional(readOnly = true) @Override public List<Long> getSubscribers(final int uid) { |