diff --git a/src/main/java/com/loafle/overflow/central/module/email/dao/EmailAuthDAO.java b/src/main/java/com/loafle/overflow/central/module/email/dao/EmailAuthDAO.java index 3cd016b..3096566 100644 --- a/src/main/java/com/loafle/overflow/central/module/email/dao/EmailAuthDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/email/dao/EmailAuthDAO.java @@ -13,6 +13,8 @@ import java.util.List; public interface EmailAuthDAO extends JpaRepository { EmailAuth findByEmailAuthKey(String emailAuthKey); - List findByMemberId(Long memberId); +// List findByMemberId(Long memberId); + + List findByMemberIdOrderByCreateDateDesc(Long memberId); } diff --git a/src/main/java/com/loafle/overflow/central/module/email/service/CentralEmailAuthService.java b/src/main/java/com/loafle/overflow/central/module/email/service/CentralEmailAuthService.java index c71cb88..22eb276 100644 --- a/src/main/java/com/loafle/overflow/central/module/email/service/CentralEmailAuthService.java +++ b/src/main/java/com/loafle/overflow/central/module/email/service/CentralEmailAuthService.java @@ -124,7 +124,7 @@ public class CentralEmailAuthService implements EmailAuthService { // dZQgXM1o/Cx48X8DM+6ec/oPfqA2l/LdWtijOZ2EnWk= public List readByMember(Long memberId) { - return this.emailAuthDAO.findByMemberId(memberId); + return this.emailAuthDAO.findByMemberIdOrderByCreateDateDesc(memberId); } public EmailAuth modify(EmailAuth emailAuth) { @@ -213,6 +213,7 @@ public class CentralEmailAuthService implements EmailAuthService { return auth; } + } // EmailAuth auth = new EmailAuth(); @@ -243,4 +244,4 @@ public class CentralEmailAuthService implements EmailAuthService { // // this.emailAuthDAO.save(auth); // -// return auth; \ No newline at end of file +// return auth; diff --git a/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberService.java b/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberService.java index cca6259..deb32a1 100644 --- a/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberService.java +++ b/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberService.java @@ -21,6 +21,8 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import java.net.URLDecoder; +import java.util.Calendar; +import java.util.Date; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -133,15 +135,31 @@ public class CentralMemberService implements MemberService { } public Member reSendEmail(String email) throws OverflowException { -// Member member = this.memberDAO.findByEmail(email); -// -// if (member != null && member.getMetaMemberStatus().getId().equals(MetaMemberStatus.Enum.NORMAL.getValue())) { -// throw new OverflowException("This email has already been verified.", new Throwable()); -// } -// -// List auths = this.emailAuthService.readByMember(member.getId()); -// - return null; + Member member = this.memberDAO.findByEmail(email); + + if (member != null && member.getMetaMemberStatus().getId().equals(MetaMemberStatus.Enum.NORMAL.getValue())) { + throw new OverflowException("This email has already been verified.", new Throwable()); + } + + List auths = this.emailAuthService.readByMember(member.getId()); + + if (auths == null || auths.size() == 0) { + return this.emailAuthService.sendEmailByMember(member).getMember(); + } + + Calendar cal = Calendar.getInstance(); + + cal.setTime(auths.get(0).getCreateDate()); + cal.add(Calendar.HOUR, 12); + Date futureDate = cal.getTime(); + + Date nowDate = new Date(); + + if (!nowDate.before(futureDate)) { + throw new OverflowException("The email authentication token is valid.", new Throwable()); + } + + return this.emailAuthService.sendEmailByMember(member).getMember(); } public Member resetPassword(String token, String password) throws OverflowException { diff --git a/src/test/java/com/loafle/overflow/central/module/email/service/EmailAuthServiceTest.java b/src/test/java/com/loafle/overflow/central/module/email/service/EmailAuthServiceTest.java index a1f7856..f3a0186 100644 --- a/src/test/java/com/loafle/overflow/central/module/email/service/EmailAuthServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/email/service/EmailAuthServiceTest.java @@ -5,6 +5,7 @@ import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.model.email.EmailAuth; import com.loafle.overflow.model.member.Member; import com.loafle.overflow.service.central.email.EmailAuthService; +import com.loafle.overflow.service.central.member.MemberService; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -14,6 +15,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Calendar; import java.util.Date; +import java.util.List; /** * Created by geek on 17. 6. 28. @@ -27,6 +29,8 @@ public class EmailAuthServiceTest { @Autowired EmailAuthService emailAuthService; + @Autowired + MemberService memberService; @Test @Ignore public void TestMailSend() throws Exception { @@ -57,4 +61,18 @@ public class EmailAuthServiceTest { // System.out.println("dd = " + dd); } -} \ No newline at end of file + @Test + public void TestMemberIdOrderByDesc() throws Exception { + + Member member = this.memberService.read((long)2); + + for (int i = 0; i < 5; i++) { + this.emailAuthService.sendEmailByMember(member); + } + + List auths = this.emailAuthService.readByMember((long)2); + +// Assert.assertArrayEquals(auths, (short)5); + System.out.println(auths.size()); + } +} diff --git a/src/test/resources/mail.properties b/src/test/resources/mail.properties index 99f696d..0a01f91 100644 --- a/src/test/resources/mail.properties +++ b/src/test/resources/mail.properties @@ -2,7 +2,7 @@ mail.host=smtp.worksmobile.com mail.port=465 mail.username=geek@loafle.com -mail.password=@loafle@5795 +mail.password=@cosmos@5795 mail.protocol=smtps mail.properties.mail.smtp.auth=true