EmailAuth Service method added
This commit is contained in:
parent
e3d3a94ab7
commit
da34f5932e
|
@ -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,19 +20,50 @@ 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 {
|
||||||
SimpleMailMessage message1 = new SimpleMailMessage();
|
this.sendEmail(memberEmail, "Test Spring Mail", "Confirm Email");
|
||||||
message1.setTo(to);
|
}catch (MailException e) {
|
||||||
message1.setSubject(sub);
|
|
||||||
message1.setText(message);
|
|
||||||
message1.setFrom("geek@loafle.com");
|
|
||||||
|
|
||||||
mailSender.send(message1);
|
|
||||||
} catch (MailException e) {
|
|
||||||
e.printStackTrace();
|
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();
|
||||||
|
message1.setTo(to);
|
||||||
|
message1.setSubject(sub);
|
||||||
|
message1.setText(message);
|
||||||
|
message1.setFrom("geek@loafle.com");
|
||||||
|
|
||||||
|
mailSender.send(message1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user