email token duplication check
This commit is contained in:
parent
c045f4015e
commit
b009d2c886
|
@ -13,6 +13,8 @@ import java.util.List;
|
|||
public interface EmailAuthDAO extends JpaRepository<EmailAuth, Long> {
|
||||
EmailAuth findByEmailAuthKey(String emailAuthKey);
|
||||
|
||||
List<EmailAuth> findByMemberId(Long memberId);
|
||||
// List<EmailAuth> findByMemberId(Long memberId);
|
||||
|
||||
List<EmailAuth> findByMemberIdOrderByCreateDateDesc(Long memberId);
|
||||
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ public class CentralEmailAuthService implements EmailAuthService {
|
|||
// dZQgXM1o/Cx48X8DM+6ec/oPfqA2l/LdWtijOZ2EnWk=
|
||||
|
||||
public List<EmailAuth> 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();
|
||||
|
|
|
@ -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<EmailAuth> 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<EmailAuth> 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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
@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<EmailAuth> auths = this.emailAuthService.readByMember((long)2);
|
||||
|
||||
// Assert.assertArrayEquals(auths, (short)5);
|
||||
System.out.println(auths.size());
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user