Merge pull request 'feat: 비밀번호 재설정 수정' (#93) from feature/pw-reset into dev
Reviewed-on: #93
This commit is contained in:
commit
9ea58d3aea
@ -1,24 +1,28 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { HttpStatusCode } from 'axios'
|
||||
import { loggerWrapper } from '@/libs/api-wrapper'
|
||||
import { axiosInstance } from '@/libs/axios'
|
||||
|
||||
async function setChgPwd(req: Request): Promise<NextResponse> {
|
||||
const { loginId, email, pwd, chgPwd } = await req.json()
|
||||
console.log('🚀 ~ POST ~ loginId:', loginId)
|
||||
console.log('🚀 ~ POST ~ email:', email)
|
||||
console.log('🚀 ~ POST ~ pwd:', pwd)
|
||||
console.log('🚀 ~ POST ~ chgPwd:', chgPwd)
|
||||
|
||||
const result = await axiosInstance(`${process.env.NEXT_PUBLIC_QSP_API_URL}`).post(`/api/user/userPwdChg`, {
|
||||
const res = await axiosInstance(`${process.env.NEXT_PUBLIC_QSP_API_URL}`).post(`/api/user/userPwdChg`, {
|
||||
loginId,
|
||||
chgType: 'C',
|
||||
email,
|
||||
pwd,
|
||||
chgPwd,
|
||||
})
|
||||
console.log('🚀 ~ result ~ result:', result)
|
||||
|
||||
return NextResponse.json({ code: 200, data: result.data })
|
||||
// console.log('🚀 ~ qsp userPwdChg api response ~ response.data:', res.data)
|
||||
|
||||
if (res.data.result.resultCode !== 'S') {
|
||||
const errorMsg = res.data.result.resultMsg
|
||||
console.error(`비밀번호 변경 중 오류가 발생했습니다: ${errorMsg}`)
|
||||
return NextResponse.json({ error: `비밀번호 변경 중 오류가 발생했습니다: ${errorMsg}` }, { status: HttpStatusCode.InternalServerError })
|
||||
}
|
||||
|
||||
return NextResponse.json(res.data)
|
||||
}
|
||||
|
||||
export const POST = loggerWrapper(setChgPwd)
|
||||
|
||||
@ -11,8 +11,8 @@ export default function layout({ children }: PwResetLayoutProps) {
|
||||
<div className="sale-contents">
|
||||
<div className="border-frame">
|
||||
<div className="pw-guide">
|
||||
<div className="pw-guide-tit">パスワードをリセットする</div>
|
||||
<div className="pw-guide-txt">新しいパスワードを入力してください.</div>
|
||||
<div className="pw-guide-tit">パスワードリセット</div>
|
||||
<div className="pw-guide-txt">新しいパスワードを入力してください。</div>
|
||||
</div>
|
||||
</div>
|
||||
{children}
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { HttpStatusCode } from 'axios'
|
||||
|
||||
import { useLocalStorage } from 'usehooks-ts'
|
||||
|
||||
@ -21,33 +22,45 @@ export default function PwResetForm() {
|
||||
const [value, setValue, removeValue] = useLocalStorage<{ indivisualData: string }>('hanasysIndivisualState', { indivisualData: '' })
|
||||
|
||||
const validatePwd = () => {
|
||||
// 비밀번호 길이 체크 (8글자 이상)
|
||||
/* 비밀번호 입력 체크 */
|
||||
if (pwd01 === '') {
|
||||
alert('新しいパスワードの入力をお願いします。')
|
||||
return false
|
||||
}
|
||||
|
||||
/* 비밀번호 재입력 체크 */
|
||||
if (pwd02 === '') {
|
||||
alert('パスワードをもう一度入力してください。')
|
||||
return false
|
||||
}
|
||||
|
||||
/* 두 비밀번호 일치 체크 */
|
||||
if (pwd01 !== pwd02) {
|
||||
alert('パスワードが一致しません。')
|
||||
return false
|
||||
}
|
||||
|
||||
/* 비밀번호 길이 체크 (8글자 이상) */
|
||||
if (pwd01.length < 8) {
|
||||
alert('パスワードは8文字以上でなければなりません。')
|
||||
return false
|
||||
}
|
||||
|
||||
// 영문 대문자 포함 체크
|
||||
/* 영문 대문자 포함 체크 */
|
||||
if (!/[A-Z]/.test(pwd01)) {
|
||||
alert('パスワードに英大文字を含める必要があります。')
|
||||
return false
|
||||
}
|
||||
|
||||
// 영문 소문자 포함 체크
|
||||
/* 영문 소문자 포함 체크 */
|
||||
if (!/[a-z]/.test(pwd01)) {
|
||||
alert('パスワードに英語の小文字を含める必要があります。')
|
||||
return false
|
||||
}
|
||||
|
||||
// 숫자 포함 체크
|
||||
/* 숫자 포함 체크 */
|
||||
if (!/[0-9]/.test(pwd01)) {
|
||||
alert('비パスワードに数字を含める必要があります。')
|
||||
return false
|
||||
}
|
||||
|
||||
// 두 비밀번호 일치 체크
|
||||
if (pwd01 !== pwd02) {
|
||||
alert('パスワードが一致しません。')
|
||||
alert('パスワードに数字を含める必要があります。')
|
||||
return false
|
||||
}
|
||||
|
||||
@ -56,30 +69,39 @@ export default function PwResetForm() {
|
||||
|
||||
const handleReset = async () => {
|
||||
if (validatePwd()) {
|
||||
const { data } = await axiosInstance(null).post(`/api/auth/chg-pwd`, {
|
||||
const req: Record<string, string | null> = {
|
||||
loginId: session.userId,
|
||||
email: session.email,
|
||||
pwd: value.indivisualData,
|
||||
chgPwd: pwd01,
|
||||
})
|
||||
|
||||
if (data.data.result.resultCode === 'S') {
|
||||
setValue({ indivisualData: pwd01 })
|
||||
}
|
||||
|
||||
window.neoAlert(data.data.result.resultMsg, () => {
|
||||
const res = await axiosInstance(null).post(`/api/auth/chg-pwd`, req)
|
||||
|
||||
if (res.status !== HttpStatusCode.Ok) {
|
||||
// console.error(`パスワードの変更に失敗しました。: ${res.data.error}`)
|
||||
alert('パスワードの変更に失敗しました。')
|
||||
return
|
||||
} else {
|
||||
setValue({ indivisualData: pwd01 })
|
||||
alert('パスワードが変更されました。')
|
||||
router.back()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 파트너 강제 진입 방어 */
|
||||
useEffect(() => {
|
||||
if (session.isLoggedIn && session.role === 'Partner') router.back()
|
||||
}, [session.role, session.isLoggedIn, router])
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="border-frame">
|
||||
<div className="data-form-wrap">
|
||||
<div className="data-input-form-bx">
|
||||
<div className="data-input-form-tit">
|
||||
新規パスワード再入力 <i className="import">*</i>
|
||||
新しいパスワード入力 <i className="import">*</i>
|
||||
</div>
|
||||
<div className="data-input">
|
||||
<div className="login-input pw change">
|
||||
@ -94,11 +116,11 @@ export default function PwResetForm() {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="data-input-guide">10文字以内</div>
|
||||
{/* <div className="data-input-guide">※半角10文字以内</div> */}
|
||||
</div>
|
||||
<div className="data-input-form-bx">
|
||||
<div className="data-input-form-tit">
|
||||
新規パスワード入力 <i className="import">*</i>
|
||||
新しいパスワードを再入力 <i className="import">*</i>
|
||||
</div>
|
||||
<div className="data-input">
|
||||
<div className="login-input pw change">
|
||||
@ -113,18 +135,18 @@ export default function PwResetForm() {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="data-input-guide">10文字以内</div>
|
||||
{/* <div className="data-input-guide">※半角10文字以内</div> */}
|
||||
</div>
|
||||
</div>
|
||||
<div className="btn-flex-wrap">
|
||||
<div className="btn-bx">
|
||||
<button className="btn-frame n-blue icon" onClick={() => router.back()}>
|
||||
戻る<i className="btn-arr"></i>
|
||||
後ろへ<i className="btn-arr"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div className="btn-bx">
|
||||
<button className="btn-frame red icon" onClick={handleReset}>
|
||||
リセットする<i className="btn-arr"></i>
|
||||
再設定<i className="btn-arr"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user