aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/service/EmailServiceImpl.java
blob: bdd786091565152eae0b549965d23ad1af6d96fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;
    }
}