diff options
author | Vitaly Takmazov | 2017-06-29 14:03:04 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-06-29 14:03:04 +0300 |
commit | 02723131139806c761539a42a5fa80b68ecadee8 (patch) | |
tree | ca66f22993908758385f708eb2da4e4aeb20510a /juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java | |
parent | 4cc4b08f4377b7db697abdb533c625da608eb3d3 (diff) |
project structure: split server into jdbc + web
Diffstat (limited to 'juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java')
-rw-r--r-- | juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java new file mode 100644 index 00000000..b0bf9e20 --- /dev/null +++ b/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java @@ -0,0 +1,52 @@ +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; +import org.springframework.transaction.annotation.Transactional; + +import javax.inject.Inject; + +/** + * Created by vitalyster on 09.12.2016. + */ +@Repository +@Transactional +public class EmailServiceImpl extends BaseJdbcService implements EmailService { + @Inject + public EmailServiceImpl(JdbcTemplate jdbcTemplate) { + super(jdbcTemplate, null); + } + + @Override + public boolean verifyAddressByCode(Integer userId, String code) { + try { + String address = getJdbcTemplate().queryForObject("SELECT account FROM auth WHERE user_id=? AND protocol='email' AND authcode=?", + String.class, userId, code); + getJdbcTemplate().update("INSERT INTO emails(user_id,email) VALUES (?,?)", userId, address); + getJdbcTemplate().update("DELETE FROM auth WHERE user_id=? AND authcode=?", userId, code); + } catch (EmptyResultDataAccessException e) { + return false; + } + 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; + } +} |