diff --git a/src/main/java/com/loafle/overflow/module/member/service/MemberService.java b/src/main/java/com/loafle/overflow/module/member/service/MemberService.java index 8422891..7190e7d 100644 --- a/src/main/java/com/loafle/overflow/module/member/service/MemberService.java +++ b/src/main/java/com/loafle/overflow/module/member/service/MemberService.java @@ -6,7 +6,9 @@ import com.loafle.overflow.module.member.exception.*; import com.loafle.overflow.module.member.model.Member; import com.loafle.overflow.module.meta.model.MetaMemberStatus; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; /** @@ -21,6 +23,8 @@ public class MemberService { @Autowired private EmailAuthService emailAuthService; + private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + public Member signin(String signinId, String signinPw) throws SignInIdNotExistException, EmailNotConfirmedException, SignInPwNotMatchException { Member m = this.memberDAO.findByEmail(signinId); @@ -32,7 +36,6 @@ public class MemberService { throw new EmailNotConfirmedException(); } - BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); Boolean match = passwordEncoder.matches(signinPw, m.getPw()); if(!match) { throw new SignInPwNotMatchException(); @@ -49,7 +52,6 @@ public class MemberService { throw new JoinedEmailException(); } - BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); member.setPw(passwordEncoder.encode(pw)); if (member.getStatus() == null) { @@ -71,7 +73,6 @@ public class MemberService { Member preMember = this.memberDAO.findByEmail(member.getEmail()); - BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); member.setPw(passwordEncoder.encode(pw)); Boolean match = passwordEncoder.matches(member.getPw(), preMember.getPw()); if(match) { @@ -81,6 +82,33 @@ public class MemberService { return this.memberDAO.save(member); } + public Member confirmPw(String signinId, String signinPw) { + + Member preMember = this.memberDAO.findByEmail(signinId); + + String encodePw = passwordEncoder.encode(signinPw); + Boolean match = passwordEncoder.matches(encodePw, preMember.getPw()); + + if (!match) { + throw new SignInPwNotMatchException(); + } + + return preMember; + } + + public Member forgotPassword(String signinId, String newPw) { + Member preMember = this.memberDAO.findByEmail(signinId); + + if (null == preMember) { + throw new SignInIdNotExistException(); + } + + preMember.setPw(this.passwordEncoder.encode(newPw)); + this.memberDAO.save(preMember); + + return preMember; + } + public Member read(long memberId) { if (memberId <= 0) { // Todo MemberId null Exception