From 5146e43ab81143a4fab59b43d4a71fd3de0f6ac9 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 12 Dec 2016 14:28:34 +0300 Subject: juick-spring-www: settings templates and other WIP --- .../java/com/juick/service/CrosspostService.java | 8 +++++ .../com/juick/service/CrosspostServiceImpl.java | 37 +++++++++++++++++++++- .../main/java/com/juick/service/EmailService.java | 3 ++ .../java/com/juick/service/EmailServiceImpl.java | 19 +++++++++++ .../java/com/juick/service/TelegramService.java | 2 ++ .../com/juick/service/TelegramServiceImpl.java | 6 ++++ 6 files changed, 74 insertions(+), 1 deletion(-) (limited to 'juick-server/src/main') 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 88821b60..725ef297 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> getTwitterTokens(int uid); + boolean deleteTwitterToken(Integer uid); + Optional getFacebookToken(int uid); ApplicationStatus getFbCrossPostStatus(int uid); + boolean enableFBCrosspost(Integer uid); + + void disableFBCrosspost(Integer uid); + String getTwitterName(int uid); String getTelegramName(int uid); Optional> 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 ed1cd676..0f043292 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> getTwitterTokens(final int uid) { List>> 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 getFacebookToken(final int uid) { List 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 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 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 list = getJdbcTemplate().queryForList( @@ -83,6 +111,7 @@ public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostSe "" : list.get(0); } + @Transactional(readOnly = true) @Override public Optional> getVkTokens(final int uid) { List>> 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 f62f4b32..67925ec1 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 bdd78609..b0bf9e20 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 259ab367..b23e3405 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 getSubscribers(int uid); List 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 89954944..a698e2e8 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 getSubscribers(final int uid) { -- cgit v1.2.3