This commit is contained in:
geek 2018-05-06 18:39:28 +09:00
parent cfa920cf37
commit 856ec27cda
2 changed files with 41 additions and 17 deletions

View File

@ -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.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.DomainDAO;
import com.loafle.overflow.central.module.domain.dao.DomainMemberDAO; import com.loafle.overflow.central.module.domain.dao.DomainMemberDAO;
import com.loafle.overflow.central.module.email.dao.EmailAuthDAO; import com.loafle.overflow.central.module.email.dao.EmailAuthDAO;
@ -53,12 +54,14 @@ public class EmailAuthService {
return this.emailAuthDAO.findOne(id); return this.emailAuthDAO.findOne(id);
} }
public EmailAuth readBySignupAuthKey(String token) throws OverflowException, UnsupportedEncodingException { public EmailAuth readBySignupAuthKey(String token) throws OverflowException {
System.out.println("authKey = [" + token + "]"); // System.out.println("authKey = [" + token + "]");
String deStr = URLDecoder.decode(token, "UTF-8"); // String deStr = URLDecoder.decode(token, "UTF-8");
System.out.println("deStr = [" + deStr + "]"); // 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) { if (auth != null) {
@ -86,9 +89,9 @@ public class EmailAuthService {
return auth; return auth;
} }
public EmailAuth readByPwAuthKey(String token) throws OverflowException, UnsupportedEncodingException { public EmailAuth readByPwAuthKey(String token) throws OverflowException {
String deStr = URLDecoder.decode(token, "UTF-8");
EmailAuth auth = this.emailAuthDAO.findByEmailAuthKey(deStr); EmailAuth auth = this.readByToken(token);
if (auth != null && (auth.getMember() != null && auth.getMember().getId() > 0)) { if (auth != null && (auth.getMember() != null && auth.getMember().getId() > 0)) {
boolean res = this.isValidateTime(auth); 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= // dZQgXM1o/Cx48X8DM+6ec/oPfqA2l/LdWtijOZ2EnWk=
public List<EmailAuth> readByMember(long memberId) { public List<EmailAuth> readByMember(long memberId) {
@ -142,7 +158,8 @@ public class EmailAuthService {
} }
private EmailAuth sendEMail(Member member, int status) throws OverflowException { 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 mailSubject = null;
String entry = null; String entry = null;
@ -150,14 +167,14 @@ public class EmailAuthService {
EmailAuth auth = new EmailAuth(); EmailAuth auth = new EmailAuth();
auth.setMember(member); auth.setMember(member);
auth.setEmailAuthKey(enMail); auth.setEmailAuthKey(key);
auth.setEmailStatus(new MetaEmailStatus(status)); auth.setEmailStatus(new MetaEmailStatus(status));
// System.out.println("encode = [" + encode + "]"); // System.out.println("encode = [" + encode + "]");
String encode = ""; String encode = "";
try { try {
encode = URLEncoder.encode(enMail, "UTF-8"); encode = URLEncoder.encode(key, "UTF-8");
}catch (UnsupportedEncodingException e) { }catch (UnsupportedEncodingException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -10,6 +10,7 @@ import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.apikey.ApiKey; import com.loafle.overflow.model.apikey.ApiKey;
import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.domain.Domain;
import com.loafle.overflow.model.domain.DomainMember; 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.member.Member;
import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.model.meta.MetaMemberStatus; import com.loafle.overflow.model.meta.MetaMemberStatus;
@ -135,23 +136,29 @@ public class CentralMemberService implements MemberService {
return member; return member;
} }
public Member resetPassword(String signinID, String newPw) throws OverflowException { public Member resetPassword(String token, String pw) throws OverflowException {
String deStr = null; String deStr = null;
try { try {
deStr = URLDecoder.decode(signinID, "UTF-8"); deStr = URLDecoder.decode(token, "UTF-8");
}catch (Exception e) { }catch (Exception e) {
} }
String deEmail = this.emailSender.decrypt(deStr); // String deEmail = this.emailSender.decrypt(deStr);
Member member = this.memberDAO.findByEmail(deEmail); 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) { if (null == member) {
throw new OverflowException("", null); throw new OverflowException("", null);
} }
boolean checkPass = this.isPasswordStrong(newPw); boolean checkPass = this.isPasswordStrong(pw);
if (!checkPass) { if (!checkPass) {
throw new OverflowException("PasswordNotStrongException()", new Throwable()); throw new OverflowException("PasswordNotStrongException()", new Throwable());
@ -159,7 +166,7 @@ public class CentralMemberService implements MemberService {
// "special character, lowercase letter, and number, " + // "special character, lowercase letter, and number, " +
// "and must be at least 6 characters long."); // "and must be at least 6 characters long.");
} }
member.setPw(passwordEncoder.encode(newPw)); member.setPw(passwordEncoder.encode(pw));
return this.modify(member); return this.modify(member);
} }