aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/service
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-12-09 16:14:27 +0300
committerGravatar Vitaly Takmazov2016-12-09 16:14:27 +0300
commit559ae343aa72db04e12b94acfa0bec30ed9a11f1 (patch)
tree5832b97c6a6a4b565de15a474bae86059763d6bb /juick-server/src/main/java/com/juick/service
parent22d30c3b50fe0ea4c18c45a4450fb1a8b1f1b1b8 (diff)
juick-spring-www: merge some work from develop branch, port some templates to Thymeleaf
Diffstat (limited to 'juick-server/src/main/java/com/juick/service')
-rw-r--r--juick-server/src/main/java/com/juick/service/EmailService.java8
-rw-r--r--juick-server/src/main/java/com/juick/service/EmailServiceImpl.java33
2 files changed, 41 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/service/EmailService.java b/juick-server/src/main/java/com/juick/service/EmailService.java
new file mode 100644
index 00000000..f62f4b32
--- /dev/null
+++ b/juick-server/src/main/java/com/juick/service/EmailService.java
@@ -0,0 +1,8 @@
+package com.juick.service;
+
+/**
+ * Created by vitalyster on 09.12.2016.
+ */
+public interface EmailService {
+ boolean verifyAddressByCode(Integer userId, String code);
+}
diff --git a/juick-server/src/main/java/com/juick/service/EmailServiceImpl.java b/juick-server/src/main/java/com/juick/service/EmailServiceImpl.java
new file mode 100644
index 00000000..bdd78609
--- /dev/null
+++ b/juick-server/src/main/java/com/juick/service/EmailServiceImpl.java
@@ -0,0 +1,33 @@
+package com.juick.service;
+
+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;
+ }
+}