Merge remote-tracking branch 'origin/master'

This commit is contained in:
insanity 2017-08-24 18:04:43 +09:00
commit 67057ceed6

View File

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