From da34f5932e1c7a8b129815a080576b4751bee57b Mon Sep 17 00:00:00 2001 From: geek Date: Mon, 3 Jul 2017 15:03:00 +0900 Subject: [PATCH] EmailAuth Service method added --- .../email/service/EmailAuthService.java | 56 +++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java index 69ba19f..1f1c33b 100644 --- a/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java +++ b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java @@ -1,11 +1,16 @@ package com.loafle.overflow.module.email.service; +import com.loafle.overflow.module.email.dao.EmailAuthDAO; +import com.loafle.overflow.module.email.model.EmailAuth; +import com.loafle.overflow.module.member.model.Member; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mail.MailException; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Service; +import java.util.List; + /** * Created by geek on 17. 6. 28. */ @@ -15,19 +20,50 @@ public class EmailAuthService { @Autowired private JavaMailSender mailSender; + @Autowired + private EmailAuthDAO emailAuthDAO; - public void sendEmail(String to, String sub, String message) { - + public EmailAuth sendEmailByMemberId(long memberId, String memberEmail) { try { - SimpleMailMessage message1 = new SimpleMailMessage(); - message1.setTo(to); - message1.setSubject(sub); - message1.setText(message); - message1.setFrom("geek@loafle.com"); - - mailSender.send(message1); - } catch (MailException e) { + this.sendEmail(memberEmail, "Test Spring Mail", "Confirm Email"); + }catch (MailException e) { e.printStackTrace(); } + + EmailAuth auth = new EmailAuth(); + auth.setMember(new Member(memberId)); + // Todo AuthKey Generation + auth.setEmailAuthKey("djdjdjdjeiejdikdjki"); + + this.emailAuthDAO.save(auth); + + return auth; + } + + public EmailAuth read(long id) { + return this.emailAuthDAO.findOne(id); + } + + public EmailAuth readByAuthKey(String authKey) { + return this.emailAuthDAO.findByEmailAuthKey(authKey); + } + + public List readByMember(long memberId) { + return this.emailAuthDAO.findByMember(new Member(memberId)); + } + + public EmailAuth modify(EmailAuth emailAuth) { + return this.emailAuthDAO.save(emailAuth); + } + + public void sendEmail(String to, String sub, String message) throws MailException { + + SimpleMailMessage message1 = new SimpleMailMessage(); + message1.setTo(to); + message1.setSubject(sub); + message1.setText(message); + message1.setFrom("geek@loafle.com"); + + mailSender.send(message1); } }