From ee34bd549c6f40f1215456b3dd638fd17e8dd0bc Mon Sep 17 00:00:00 2001 From: leeyongjae Date: Thu, 17 Oct 2024 10:32:55 +0900 Subject: [PATCH] =?UTF-8?q?Q.CAST=20=EC=9E=90=EB=8F=99=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EB=B9=84=EB=B0=80?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EB=B3=80=EA=B2=BD=20=ED=8C=9D=EC=97=85=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/auth/Login.jsx | 71 +++++++++---------------- src/components/myInfo/UserInfoModal.jsx | 49 ++++++++++++++--- src/locales/ja.json | 2 + src/locales/ko.json | 2 + 4 files changed, 71 insertions(+), 53 deletions(-) diff --git a/src/components/auth/Login.jsx b/src/components/auth/Login.jsx index c43341e3..28416284 100644 --- a/src/components/auth/Login.jsx +++ b/src/components/auth/Login.jsx @@ -16,8 +16,7 @@ import Cookies from 'js-cookie' import { useSearchParams } from 'next/navigation' export default function Login() { - //////////////////////////////////////////////////////////////////////////////// - // 자동 로그인 작업진행중 + // 자동 로그인 const initParams = useSearchParams() const autoLoginParam = initParams.get('autoLoginParam1') useEffect(() => { @@ -26,45 +25,27 @@ export default function Login() { } }, []) const autoLoginProcess = async (autoLoginParam) => { - setSession({ - userId: autoLoginParam, - saleStoreId: null, - name: null, - mail: null, - tel: null, - storeId: 'TEMP02', - userNm: 'ㅇㅇ6610', - userNmKana: '신규사용자 16610', - category: '인상6610', - telNo: '336610', - fax: null, - email: 't10t@naver.com', - pwdInitYn: 'Y', - storeLvl: '2', - groupId: '70000', - }) - - setSessionState({ - userId: autoLoginParam, - saleStoreId: null, - name: null, - mail: null, - tel: null, - storeId: 'TEMP02', - userNm: 'ㅇㅇ6610', - userNmKana: '신규사용자 16610', - category: '인상6610', - telNo: '336610', - fax: null, - email: 't10t@naver.com', - pwdInitYn: 'Y', - storeLvl: '2', - groupId: '70000', - }) - - router.push('/') + await promisePost({ url: '/api/login/v1.0/user/login/autoLoginDecryptData', data: { loginId: autoLoginParam } }) + .then((res) => { + if (res) { + if (res.data) { + post({ url: '/api/login/v1.0/user', data: { loginId: res.data } }).then((response) => { + if (response) { + const result = { ...response, storeLvl: response.groupId === '60000' ? '1' : '2', pwdInitYn: 'Y' } + setSession(result) + setSessionState(result) + router.push('/') + } else { + router.push('/login') + } + }) + } + } + }) + .catch((error) => { + router.push('/login') + }) } - //////////////////////////////////////////////////////////////////////////////// const [userId, setUserId] = useState('') const [checkId, setCheckId] = useState('') @@ -86,12 +67,14 @@ export default function Login() { const [passwordReset, setPasswordReset] = useState(1) - const { promisePost, promisePatch } = useAxios(globalLocaleState) + const { promisePost, promisePatch, post } = useAxios(globalLocaleState) // login process const loginProcess = async (e) => { e.preventDefault() const formData = new FormData(e.target) + + /////////////////////////////////////////////////////////// // 임시 로그인 처리 setSession({ userId: 'NEW016610', @@ -110,7 +93,6 @@ export default function Login() { storeLvl: '1', groupId: '60000', }) - setSessionState({ userId: 'NEW016610', saleStoreId: null, @@ -128,16 +110,14 @@ export default function Login() { storeLvl: '1', groupId: '60000', }) - - // ID SAVE 체크되어 있는 경우, 쿠키 저장 if (chkLoginId) { Cookies.set('chkLoginId', formData.get('id'), { expires: 7 }) } else { Cookies.remove('chkLoginId') } - router.push('/') // 임시 로그인 처리 끝 + /////////////////////////////////////////////////////////// // 로그인 처리 시작 - ** 상단 임시 로그인 추후 삭제 필요 ** // const param = { @@ -173,7 +153,6 @@ export default function Login() { loginId: checkId, email: checkEmail, } - await promisePatch({ url: '/api/login/v1.0/user/init-password', data: param, diff --git a/src/components/myInfo/UserInfoModal.jsx b/src/components/myInfo/UserInfoModal.jsx index 9f8b0721..7643913c 100644 --- a/src/components/myInfo/UserInfoModal.jsx +++ b/src/components/myInfo/UserInfoModal.jsx @@ -8,7 +8,7 @@ export default function UserInfoModal({ userId, userInfoModal, setUserInfoModal const { getMessage } = useMessage() // api 조회 관련 - const { get, promisePatch } = useAxios() + const { get, promisePatch, promisePost } = useAxios() const [info, setInfo] = useState({ userId: '', name: '', @@ -25,6 +25,7 @@ export default function UserInfoModal({ userId, userInfoModal, setUserInfoModal const [showPwd, setShowPwd] = useState(false) const [chkChgPwd, setChkChgPwd] = useState(false) const [chgPwd, setChgPwd] = useState('') + const pwdInput = useRef() const chgPwdInput = useRef() useEffect(() => { @@ -54,7 +55,7 @@ export default function UserInfoModal({ userId, userInfoModal, setUserInfoModal const handleChangePassword = async () => { if (chgPwd === '') { chgPwdInput.current.focus() - return alert(getMessage('myinfo.message.validation.password1')) + return alert(getMessage('myinfo.message.validation.password4')) } if (password === chgPwd) { chgPwdInput.current.focus() @@ -73,6 +74,8 @@ export default function UserInfoModal({ userId, userInfoModal, setUserInfoModal if (res.data.result.resultCode === 'S') { alert(getMessage('myinfo.message.save')) setChkChgPwd(false) + setPassword(chgPwd) + setChgPwd('') } else { alert(res.data.result.resultMsg) } @@ -83,6 +86,40 @@ export default function UserInfoModal({ userId, userInfoModal, setUserInfoModal }) } + // 비밀번호 변경 버튼 클릭 시, + const checkPasswordProcess = async (e) => { + if (password === '') { + pwdInput.current.focus() + return alert(getMessage('myinfo.message.validation.password1')) + } + + const param = { + loginId: userId, + pwd: password, + } + await promisePost({ url: '/api/login/v1.0/login', data: param }) + .then((res) => { + if (res) { + if (res.data.result.resultCode === 'S') { + setChkChgPwd(true) + setTimeout(() => { + chgPwdInput.current.focus() + }, 10) + } else { + alert(getMessage('myinfo.message.password.error')) + setChkChgPwd(false) + setChgPwd('') + setTimeout(() => { + pwdInput.current.focus() + }, 10) + } + } + }) + .catch((error) => { + alert(error.response.data.message) + }) + } + return ( <>
@@ -141,6 +178,7 @@ export default function UserInfoModal({ userId, userInfoModal, setUserInfoModal { setPassword(e.target.value) }} @@ -151,11 +189,8 @@ export default function UserInfoModal({ userId, userInfoModal, setUserInfoModal