🤍📝 비밀번호 변경
🔎 MyPageController
@PostMapping("/changePw")
public String changePw( String currentPw, String newPw
,@SessionAttribute("loginMember") Member loginMember
,RedirectAttributes ra) {
int memberNo = loginMember.getMemberNo();
int result = service.changePw(currentPw, newPw, memberNo);
String path = "redirect:";
String message = null;
if( result > 0 ) {
message = "비밀번호가 변경 되었습니다.";
path += "info";
}else {
message = "현재 비밀번호가 일치하지 않습니다.";
path += "changePw";
}
ra.addFlashAttribute("message", message);
return path;
}
🔎 MyPageServiceImpl
@Transactional(rollbackFor = {Exception.class} )
@Override
public int changePw(String currentPw, String newPw, int memberNo) {
String encPW = dao.selectEncPw(memberNo);
if(bcrypt.matches(currentPw, encPW)) {
return dao.changePw(bcrypt.encode(newPw), memberNo);
}
return 0;
}
🔎 MyPageDAO
public int changePw(String newPw, int memberNo) {
Member member = new Member();
member.setMemberNo(memberNo);
member.setMemberPw(newPw);
return sqlSession.update("myPageMapper.changePw", member);
}
}
🔎 myPage-mapper.xml
<!-- 비밀번호 변경 -->
<!-- Member : 사용자 지정 별칭 (mybatis-config.xml) -->
<update id="changePw" parameterType="Member">
UPDATE MEMBER SET
MEMBER_PW = #{memberPw}
WHERE MEMBER_NO = #{memberNo}
</update>
🔎 myPage.js
const currentPw = document.getElementById("currentPw");
const newPw = document.getElementById("newPw");
const newPwConfirm = document.getElementById("newPwConfirm");
const changePwFrm = document.getElementById("changePwFrm");
if(changePwFrm!=null){
changePwFrm.addEventListener("submit", e=>{
if(currentPw.value.trim().length == 0){
alert("비밀번호를 작성해주세요");
e.preventDefault();
currentPw.focus();
currentPw.value="";
return;
}
const regEX = /^[A-Za-z\d\-\_\#\@\!]{6,20}$/;
if(!regEX.test(newPw.value)){
alert("비밀번호가 유효하지 않습니다.");
e.preventDefault();
newPw.focus();
return;
}
if(newPw.value != newPwConfirm.value){
alert("비밀번호가 일치하지 않습니다");
e.preventDefault();
newPwConfirm.focus();
return;
}
})
}
🤍📝 회원 탈퇴
🔎 MyPageController
@PostMapping("/secession")
public String secession(String memberPw
,@SessionAttribute("loginMember") Member loginMember
,RedirectAttributes ra
,SessionStatus status
,HttpServletResponse resp) {
int memberNo = loginMember.getMemberNo();
int result = service.secession(memberPw, memberNo);
String path = "redirect:";
String message = null;
if( result > 0 ) {
message = "탈퇴 되었습니다.";
path += "/";
status.setComplete();
Cookie cookie = new Cookie("saveId", "");
cookie.setMaxAge(0);
cookie.setPath("/");
resp.addCookie(cookie);
}else {
message = "현재 비밀번호가 일치하지 않습니다.";
path += "secession";
}
ra.addFlashAttribute("message", message);
return path;
}
🔎 MyPageServiceImpl
@Transactional(rollbackFor = {Exception.class} )
@Override
public int secession(String memberPw, int memberNo) {
String encPW = dao.selectEncPw(memberNo);
if(bcrypt.matches(memberPw, encPW)) {
return dao.secession(memberNo);
}
return 0;
}
🔎 MyPageDAO
public int secession(int memberNo) {
return sqlSession.update("myPageMapper.secession", memberNo);
}
🔎 myPage-mapper.xml
<!-- 회원 탈퇴 -->
<update id="secession" parameterType="_int">
UPDATE MEMBER SET MEMBER_DEL_FL ='Y'
WHERE MEMBER_NO = #{memberNo}
</update>