EmailAuth Service method added

This commit is contained in:
geek 2017-07-03 15:03:00 +09:00
parent e3d3a94ab7
commit da34f5932e

View File

@ -1,11 +1,16 @@
package com.loafle.overflow.module.email.service; 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.beans.factory.annotation.Autowired;
import org.springframework.mail.MailException; import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* Created by geek on 17. 6. 28. * Created by geek on 17. 6. 28.
*/ */
@ -15,10 +20,44 @@ public class EmailAuthService {
@Autowired @Autowired
private JavaMailSender mailSender; private JavaMailSender mailSender;
@Autowired
private EmailAuthDAO emailAuthDAO;
public void sendEmail(String to, String sub, String message) { public EmailAuth sendEmailByMemberId(long memberId, String memberEmail) {
try { try {
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<EmailAuth> 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(); SimpleMailMessage message1 = new SimpleMailMessage();
message1.setTo(to); message1.setTo(to);
message1.setSubject(sub); message1.setSubject(sub);
@ -26,8 +65,5 @@ public class EmailAuthService {
message1.setFrom("geek@loafle.com"); message1.setFrom("geek@loafle.com");
mailSender.send(message1); mailSender.send(message1);
} catch (MailException e) {
e.printStackTrace();
}
} }
} }