diff --git a/src/main/java/com/loafle/overflow/central/module/email/service/EmailAuthService.java b/src/main/java/com/loafle/overflow/central/module/email/service/EmailAuthService.java index 06d33f5..25c2181 100644 --- a/src/main/java/com/loafle/overflow/central/module/email/service/EmailAuthService.java +++ b/src/main/java/com/loafle/overflow/central/module/email/service/EmailAuthService.java @@ -2,6 +2,7 @@ package com.loafle.overflow.central.module.email.service; import com.loafle.overflow.central.commons.utils.EmailSender; +import com.loafle.overflow.central.commons.utils.GenerateKey; import com.loafle.overflow.central.module.domain.dao.DomainDAO; import com.loafle.overflow.central.module.domain.dao.DomainMemberDAO; import com.loafle.overflow.central.module.email.dao.EmailAuthDAO; @@ -53,12 +54,14 @@ public class EmailAuthService { return this.emailAuthDAO.findOne(id); } - public EmailAuth readBySignupAuthKey(String token) throws OverflowException, UnsupportedEncodingException { - System.out.println("authKey = [" + token + "]"); - String deStr = URLDecoder.decode(token, "UTF-8"); - System.out.println("deStr = [" + deStr + "]"); + public EmailAuth readBySignupAuthKey(String token) throws OverflowException { +// System.out.println("authKey = [" + token + "]"); +// String deStr = URLDecoder.decode(token, "UTF-8"); +// System.out.println("deStr = [" + deStr + "]"); +// +// EmailAuth auth = this.emailAuthDAO.findByEmailAuthKey(deStr); - EmailAuth auth = this.emailAuthDAO.findByEmailAuthKey(deStr); + EmailAuth auth = this.readByToken(token); if (auth != null) { @@ -86,9 +89,9 @@ public class EmailAuthService { return auth; } - public EmailAuth readByPwAuthKey(String token) throws OverflowException, UnsupportedEncodingException { - String deStr = URLDecoder.decode(token, "UTF-8"); - EmailAuth auth = this.emailAuthDAO.findByEmailAuthKey(deStr); + public EmailAuth readByPwAuthKey(String token) throws OverflowException { + + EmailAuth auth = this.readByToken(token); if (auth != null && (auth.getMember() != null && auth.getMember().getId() > 0)) { boolean res = this.isValidateTime(auth); @@ -105,6 +108,19 @@ public class EmailAuthService { } + public EmailAuth readByToken(String token) { + String encode = ""; + + try { + encode = URLEncoder.encode(token, "UTF-8"); + }catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + EmailAuth auth = this.emailAuthDAO.findByEmailAuthKey(encode); + + return auth; + } // dZQgXM1o/Cx48X8DM+6ec/oPfqA2l/LdWtijOZ2EnWk= public List readByMember(long memberId) { @@ -142,7 +158,8 @@ public class EmailAuthService { } private EmailAuth sendEMail(Member member, int status) throws OverflowException { - String enMail = emailSender.encrypt(member.getEmail()); + String key = GenerateKey.getKey(); +// String enMail = emailSender.encrypt(key); String mailSubject = null; String entry = null; @@ -150,14 +167,14 @@ public class EmailAuthService { EmailAuth auth = new EmailAuth(); auth.setMember(member); - auth.setEmailAuthKey(enMail); + auth.setEmailAuthKey(key); auth.setEmailStatus(new MetaEmailStatus(status)); // System.out.println("encode = [" + encode + "]"); String encode = ""; try { - encode = URLEncoder.encode(enMail, "UTF-8"); + encode = URLEncoder.encode(key, "UTF-8"); }catch (UnsupportedEncodingException e) { e.printStackTrace(); } 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 d570fa3..ee76ac9 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 @@ -10,6 +10,7 @@ import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.model.apikey.ApiKey; import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.domain.DomainMember; +import com.loafle.overflow.model.email.EmailAuth; import com.loafle.overflow.model.member.Member; import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.model.meta.MetaMemberStatus; @@ -135,23 +136,29 @@ public class CentralMemberService implements MemberService { return member; } - public Member resetPassword(String signinID, String newPw) throws OverflowException { + public Member resetPassword(String token, String pw) throws OverflowException { String deStr = null; try { - deStr = URLDecoder.decode(signinID, "UTF-8"); + deStr = URLDecoder.decode(token, "UTF-8"); }catch (Exception e) { } - String deEmail = this.emailSender.decrypt(deStr); - Member member = this.memberDAO.findByEmail(deEmail); +// String deEmail = this.emailSender.decrypt(deStr); + EmailAuth auth = this.emailAuthService.readByToken(deStr); + + if (auth == null) { + throw new OverflowException("Not Exist Token", null); + } + + Member member = this.memberDAO.findByEmail(auth.getMember().getEmail()); if (null == member) { throw new OverflowException("", null); } - boolean checkPass = this.isPasswordStrong(newPw); + boolean checkPass = this.isPasswordStrong(pw); if (!checkPass) { throw new OverflowException("PasswordNotStrongException()", new Throwable()); @@ -159,7 +166,7 @@ public class CentralMemberService implements MemberService { // "special character, lowercase letter, and number, " + // "and must be at least 6 characters long."); } - member.setPw(passwordEncoder.encode(newPw)); + member.setPw(passwordEncoder.encode(pw)); return this.modify(member); }