🌼내 정보 조회(myPage-info.jsp)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>마이페이지</title>
<link rel="stylesheet" href="/resources/css/myPage/myPage-style.css">
</head>
<body>
<main>
<jsp:include page="/WEB-INF/views/common/header.jsp" />
<section class="myPage-content">
<jsp:include page="/WEB-INF/views/myPage/sideMenu.jsp" />
<section class="myPage-main">
<h1 class="myPage-title">내 정보</h1>
<span class="myPage-subject">원하는 회원 정보를 수정할 수 있습니다.</span>
<%-- 현재페이지 : http://localhost/myPage/info
제일 뒤에 info 지우고
action에 작성된 경로 추가
--%>
<form action="info" method="POST" name="myPageFrm" id ="updateInfo">
<div class="myPage-row">
<label>닉네임</label>
<input type="text" name="memberNickname" maxlength="10"
value="${loginMember.memberNickname}" id="memberNickname">
</div>
<div class="myPage-row">
<label>전화번호</label>
<input type="text" name="memberTel" maxlength="11"
value="${loginMember.memberTel}" id="memberTel">
</div>
<div class="myPage-row info-title">
<span>주소</span>
</div>
<%-- ${fn:split(loginMember.memberAddress, '^^^')[0]}
${fn:split(loginMember.memberAddress, '^^^')[1]}
${fn:split(loginMember.memberAddress, '^^^')[2]} --%>
<%--
${fn:split(문자열, 구분자)}
문자열을 구분자로 나누어 배열 형태로 반환
--%>
<c:set var="addr" value="${fn:split(loginMember.memberAddress,'^^^')}"/>
<div class="myPage-row info-address">
<input type="text" name="memberAddress" placeholder="우편번호" value="${addr[0]}" id="sample6_postcode">
<button type="button" onclick="sample6_execDaumPostcode()">검색</button>
</div>
<div class="myPage-row info-address">
<input type="text" name="memberAddress" placeholder="도로명/지번 주소" value="${addr[1]}" id="sample6_address">
</div>
<div class="myPage-row info-address">
<input type="text" name="memberAddress" placeholder="상세 주소" value="${addr[2]}" id="sample6_detailAddress">
</div>
<button class="myPage-submit">수정하기</button>
</form>
</section>
</section>
</main>
<jsp:include page="/WEB-INF/views/common/footer.jsp" />
<script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
<script>
function sample6_execDaumPostcode() {
new daum.Postcode({
oncomplete: function(data) {
var addr = '';
if (data.userSelectedType === 'R') {
addr = data.roadAddress;
} else {
addr = data.jibunAddress;
}
document.getElementById('sample6_postcode').value = data.zonecode;
document.getElementById("sample6_address").value = addr;
document.getElementById("sample6_detailAddress").focus();
}
}).open();
}
</script>
<script src="/resources/js/myPage/myPage.js"></script>
</body>
</html>
🌼비밀번호 변경(myPage-changePw.jsp)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Page</title>
<link rel="stylesheet" href="/resources/css/myPage/myPage-style.css">
</head>
<body>
<main>
<jsp:include page="/WEB-INF/views/common/header.jsp"/>
<section class="myPage-content">
<jsp:include page="/WEB-INF/views/myPage/sideMenu.jsp"/>
<section class="myPage-main">
<h1 class="myPage-title">비밀번호 변경</h1>
<span class="myPage-subject">현재 비밀번호가 일치하는 경우 새 비밀번호로 변경할 수 있습니다.</span>
<form action="changePw" method="POST" name="myPageFrm" id="changePwFrm">
<div class="myPage-row">
<label>현재 비밀번호</label>
<input type="password" name="currentPw" id="currentPw" maxlength="30" >
</div>
<div class="myPage-row">
<label>새 비밀번호</label>
<input type="password" name="newPw" id="newPw" maxlength="30">
</div>
<div class="myPage-row">
<label>새 비밀번호 확인</label>
<input type="password" name="newPwConfirm" id="newPwConfirm" maxlength="30">
</div>
<button class="myPage-submit">변경하기</button>
</form>
</section>
</section>
</main>
<jsp:include page="/WEB-INF/views/common/footer.jsp"/>
<script src="/resources/js/myPage/myPage.js"></script>
</body>
</html>
🌼회원탈퇴(myPage-secession.jsp)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Page</title>
<link rel="stylesheet" href="/resources/css/myPage/myPage-style.css">
</head>
<body>
<main>
<jsp:include page="/WEB-INF/views/common/header.jsp"/>
<section class="myPage-content">
<jsp:include page="/WEB-INF/views/myPage/sideMenu.jsp"/>
<section class="myPage-main">
<h1 class="myPage-title">회원 탈퇴</h1>
<span class="myPage-subject">현재 비밀번호가 일치하는 경우 탈퇴할 수 있습니다.</span>
<form action="secession" method="POST" name="myPageFrm" id="secessionFrm">
<div class="myPage-row">
<label>비밀번호</label>
<input type="password" name="memberPw" id="memberPw" maxlength="30">
</div>
<div class="myPage-row info-title">
<label>회원 탈퇴 약관</label>
</div>
<pre class="secession-terms">
제1조
이 약관은 샘플 약관입니다.
① 약관 내용 1
② 약관 내용 2
③ 약관 내용 3
④ 약관 내용 4
제2조
이 약관은 샘플 약관입니다.
① 약관 내용 1
② 약관 내용 2
③ 약관 내용 3
④ 약관 내용 4
</pre>
<div>
<input type="checkbox" name="agree" id="agree">
<label for="agree">위 약관에 동의합니다.</label>
</div>
<button class="myPage-submit">탈퇴</button>
</form>
</section>
</section>
</main>
<jsp:include page="/WEB-INF/views/common/footer.jsp"/>
<script src="/resources/js/myPage/myPage.js"></script>
</body>
</html>
🌼myPage.js
const memberNickname = document.getElementById("memberNickname");
const memberTel = document.getElementById("memberTel");
const updateInfo = document.getElementById("updateInfo");
if(updateInfo != null){
initNickname = memberNickname.value;
initTel = memberTel.value;
memberNickname.addEventListener("input", ()=>{
if(initNickname == memberNickname.value){
memberNickname.removeAttribute("style");
return;
}
const regEx = /^[가-힣\d\w]{2,10}$/;
if(regEx.test(memberNickname.value)){
memberNickname.style.color="green";
}else{
memberNickname.style.color="red";
}
});
memberTel.addEventListener("input", ()=>{
if(initTel == memberTel.value){
memberTel.removeAttribute("style");
return;
}
const regEx = /^0(1[01679]|2|[3-6][1-5]|70)\d{3,4}\d{4}$/;
if(regEx.test(memberTel.value)){
memberTel.style.color="green";
}else{
memberTel.style.color="red";
}
});
updateInfo.addEventListener("submit", e =>{
if(memberNickname.style.color=="red"){
alert("닉네임이 유효하지 않습니다.");
memberNickname.focus();
e.preventDefault();
return;
}
if(memberTel.style.color=="red"){
alert("전화번호가 유효하지 않습니다.");
memberTel.focus();
e.preventDefault();
return;
}
})
}
const changePwFrm = document.getElementById("changePwFrm");
const currentPw = document.getElementById("currentPw");
const newPw = document.getElementById("newPw");
const newPwConfirm = document.getElementById("newPwConfirm");
if(changePwFrm != null){
changePwFrm.addEventListener("submit", e=>{
if(currentPw.value.trim() == ""){
alert("현재비밀번호를 입력해주세요");
e.preventDefault();
currentPw.focus();
currentPw.value="";
return;
}
const regEx =/^[A-Za-z0-9\!\@\#\-\_]{6,20}$/;
if(!regEx.test(newPw.value)){
alert("비밀번호가 유효하지 않습니다.");
e.preventDefault();
newPw.focus();
return;
}else{
if(newPw.value != newPwConfirm.value){
alert("비밀번호가 일치하지 않습니다.");
e.preventDefault();
newPwConfirm.focus();
return;
}
}
})
}
const secessionFrm = document.getElementById("secessionFrm");
const memberPw = document.getElementById("memberPw");
const agree = document.getElementById("agree");
if(secessionFrm != null){
secessionFrm.addEventListener("submit", e =>{
if(memberPw.value.trim() == ""){
alert("비밀번호를 입력해주세요");
memberPw.focus();
e.preventDefault();
return;
}
if(!agree.checked){
alert(" 약관동의 후 탈퇴 버튼을 눌러주세요")
e.preventDefault();
agree.focus();
return;
}
if(!confirm("정말로 탈퇴하시겠습니까?")){
alert("탈퇴취소")
e.preventDefault();
memberPw.value="";
return;
}
})
}