Commit 731cc282 authored by 한규민's avatar 한규민
Browse files

인증번호 주석 풀지 마세요

돈 나가요ㅠㅠ
parent 1563c9a4
/node_modules /node_modules
.env.development .env.development
.env .env
./upload
\ No newline at end of file
...@@ -32,13 +32,13 @@ const compareId = async (userId) => { ...@@ -32,13 +32,13 @@ const compareId = async (userId) => {
const confirmMbnum = async (phone) => { const confirmMbnum = async (phone) => {
const url = `${baseUrl}/api/auth/phone/${phone}` const url = `${baseUrl}/api/auth/phone/${phone}`
const { data } = await axios.post(url) const { data } = await axios.post(url);
return data return data
} }
const confirmNum = async (num) => { const confirmNum = async (confirmNum) => {
const url = `${baseUrl}/api/auth/num/${num}` const url = `${baseUrl}/api/auth/num`
const { data } = await axios.get(url) const { data } = await axios.post(url, confirmNum);
return data return data
} }
...@@ -61,7 +61,8 @@ const comparePw = async (pw) => { ...@@ -61,7 +61,8 @@ const comparePw = async (pw) => {
const modifyUser = async (user) => { const modifyUser = async (user) => {
const url = `${baseUrl}/api/auth/modify` const url = `${baseUrl}/api/auth/modify`
await axios.post(url, user) const { data } = await axios.post(url, user)
return data
} }
const authApi = { const authApi = {
......
...@@ -8,6 +8,7 @@ const MyInfo = () => { ...@@ -8,6 +8,7 @@ const MyInfo = () => {
const [img, setImg] = useState(""); const [img, setImg] = useState("");
const [profile, setProfile] = useState(""); const [profile, setProfile] = useState("");
const [startTime, setStartTime] = useState("");
// 사용자 이름 가져오는 함수 // 사용자 이름 가져오는 함수
const getMember = async () => { const getMember = async () => {
const member = await authApi.getMember(); const member = await authApi.getMember();
...@@ -22,16 +23,21 @@ const MyInfo = () => { ...@@ -22,16 +23,21 @@ const MyInfo = () => {
//변경할 데이터 입력받는 state //변경할 데이터 입력받는 state
const [userRe, setUserRe] = useState({ const [userRe, setUserRe] = useState({
userName: "",
userEmail: "", userEmail: "",
userNickName: "", userNickName: "",
userMbnum: "", userMbnum: "",
userPassword: "", userPassword: "",
userRePassword: "" userRePassword: ""
}) })
const [confirmMb, setConfirmMb] = useState(false);
const [number, setNumber] = useState(null);
//각 타입별 error 유무 state //각 타입별 error 유무 state
const [mbError,setMbError] = useState(false);
const [error, setError] = useState(""); const [error, setError] = useState("");
const [errorMsg, setErrorMsg] = useState({ const [errorMsg, setErrorMsg] = useState({
errorName: false,
errorEmail: false, errorEmail: false,
errorNickName: false, errorNickName: false,
errorMbnum: false, errorMbnum: false,
...@@ -62,7 +68,6 @@ const MyInfo = () => { ...@@ -62,7 +68,6 @@ const MyInfo = () => {
} }
const enterKey = (e) => { const enterKey = (e) => {
if (e.key === "Enter") { if (e.key === "Enter") {
handleOnSummitVerify(e); handleOnSummitVerify(e);
} }
} }
...@@ -105,6 +110,55 @@ const MyInfo = () => { ...@@ -105,6 +110,55 @@ const MyInfo = () => {
} }
} }
const handleOnClickMbnum = async (e) => {
e.preventDefault();
try {
setStartTime("");
setError("");
setLoading(true);
const phone = userRe.userMbnum;
console.log("phone : ", phone);
const message = await authApi.confirmMbnum(phone);
console.log("message : ", message);
if(message.isSuccess){
console.log("mberror: "+mbError);
setMbError("보냄");
setStartTime(message.startTime);
}
} catch (error) {
console.log('error'+ error)
}finally {
setLoading(false);
}
}
const handleOnChangeMb = (e) => {
setNumber(String(e.target.value));
}
const handleOnClickMbConfirm = async (e) => {
e.preventDefault();
try {
setError("");
setLoading(true);
console.log("startTime : ", startTime);
const confirmNum = {userMbnum : userRe.userMbnum, number : number, startTime : startTime};
console.log(confirmNum);
const message = await authApi.confirmNum(confirmNum);
console.log(message);
setMbError(message);
if(message === "성공"){
setConfirmMb(true);
console.log("인증완료");
}
} catch (error) {
catchErrors(error, setError);
}finally {
setLoading(false);
}
}
//비교하여 error메세지 반환 //비교하여 error메세지 반환
const vaildationData = (text, compareValue, error) => { const vaildationData = (text, compareValue, error) => {
if (text !== compareValue) { if (text !== compareValue) {
...@@ -121,8 +175,11 @@ const MyInfo = () => { ...@@ -121,8 +175,11 @@ const MyInfo = () => {
setErrorMsg(errorMsg => ({ ...errorMsg, [error]: false })); setErrorMsg(errorMsg => ({ ...errorMsg, [error]: false }));
} }
} }
//유효성 검사 //유효성 검사
const validation = () => { const validation = () => {
//이름 유효성 검사
vaildationData((userRe.userName.length === 0), false, "errorName");
//별명 유효성 검사 //별명 유효성 검사
vaildationData((userRe.userNickName.length === 0), false, "errorNickName"); vaildationData((userRe.userNickName.length === 0), false, "errorNickName");
// 휴대폰 유효성 검사 // 휴대폰 유효성 검사
...@@ -133,31 +190,29 @@ const MyInfo = () => { ...@@ -133,31 +190,29 @@ const MyInfo = () => {
vaildationData(userRe.userPassword, userRe.userRePassword, "errorRePassword"); vaildationData(userRe.userPassword, userRe.userRePassword, "errorRePassword");
// 최종 유효성 검사 // 최종 유효성 검사
if ((Object.values(errorMsg).some((element) => (element)) === false)) { if (!(Object.values(errorMsg).some((element) => (element)))) {
return true return true
} else { } else {
return false return false
} }
} }
const handleOnSummit = async (e) => { const handleOnSummit = async (e) => {
e.preventDefault(); e.preventDefault();
try { try {
console.log('handle ?????')
setError(() => ("")); setError(() => (""));
//처리가 될때까지 버튼(가입하기)이 안눌리게 지정 //처리가 될때까지 버튼(가입하기)이 안눌리게 지정
setLoading(() => (true)); setLoading(() => (true));
console.log("userRe : " + userRe.userEmail);
//유효성 검사 //유효성 검사
let valid = validation(); let valid = validation();
console.log("valid :" + valid); console.log('handle on submit', valid)
if (valid) { if (valid) {
const userData = userRe; const userData = userRe;
console.log(userData); console.log(userData);
//서버로 전송 //서버로 전송
const process = await authApi.modifyUser(userData); const result = await authApi.modifyUser(userData);
console.log("process : " + process); console.log("result : " + result);
alert("회원정보 수정 완료"); alert("회원정보 수정 완료");
valid = false; valid = false;
} else { throw new Error("유효하지 않은 데이터입니다.") } } else { throw new Error("유효하지 않은 데이터입니다.") }
...@@ -190,8 +245,8 @@ const MyInfo = () => { ...@@ -190,8 +245,8 @@ const MyInfo = () => {
</div> </div>
</div> </div>
</div> </div>
{/* 프로필 변경 모달창 */}
<div className="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true"> <div className="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabIndex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div className="modal-dialog modal-dialog-centered"> <div className="modal-dialog modal-dialog-centered">
<form className="modal-content" onSubmit={handleOnSummitForm}> <form className="modal-content" onSubmit={handleOnSummitForm}>
<div className="modal-header"> <div className="modal-header">
...@@ -210,15 +265,15 @@ const MyInfo = () => { ...@@ -210,15 +265,15 @@ const MyInfo = () => {
</div> </div>
{/* 기존 비밀번호 확인 모달창 */} {/* 기존 비밀번호 확인 모달창 */}
<div className="modal fade" id="verifyPassword" data-bs-backdrop="static" data-bs-keyboard="false" aria-hidden="true" aria-labelledby="verifyPasswordLabel" tabindex="-1"> <div className="modal fade" id="verifyPassword" data-bs-backdrop="static" data-bs-keyboard="false" aria-hidden="true" aria-labelledby="verifyPasswordLabel" tabIndex="-1">
<div className="modal-dialog modal-dialog-centered modal-dialog-centered"> <div className="modal-dialog modal-dialog-centered modal-dialog-centered">
{page ? {page ?
<><form className="modal-content" onSubmit={handleOnSummitVerify}> <><form className="modal-content" onSubmit={handleOnSummitVerify}>
<div className="modal-header"> <div className="modal-header">
<h5 className="modal-title" id="verifyPasswordLabel">기존 비밀번호 확인</h5> <h5 className="modal-title" id="verifyPasswordLabel">기존 비밀번호 확인</h5>
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close" onclick={handleOnClick}></button> <button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close" onClick={handleOnClick}></button>
</div> </div>
<div clasNames="modal-body"> <div className="modal-body">
<div className="d-flex flex-column"> <div className="d-flex flex-column">
<div className="d-flex justify-content-around align-items-center my-4"> <div className="d-flex justify-content-around align-items-center my-4">
<label className={styles.signupLabel}>현재 비밀번호</label> <label className={styles.signupLabel}>현재 비밀번호</label>
...@@ -233,13 +288,20 @@ const MyInfo = () => { ...@@ -233,13 +288,20 @@ const MyInfo = () => {
: <><form className={`modal-content d-flex col-md-6 col-12 justify-content-center d-flex flex-column`} onSubmit={handleOnSummit}> : <><form className={`modal-content d-flex col-md-6 col-12 justify-content-center d-flex flex-column`} onSubmit={handleOnSummit}>
<div className="modal-header"> <div className="modal-header">
<h5 className="modal-title" id="modifyLabel">회원정보 수정</h5> <h5 className="modal-title" id="modifyLabel">회원정보 수정</h5>
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close" onclick={handleOnClick}></button> <button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close" onClick={handleOnClick}></button>
</div> </div>
<div className={`modal-body`}> <div className={`modal-body`}>
<div className="d-flex flex-column">
<div className={styles.inputContent}>
<label className={styles.signupLabel}>이름</label>
<input className={`${styles.input} ${styles.inputSize}`} type="text" name="userName" placeholder="이름을 입력해주세요" onChange={handleUserOnChange} maxLength="11" required />
</div>
{errorMsg.errorName && <p className={styles.passwordConfirmError}>이름을 입력해주세요</p>}
</div>
<div className="d-flex flex-column"> <div className="d-flex flex-column">
<div className={styles.inputContent}> <div className={styles.inputContent}>
<label className={styles.signupLabel}>이메일</label> <label className={styles.signupLabel}>이메일</label>
<input className={`${styles.input} ${styles.inputSize}`} type="email" name="userEmail" placeholder="이메일을 입력해주세요" onChange={handleUserOnChange} maxlength="20" required /> <input className={`${styles.input} ${styles.inputSize}`} type="email" name="userEmail" placeholder="이메일을 입력해주세요" onChange={handleUserOnChange} maxLength="20" required />
</div> </div>
{errorMsg.errorEmail && <p className={styles.passwordConfirmError}>이메일을 입력해주세요</p>} {errorMsg.errorEmail && <p className={styles.passwordConfirmError}>이메일을 입력해주세요</p>}
</div> </div>
...@@ -255,11 +317,28 @@ const MyInfo = () => { ...@@ -255,11 +317,28 @@ const MyInfo = () => {
<div className={styles.inputContent}> <div className={styles.inputContent}>
<label className={styles.signupLabel}>휴대폰 번호</label> <label className={styles.signupLabel}>휴대폰 번호</label>
<div className="d-flex col-md-auto"> <div className="d-flex col-md-auto">
<input className={`${styles.input} ${styles.inputSize}`} type="number" name="userMbnum" placeholder="-없이 11자리 입력" onChange={handleUserOnChange} min="" max="99999999999" required /> <input className={`${styles.input} `} type="number" name="userMbnum" placeholder="-없이 11자리 입력" onChange={handleUserOnChange} min="" max="99999999999" required />
<button type="button" disabled={loading} className={`rounded-2 mt-2 ${styles.butterYellowAndBtn} ${styles.btnHover}`} data-bs-toggle="collapse" data-bs-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample" onClick={handleOnClickMbnum}>인증번호받기</button>
</div> </div>
</div> </div>
{errorMsg.errorMbnum && <p className={styles.passwordConfirmError}>-없이 숫자 11자리를 입력해주세요.</p>} {errorMsg.errorMbnum && <p className={styles.passwordConfirmError}>-없이 숫자 11자리를 입력해주세요.</p>}
<div className="collapse" id="collapseExample">
{/* <div className="d-flex col-md-auto justify-content-end"> */}
<div className="d-flex justify-content-around mt-3">
<label className={`${styles.confirm}`}>인증하기</label>
<div>
<input className={`${styles.input}`} type="number" placeholder="인증번호를 입력" onChange={handleOnChangeMb} required/>
<button type="button" className={`rounded-2 py-2 ${styles.butterYellowAndBtn} ${styles.btnHover}`} onClick={handleOnClickMbConfirm}>확인</button>
<button type="button" className={`rounded-2 py-2 ${styles.butterYellowAndBtn} ${styles.btnHover}`} onClick={handleOnClickMbnum}>재전송</button>
</div> </div>
</div>
{(mbError === "재전송") && <p className={styles.passwordConfirmError}>유효시간이 만료되었습니다. 재전송해주세요.</p>}
{(mbError === "보냄") && <p className={styles.passwordConfirmError}>5분이내에 입력해주세요.</p>}
{(mbError === "성공") && <p className={styles.passwordConfirmError}>인증되었습니다.</p>}
{(mbError === "실패") && <p className={styles.passwordConfirmError}>인증번호를 다시 입력해주세요.</p>}
</div>
</div>
<div className="d-flex flex-column"> <div className="d-flex flex-column">
<div className={styles.inputContent}> <div className={styles.inputContent}>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
display: flex; display: flex;
justify-content: center; justify-content: center;
color: #FEDC00; color: #FEDC00;
font-size: 1.8rem; font-size: 3rem;
margin: 2rem 0; margin: 2rem 0;
} }
img{ img{
...@@ -22,7 +22,7 @@ width: 40%; ...@@ -22,7 +22,7 @@ width: 40%;
} }
.userName{ .userName{
color: white; color: white;
font-size: 1.3rem; font-size: 1.8rem;
} }
.contents{ .contents{
...@@ -120,9 +120,11 @@ width: 40%; ...@@ -120,9 +120,11 @@ width: 40%;
.passwordConfirmError{ .passwordConfirmError{
margin-bottom: 0; margin-bottom: 0;
margin-top: 0.5rem; margin-top: 0.5rem;
margin-right: 3rem;
text-align: end; text-align: end;
font-size: 13px; font-size: 13px;
color: #FEDC00; font-weight: bold;
color: black;
} }
@media (max-width: 403px) { @media (max-width: 403px) {
......
import styles from "./reservation-details.module.scss"; import styles from "./reservation-details.module.scss";
const ReservationDetails = () => { const ReservationDetails = () => {
return( return (
<div className={`${styles.width}`}> <div className={`d-flex flex-column align-items-center ${styles.width}`}>
<header className={`${styles.header}`}>나의 예매 내역</header> <div className={`${styles.header}`}>나의 예매 내역</div>
<main> <div className={`${styles.body}`}>
<div className={`d-flex justify-content-around align-items-center py-3`}>
</main> <div className={`${styles.span} d-flex justify-content-center`}>
<span>영화 포스터</span>
</div>
<div className={`${styles.span} d-flex flex-column`}>
<span>영화제목</span>
<span>예매확인번호</span>
<span>예매날짜</span>
<span>상영관</span>
<span>좌석정보</span>
<span>결제금액</span>
<span>결제수단</span>
</div>
</div>
</div>
<div className={`${styles.header}`}>나의 리뷰</div>
</div> </div>
) )
} }
......
.width{ .width{
width : 100%; width : 100%;
display: flex; display: flex;
margin-top: 5rem;
justify-content: center; justify-content: center;
} }
.header{ .header{
display: flex; display: flex;
...@@ -12,5 +10,15 @@ ...@@ -12,5 +10,15 @@
width: 80%; width: 80%;
text-align: center; text-align: center;
font-size: 2.5rem; font-size: 2.5rem;
margin: 5rem;
}
.body{
width: 80%;
border-top: 1px solid #FEDC00;
border-bottom: 1px solid #FEDC00;
}
.span span{
color:white;
font-size: 1.5rem;
} }
\ No newline at end of file
...@@ -7,6 +7,7 @@ import catchErrors from "../../utils/catchErrors.js"; ...@@ -7,6 +7,7 @@ import catchErrors from "../../utils/catchErrors.js";
const Signup = () => { const Signup = () => {
const [user, setUser] = useState({ const [user, setUser] = useState({
userId: "", userId: "",
userName:"",
userEmail: "", userEmail: "",
userNickName: "", userNickName: "",
userBirthday: "", userBirthday: "",
...@@ -14,7 +15,7 @@ const Signup = () => { ...@@ -14,7 +15,7 @@ const Signup = () => {
userPassword: "", userPassword: "",
userRePassword: "" userRePassword: ""
}) })
const [startTime, setStartTime] = useState("");
const [number, setNumber] = useState(null); const [number, setNumber] = useState(null);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false); const [success, setSuccess] = useState(false);
...@@ -23,6 +24,7 @@ const Signup = () => { ...@@ -23,6 +24,7 @@ const Signup = () => {
const [error, setError] = useState(""); const [error, setError] = useState("");
const [errorMsg, setErrorMsg] = useState({ const [errorMsg, setErrorMsg] = useState({
errorId: null, errorId: null,
errorName: false,
errorEmail: false, errorEmail: false,
errorNickName: false, errorNickName: false,
errorBirthday: false, errorBirthday: false,
...@@ -87,15 +89,18 @@ const Signup = () => { ...@@ -87,15 +89,18 @@ const Signup = () => {
const handleOnClickMbnum = async (e) => { const handleOnClickMbnum = async (e) => {
e.preventDefault(); e.preventDefault();
try { try {
setStartTime("");
setError(""); setError("");
setLoading(true) setLoading(true)
const phone = user.userMbnum; const phone = user.userMbnum;
console.log("phone : ", phone) console.log("phone : ", phone);
const message = await authApi.confirmMbnum(phone); const message = await authApi.confirmMbnum(phone);
console.log("message : ", message); console.log("message : ", message);
if(message.isSuccess){ if(message.isSuccess){
console.log("mberror: "+mbError); console.log("mberror: "+mbError);
setMbError("보냄"); setMbError("보냄");
setStartTime(message.startTime);
} }
} catch (error) { } catch (error) {
console.log('error'+ error) console.log('error'+ error)
...@@ -112,9 +117,10 @@ const Signup = () => { ...@@ -112,9 +117,10 @@ const Signup = () => {
e.preventDefault(); e.preventDefault();
try { try {
setError(""); setError("");
setLoading(true) setLoading(true);
const confirmNum = number; console.log("startTime : ", startTime);
console.log(confirmNum) const confirmNum = {userMbnum : user.userMbnum, number : number, startTime : startTime};
console.log(confirmNum);
const message = await authApi.confirmNum(confirmNum); const message = await authApi.confirmNum(confirmNum);
console.log(message); console.log(message);
setMbError(message); setMbError(message);
...@@ -129,6 +135,9 @@ const Signup = () => { ...@@ -129,6 +135,9 @@ const Signup = () => {
} }
} }
const handleOnSummit = async (e) => { const handleOnSummit = async (e) => {
e.preventDefault(); e.preventDefault();
try { try {
...@@ -176,6 +185,8 @@ const Signup = () => { ...@@ -176,6 +185,8 @@ const Signup = () => {
setPreId(user.userId); setPreId(user.userId);
//아이디 유효성 검사 //아이디 유효성 검사
vaildationIdPw(user.userId.length, 5, "errorId"); vaildationIdPw(user.userId.length, 5, "errorId");
//이름 유효성 검사
vaildationData((user.userName.length === 0), false, "errorName");
//별명 유효성 검사 //별명 유효성 검사
vaildationData((user.userNickName.length === 0), false, "errorNickName"); vaildationData((user.userNickName.length === 0), false, "errorNickName");
// 생일 유효성 검사 // 생일 유효성 검사
...@@ -228,6 +239,13 @@ const Signup = () => { ...@@ -228,6 +239,13 @@ const Signup = () => {
{overlapId && (errorMsg.errorId === false) && <p className={styles.passwordConfirmError}>아이디 중복이 확인되었습니다.</p>} {overlapId && (errorMsg.errorId === false) && <p className={styles.passwordConfirmError}>아이디 중복이 확인되었습니다.</p>}
{(errorMsg.errorId === false) && (overlapId === false) && <p className={styles.passwordConfirmError}>아이디 중복확인을 해주세요.</p>} {(errorMsg.errorId === false) && (overlapId === false) && <p className={styles.passwordConfirmError}>아이디 중복확인을 해주세요.</p>}
</div> </div>
<div className="d-flex flex-column">
<div className={styles.inputContent}>
<label className={styles.signupLabel}>이름</label>
<input className={`${styles.input} ${styles.inputSize}`} type="text" name="userName" placeholder="이름을 입력해주세요" onChange={handleUserOnChange} maxlength="10" required />
</div>
{errorMsg.errorName && <p className={styles.passwordConfirmError}>이름을 입력해주세요</p>}
</div>
<div className="d-flex flex-column"> <div className="d-flex flex-column">
<div className={styles.inputContent}> <div className={styles.inputContent}>
<label className={styles.signupLabel}>이메일</label> <label className={styles.signupLabel}>이메일</label>
...@@ -266,7 +284,7 @@ const Signup = () => { ...@@ -266,7 +284,7 @@ const Signup = () => {
<div className="d-flex justify-content-between mt-3"> <div className="d-flex justify-content-between mt-3">
<label className={`${styles.confirm}`}>인증하기</label> <label className={`${styles.confirm}`}>인증하기</label>
<div> <div>
<input className={`${styles.input} ${styles.input2}`} type="number" placeholder="인증번호를 입력" onChange={handleOnChangeMb} require /> <input className={`${styles.input} ${styles.input2}`} type="number" placeholder="인증번호를 입력" onChange={handleOnChangeMb} required/>
<button type="button" className={`rounded-2 py-2 ${styles.butterYellowAndBtn} ${styles.btnHover}`} onClick={handleOnClickMbConfirm}>확인</button> <button type="button" className={`rounded-2 py-2 ${styles.butterYellowAndBtn} ${styles.btnHover}`} onClick={handleOnClickMbConfirm}>확인</button>
<button type="button" className={`rounded-2 py-2 ${styles.butterYellowAndBtn} ${styles.btnHover}`} onClick={handleOnClickMbnum}>재전송</button> <button type="button" className={`rounded-2 py-2 ${styles.butterYellowAndBtn} ${styles.btnHover}`} onClick={handleOnClickMbnum}>재전송</button>
</div> </div>
......
...@@ -59,7 +59,7 @@ const TicketingSeatPage = ({ location }) => { ...@@ -59,7 +59,7 @@ const TicketingSeatPage = ({ location }) => {
return ( return (
<> <>
<div ref={modalRef} className="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden={modal}> <div ref={modalRef} className="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabIndex="-1" aria-labelledby="staticBackdropLabel" aria-hidden={modal}>
<div className="modal-dialog"> <div className="modal-dialog">
<div className="modal-content"> <div className="modal-content">
{ } { }
......
...@@ -4,6 +4,7 @@ const config = { ...@@ -4,6 +4,7 @@ const config = {
jwtSecret: 'dfkasf23i$efksdfks!', jwtSecret: 'dfkasf23i$efksdfks!',
jwtExpires: '7d', jwtExpires: '7d',
cookieName: 'butterStudio', cookieName: 'butterStudio',
cookieNameMb: 'confirmNum',
cookieMaxAge: 60 * 60 * 24 * 7 * 1000, cookieMaxAge: 60 * 60 * 24 * 7 * 1000,
kakaoAdminKey: 'e3ce7106688a35e072e2630daa9d7250', kakaoAdminKey: 'e3ce7106688a35e072e2630daa9d7250',
} }
......
import jwt from "jsonwebtoken"; import jwt from "jsonwebtoken";
import config from "../config/app.config.js"; import config from "../config/app.config.js";
import { User, Role } from '../db/index.js'; import { User, Role, ConfirmNum } from '../db/index.js';
import fs from "fs"; import fs from "fs";
import CryptoJS from "crypto-js"; import CryptoJS from "crypto-js";
import axios from "axios"; import axios from "axios";
...@@ -95,7 +95,6 @@ const compareId = async (req, res) => { ...@@ -95,7 +95,6 @@ const compareId = async (req, res) => {
} }
// 휴대폰 인증 // 휴대폰 인증
const NCP_serviceID = 'ncp:sms:kr:270376424445:butterstudio'; const NCP_serviceID = 'ncp:sms:kr:270376424445:butterstudio';
const NCP_accessKey = 'GQmVCT2ZFxnEaJOWbrQs'; const NCP_accessKey = 'GQmVCT2ZFxnEaJOWbrQs';
const NCP_secretKey = 'XLQQ8sd9WxW40hNi0xNBTOG0T8ksRsr8c8sUIEvy'; const NCP_secretKey = 'XLQQ8sd9WxW40hNi0xNBTOG0T8ksRsr8c8sUIEvy';
...@@ -123,12 +122,8 @@ hmac.update(accessKey); ...@@ -123,12 +122,8 @@ hmac.update(accessKey);
const hash = hmac.finalize(); const hash = hmac.finalize();
const signature = hash.toString(CryptoJS.enc.Base64); const signature = hash.toString(CryptoJS.enc.Base64);
let inherentNum = "";
// 유효시간 5분 설정
const time = () => {
inherentNum = false;
return inherentNum
}
// 인증번호 발송 // 인증번호 발송
const confirmMbnum = async (req, res) => { const confirmMbnum = async (req, res) => {
...@@ -139,39 +134,56 @@ const confirmMbnum = async (req, res) => { ...@@ -139,39 +134,56 @@ const confirmMbnum = async (req, res) => {
//인증번호 생성 //인증번호 생성
const verifyCode = Math.floor(Math.random() * (999999 - 100000)) + 100000; const verifyCode = Math.floor(Math.random() * (999999 - 100000)) + 100000;
console.log("verifyCode : ",verifyCode); console.log("verifyCode : ",verifyCode);
let today = new Date();
let time = String(today.getTime());
console.log("time : ", time);
// let result = await axios({
// method: method,
// json: true,
// url: url,
// headers: {
// 'Content-Type': "application/json",
// 'x-ncp-apigw-timestamp': date,
// 'x-ncp-iam-access-key': accessKey,
// 'x-ncp-apigw-signature-v2': signature,
// },
// data: {
// type: 'SMS',
// contentType: 'COMM',
// countryCode: '82',
// from: '01086074580',
// content: `[본인 확인] 인증번호 [${verifyCode}]를 입력해주세요.`,
// messages: [
// {
// to: `${phoneNumber}`,
// },
// ],
// },
// });
let result = await axios({ // const resultMs = result.data.messages;
method: method, // console.log('resultMs', resultMs);
json: true,
url: url,
headers: {
'Content-Type': "application/json",
'x-ncp-apigw-timestamp': date,
'x-ncp-iam-access-key': accessKey,
'x-ncp-apigw-signature-v2': signature,
},
data: {
type: 'SMS',
contentType: 'COMM',
countryCode: '82',
from: '01086074580',
content: `[본인 확인] 인증번호 [${verifyCode}]를 입력해주세요.`,
messages: [
{
to: `${phoneNumber}`,
},
],
},
});
const resultMs = result.data.messages;
console.log('resultMs', resultMs);
console.log('response', res.data, res['data']);
inherentNum = String(verifyCode);
// console.log('response', res.data, res['data']);
const confirm = await ConfirmNum.findOne({ where: { phone: phoneNumber} });
console.log(confirm);
if(confirm){
await confirm.destroy();
// 5분 유효시간 설정 // 5분 유효시간 설정
setTimeout(time, 300000); await ConfirmNum.create({
res.json({ isSuccess: true, code: 202, message: "본인인증 문자 발송 성공", result: res.data }); confirmNum: String(verifyCode),
phone: phoneNumber,
startTime: time,
});
}else{
await ConfirmNum.create({
confirmNum: String(verifyCode),
phone: phoneNumber,
startTime: time,
}
);
}
res.json({ startTime: time, isSuccess: true, code: 202, message: "본인인증 문자 발송 성공", result: res.data });
} catch (error) { } catch (error) {
console.log("error: ", error); console.log("error: ", error);
if (error.res == undefined) { if (error.res == undefined) {
...@@ -180,19 +192,30 @@ const confirmMbnum = async (req, res) => { ...@@ -180,19 +192,30 @@ const confirmMbnum = async (req, res) => {
else res.json({ isSuccess: true, code: 204, message: "본인인증 문자 발송에 문제가 있습니다.", result: error.res }); else res.json({ isSuccess: true, code: 204, message: "본인인증 문자 발송에 문제가 있습니다.", result: error.res });
} }
}; };
// 인증번호 확인 // 인증번호 확인
const confirmNum = async (req, res) => { const confirmNum = async (req, res) => {
try { try {
const verifyCode = inherentNum; const {userMbnum, number, startTime} = req.body;
const confirmNum = req.params.num; console.log(userMbnum, number, startTime);
if(!verifyCode){ const confirm = await ConfirmNum.findOne({ where: { phone: userMbnum, startTime: startTime} });
res.send("재전송") console.log(confirm);
}else{
if (confirmNum !== verifyCode) { let today = new Date();
let time = today.getTime();
console.log("time2 :", time);
const elapsedMSec = time - confirm.startTime;
const elapsedMin = String(elapsedMSec / 1000 / 60);
console.log("elapsedMin : ", elapsedMin);
if(elapsedMin <= 5 ){
if (number !== confirm.confirmNum) {
res.send("실패"); res.send("실패");
}else { }else {
await confirm.destroy();
res.send("성공"); res.send("성공");
} }
}else{
res.send("재전송")
} }
} catch (error) { } catch (error) {
console.error("error : ", error.message); console.error("error : ", error.message);
...@@ -201,10 +224,9 @@ const confirmNum = async (req, res) => { ...@@ -201,10 +224,9 @@ const confirmNum = async (req, res) => {
}; };
const signup = async (req, res) => { const signup = async (req, res) => {
const { userId, userEmail, userNickName, userBirthday, userMbnum, userPassword } = req.body; const { userId, userName, userEmail, userNickName, userBirthday, userMbnum, userPassword } = req.body;
// 휴대폰 중복 확인
try { try {
const mbnum = await User.findOne({ where: { phoneNumber: userMbnum } }); const mbnum = await User.findOne({ where: { phoneNumber: userMbnum }});
const email = await User.findOne({ where: { email: userEmail } }); const email = await User.findOne({ where: { email: userEmail } });
if (mbnum && email) { if (mbnum && email) {
...@@ -217,6 +239,7 @@ const signup = async (req, res) => { ...@@ -217,6 +239,7 @@ const signup = async (req, res) => {
const role = await Role.findOne({ where: { name: "member" } }) const role = await Role.findOne({ where: { name: "member" } })
const newUser = await User.create({ const newUser = await User.create({
userId: userId, userId: userId,
name: userName,
email: userEmail, email: userEmail,
nickname: userNickName, nickname: userNickName,
birth: userBirthday, birth: userBirthday,
...@@ -258,7 +281,6 @@ const uploadProfile = async (req, res) => { ...@@ -258,7 +281,6 @@ const uploadProfile = async (req, res) => {
if (decoded) { if (decoded) {
const img = await User.findOne({ where: { id: decoded.id }, attributes: ["img"] }); const img = await User.findOne({ where: { id: decoded.id }, attributes: ["img"] });
console.log("여기여기");
fs.unlink("upload" + `\\${img.img}`, function (data) { console.log(data); }); fs.unlink("upload" + `\\${img.img}`, function (data) { console.log(data); });
const user = await User.update({ const user = await User.update({
...@@ -304,7 +326,6 @@ const overlap = async (decoded, dataType, data) => { ...@@ -304,7 +326,6 @@ const overlap = async (decoded, dataType, data) => {
let overlap = await User.findOne({ where: { id: decoded.id } }); let overlap = await User.findOne({ where: { id: decoded.id } });
console.log("기존 데이터 : ", overlap, "변경할 데이터 : ", data); console.log("기존 데이터 : ", overlap, "변경할 데이터 : ", data);
if (overlap[dataType] === data) { if (overlap[dataType] === data) {
console.log("여기여기")
return true return true
} else { } else {
let overlap2 = await User.findOne({ attributes: [dataType] }); let overlap2 = await User.findOne({ attributes: [dataType] });
...@@ -324,21 +345,19 @@ const modifyUser = async (req, res) => { ...@@ -324,21 +345,19 @@ const modifyUser = async (req, res) => {
try { try {
const token = req.cookies.butterStudio; const token = req.cookies.butterStudio;
const decoded = jwt.verify(token, config.jwtSecret); const decoded = jwt.verify(token, config.jwtSecret);
const { userEmail, userNickName, userMbnum, userPassword } = req.body; const { userName, userEmail, userNickName, userMbnum, userPassword } = req.body;
console.log(userEmail);
console.log(userMbnum);
const overlapEmail = await overlap(decoded, "email", userEmail); const overlapEmail = await overlap(decoded, "email", userEmail);
const overlapMbnum = await overlap(decoded, "phoneNumber", userMbnum); const overlapMbnum = await overlap(decoded, "phoneNumber", userMbnum);
console.log("overlapEmail", overlapEmail, " overlapMbnum : ", overlapMbnum);
if (overlapEmail && overlapMbnum) { if (overlapEmail && overlapMbnum) {
const user = await User.update({ const user = await User.update({
name: userName,
email: userEmail, email: userEmail,
nickname: userNickName, nickname: userNickName,
phoneNumber: userMbnum, phoneNumber: userMbnum,
password: userPassword, password: userPassword,
}, { where: { id: decoded.id } }); }, { where: { id: decoded.id }, individualHooks: true });
console.log("user22 :", user); console.log("user22 :", user);
res.json(user); res.json(user);
} else if (!overlapEmail && overlapMbnum) { } else if (!overlapEmail && overlapMbnum) {
...@@ -353,6 +372,7 @@ const modifyUser = async (req, res) => { ...@@ -353,6 +372,7 @@ const modifyUser = async (req, res) => {
res.status(500).send("수정 에러. 나중에 다시 시도 해주세요"); res.status(500).send("수정 에러. 나중에 다시 시도 해주세요");
} }
}; };
const getUserInfo = async (req, res) => { const getUserInfo = async (req, res) => {
const { id } = req.body const { id } = req.body
console.log(id) console.log(id)
......
...@@ -8,6 +8,7 @@ import TheaterTypeModel from "../models/theatertype.model.js"; ...@@ -8,6 +8,7 @@ import TheaterTypeModel from "../models/theatertype.model.js";
import TicketFeeModel from "../models/ticketfee.model.js"; import TicketFeeModel from "../models/ticketfee.model.js";
import TimeTableModel from '../models/role.model.js'; import TimeTableModel from '../models/role.model.js';
import ReservationModel from '../models/reservation.model.js'; import ReservationModel from '../models/reservation.model.js';
import ConfirmNumModel from '../models/confirmnum.model.js'
import dbConfig from "../config/db.config.js"; import dbConfig from "../config/db.config.js";
const sequelize = new Sequelize( const sequelize = new Sequelize(
...@@ -35,6 +36,7 @@ const TheaterType = TheaterTypeModel(sequelize) ...@@ -35,6 +36,7 @@ const TheaterType = TheaterTypeModel(sequelize)
const TicketFee = TicketFeeModel(sequelize) const TicketFee = TicketFeeModel(sequelize)
const TimeTable = TimeTableModel(sequelize) const TimeTable = TimeTableModel(sequelize)
const Reservation = ReservationModel(sequelize) const Reservation = ReservationModel(sequelize)
const ConfirmNum = ConfirmNumModel(sequelize)
User.belongsTo(Role); User.belongsTo(Role);
Role.hasOne(User); Role.hasOne(User);
...@@ -53,5 +55,6 @@ export { ...@@ -53,5 +55,6 @@ export {
TheaterType, TheaterType,
TicketFee, TicketFee,
TimeTable, TimeTable,
Reservation Reservation,
ConfirmNum
} }
\ No newline at end of file
...@@ -22,6 +22,7 @@ sequelize ...@@ -22,6 +22,7 @@ sequelize
if (!adminRole) { if (!adminRole) {
await User.create({ await User.create({
userId: "admin", userId: "admin",
name: "관리자",
email: "han35799@naver.com", email: "han35799@naver.com",
nickname: "haha", nickname: "haha",
birth: "990926", birth: "990926",
......
import Sequelize from "sequelize";
const { DataTypes } = Sequelize;
const ConfirmNumModel = (sequelize) => {
const ConfirmNum = sequelize.define(
"confirmnum",
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
confirmNum: {
type: DataTypes.STRING,
},
phone: {
type: DataTypes.STRING
},
startTime: {
type: DataTypes.STRING
},
},
{
timestamps: true,
freezeTableName: true,
tableName: "confirmnum"
}
);
return ConfirmNum;
};
export default ConfirmNumModel;
\ No newline at end of file
...@@ -16,6 +16,9 @@ const UserModel = (sequelize) => { ...@@ -16,6 +16,9 @@ const UserModel = (sequelize) => {
userId: { userId: {
type: DataTypes.STRING type: DataTypes.STRING
}, },
name: {
type: DataTypes.STRING
},
email: { email: {
type: DataTypes.STRING type: DataTypes.STRING
}, },
...@@ -51,6 +54,7 @@ const UserModel = (sequelize) => { ...@@ -51,6 +54,7 @@ const UserModel = (sequelize) => {
); );
User.beforeSave(async (user) => { User.beforeSave(async (user) => {
console.log('update before', user)
if (!user.changed("password")) { if (!user.changed("password")) {
return; return;
} }
......
...@@ -34,6 +34,9 @@ router ...@@ -34,6 +34,9 @@ router
.route("/member") .route("/member")
.get(userCtrl.getMember) .get(userCtrl.getMember)
router
.route("/num")
.post(userCtrl.confirmNum)
router router
.route("/pw/:pw") .route("/pw/:pw")
.get(userCtrl.comparePw) .get(userCtrl.comparePw)
...@@ -46,9 +49,6 @@ router ...@@ -46,9 +49,6 @@ router
.route("/phone/:phone") .route("/phone/:phone")
.post(userCtrl.confirmMbnum) .post(userCtrl.confirmMbnum)
router
.route("/num/:num")
.get(userCtrl.confirmNum)
router.route('/getuserinfo') router.route('/getuserinfo')
.post(userCtrl.getUserInfo) .post(userCtrl.getUserInfo)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment