사용자 비밀번호 확인 추가.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package app.module.front.config.application.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ApiResponse<T> {
|
||||
private String code;
|
||||
private String message;
|
||||
|
||||
@@ -18,6 +18,9 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@@ -31,16 +34,16 @@ class GetUserPasswordController {
|
||||
private final GetHouseholdPortIn getHouseholdPortIn;
|
||||
|
||||
@PostMapping(path = "/api/front/info/user/password/auth")
|
||||
ResponseEntity<?> operate(@Valid GetUserPasswordReqVO reqVO, BindingResult bindingResult){
|
||||
ResponseEntity<?> operate(@RequestBody @Valid GetUserPasswordReqVO reqVO, BindingResult bindingResult){
|
||||
if (bindingResult.hasErrors()) {
|
||||
return coreUtil.getErrorInfo(bindingResult);
|
||||
}
|
||||
GetHousehold user = getHouseholdPortIn.operate(new GetHouseholdCmd(CommonUtil.getLoginUsername())).orElseThrow();
|
||||
|
||||
if (!passwordEncoder.matches(reqVO.getPassword(), user.getPassword())) {
|
||||
return ResponseEntity.status(HttpStatus.OK).body(ApiResponse.failure("INVALID_PASSWORD"));
|
||||
return ResponseEntity.ok(ApiResponse.failure("INVALID_PASSWORD"));
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(ApiResponse.success(null));
|
||||
return ResponseEntity.ok(ApiResponse.success(null));
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,14 @@ package app.module.front.usecase.info.user.getUserPasswordUI.adapters.web.model;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Data
|
||||
@NoArgsConstructor // 기본 생성자 자동 추가
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class GetUserPasswordReqVO {
|
||||
|
||||
@NotNull(message = "비밀번호는 필수 입력값입니다.")
|
||||
@Pattern(regexp = "\\d{6}", message = "비밀번호는 숫자 6자리여야 합니다.")
|
||||
@Pattern(regexp = "\\d{4}", message = "비밀번호는 숫자 4자리여야 합니다.")
|
||||
private String password;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,13 @@ package app.module.front.usecase.info.user.getUserUI.adapters.web;
|
||||
import app.module.core.config.application.util.CommonUtil;
|
||||
import app.module.core.usecase.household.getHousehold.ports.GetHouseholdPortIn;
|
||||
import app.module.core.usecase.household.getHousehold.ports.application.domain.GetHouseholdCmd;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@@ -15,7 +18,12 @@ class GetUserUIController {
|
||||
private final GetHouseholdPortIn getHouseholdPortIn;
|
||||
|
||||
@GetMapping(path = "/info/user")
|
||||
String operate(Model model) {
|
||||
String operate(Model model, HttpServletRequest request) {
|
||||
|
||||
String referer = request.getHeader("Referer");
|
||||
if (referer == null || !referer.contains("/info/user/password")) {
|
||||
return "redirect:/"; // 요청 처리 중단
|
||||
}
|
||||
|
||||
model.addAttribute("userInfo",
|
||||
getHouseholdPortIn.operate(new GetHouseholdCmd(CommonUtil.getLoginUsername())).orElseThrow());
|
||||
|
||||
@@ -16,24 +16,22 @@
|
||||
|
||||
<section class="form-group">
|
||||
<form method="post" name="reqForm" id="reqForm" onsubmit="formControl.authInfoUser();" th:action="@{/}" >
|
||||
|
||||
<div class="component-input" data-props-toggle-Password="true">
|
||||
<div class="input-label">
|
||||
<label for="temp_input_0001" class="label-txt">
|
||||
비밀번호
|
||||
</label>
|
||||
<div class="component-input" data-props-toggle-Password="true">
|
||||
<div class="input-label">
|
||||
<label for="password" class="label-txt">비밀번호</label>
|
||||
</div>
|
||||
<div class="input-field">
|
||||
<input type="password" id="password" placeholder="비밀번호 4자리를 입력해 주세요" name="password">
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-field">
|
||||
<input type="password" id="temp_input_0001" placeholder="비밀번호 4자리를 입력해 주세요" name="password">
|
||||
<div class="component-btns">
|
||||
<div class="btns-row">
|
||||
<button type="button" class="btn btn-full btn-l btn-primary" onclick="formControl.authInfoUser()">
|
||||
<span class="btn-txt">다음</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="component-btns">
|
||||
<div class="btns-row">
|
||||
<button type="button" class="btn btn-full btn-l btn-primary" onclick="formControl.authInfoUser()">
|
||||
<span class="btn-txt">다음</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
@@ -44,8 +42,9 @@
|
||||
<script th:inline="javascript">
|
||||
let ENV = {
|
||||
httpUrl: {
|
||||
root: /*[[#{uri.front.info.user.path}]]*/'rootUrl',
|
||||
root: /*[[|#{uri.front.info.user.path}/password|]]*/'rootUrl',
|
||||
auth: /*[[|/api/front#{uri.front.info.user.path}/password/auth|]]*/'passwordAuthUrl',
|
||||
user: /*[[#{uri.front.info.user.path}]]*/'userUrl',
|
||||
|
||||
},
|
||||
submitted: false,
|
||||
@@ -56,11 +55,20 @@
|
||||
const f = document.reqForm;
|
||||
|
||||
const obj = $(f).serializeObject();
|
||||
console.log(obj)
|
||||
ajaxUtil._ajaxAsync(
|
||||
ENV.httpUrl.auth,
|
||||
obj,
|
||||
function (rstData, status) {
|
||||
console.log(rstData.status)
|
||||
if(rstData.code ==='SUCCESS'){
|
||||
location.href = ENV.httpUrl.user;
|
||||
} else if (rstData.code === 'ERROR'){
|
||||
if(rstData.message ==='INVALID_PASSWORD'){
|
||||
ajaxUtil._alert('비밀번호가 일치하지 않습니다.', '비밀번호 확인');
|
||||
} else {
|
||||
ajaxUtil._alert('잠시 뒤에 다시 시도해 주세요.', '비밀번호 확인');
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,129 +2,243 @@
|
||||
<html layout:decorate="~{layout/layout}" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<div layout:fragment="content">
|
||||
<main id="content" role="main">
|
||||
|
||||
<style>
|
||||
label {
|
||||
display: inline-block;
|
||||
width: 150px;
|
||||
}
|
||||
<div layout:fragment="content" th:classappend="'mypage-wrap'">
|
||||
<main id="content" role="main">
|
||||
<div class="inner">
|
||||
|
||||
div {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
<p class="form-desc">필수입력</p>
|
||||
|
||||
.invalid-feedback {
|
||||
display: none;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
}
|
||||
<section class="form-group">
|
||||
<!-- 이름 -->
|
||||
<div class="component-input">
|
||||
<div class="input-label">
|
||||
<label for="temp_input_0001" class="label-txt">
|
||||
이름<i class="ico-required-mark" role="img" aria-label="필수">*</i>
|
||||
</label>
|
||||
</div>
|
||||
<div class="input-field">
|
||||
<input type="text" id="temp_input_0001" placeholder="이름을 입력해 주세요">
|
||||
</div>
|
||||
</div>
|
||||
<!-- 연령 -->
|
||||
<div class="component-input">
|
||||
<div class="input-label">
|
||||
<label for="temp_input_0002" class="label-txt">
|
||||
연령<span>(만 나이)</span> <i class="ico-required-mark" role="img" aria-label="필수">*</i>
|
||||
</label>
|
||||
</div>
|
||||
<div class="input-field">
|
||||
<input type="number" id="temp_input_0002" placeholder="만 나이를 입력해 주세요">
|
||||
</div>
|
||||
</div>
|
||||
<!-- 가구연락처 -->
|
||||
<div class="input-flex-group type-num">
|
||||
<div class="input-label">
|
||||
<label for="temp_input_00012" class="label-txt">
|
||||
가구 연락처
|
||||
</label>
|
||||
</div>
|
||||
<div class="d-flex">
|
||||
<div class="select-group">
|
||||
<div id="temp_input_00012" class="component-select bottom-sheet" data-props-default="선택" data-props-type="bottomSheet">
|
||||
<button type="button" class="select-box">
|
||||
<span class="select-txt"></span>
|
||||
</button>
|
||||
<div class="select-options">
|
||||
<div class="select-header">
|
||||
<p>가구 연락처</p>
|
||||
<button type="button" class="select-close">
|
||||
<span class="hide-txt">닫기</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="select-scroll">
|
||||
<ul class="">
|
||||
<li class="option" data-value="option1">option1</li>
|
||||
<li class="option" data-value="option2">option2</li>
|
||||
<li class="option" data-value="option3">option3</li>
|
||||
<li class="option" data-value="option4">option4</li>
|
||||
<li class="option" data-value="option5">option5</li>
|
||||
<li class="option" data-value="option6">option6</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="component-input">
|
||||
<div class="input-field">
|
||||
<input type="number" id="temp_input_0003" placeholder=0000>
|
||||
</div>
|
||||
</div>
|
||||
<div class="component-input">
|
||||
<div class="input-field">
|
||||
<input type="number" id="temp_input_0004" placeholder=0000>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 휴대폰 번호 -->
|
||||
<div class="input-flex-group type-num">
|
||||
<div class="input-label">
|
||||
<label for="temp_input_0005" class="label-txt">
|
||||
휴대폰 번호 <i class="ico-required-mark" role="img" aria-label="필수">*</i>
|
||||
</label>
|
||||
</div>
|
||||
<div class="d-flex">
|
||||
<div class="select-group">
|
||||
<div id="temp_input_0005" class="component-select bottom-sheet" data-props-default="선택" data-props-type="bottomSheet">
|
||||
<button type="button" class="select-box">
|
||||
<span class="select-txt"></span>
|
||||
</button>
|
||||
<div class="select-options">
|
||||
<div class="select-header">
|
||||
<p>휴대폰 번호</p>
|
||||
<button type="button" class="select-close">
|
||||
<span class="hide-txt">닫기</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="select-scroll">
|
||||
<ul class="">
|
||||
<li class="option" data-value="option1">option1</li>
|
||||
<li class="option" data-value="option2">option2</li>
|
||||
<li class="option" data-value="option3">option3</li>
|
||||
<li class="option" data-value="option4">option4</li>
|
||||
<li class="option" data-value="option5">option5</li>
|
||||
<li class="option" data-value="option6">option6</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="component-input">
|
||||
<div class="input-field">
|
||||
<input type="number" id="temp_input_0006" placeholder=0000>
|
||||
</div>
|
||||
</div>
|
||||
<div class="component-input">
|
||||
<div class="input-field">
|
||||
<input type="number" id="temp_input_0007" placeholder=0000>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 도로명 주소 -->
|
||||
<div class="input-col-group">
|
||||
<div class="select-group">
|
||||
<div class="select-label">
|
||||
<p class="label-txt">
|
||||
도로명 주소
|
||||
<i class="ico-required-mark" role="img" aria-label="필수">*</i>
|
||||
</p>
|
||||
</div>
|
||||
<div id="select213" class="component-select bottom-sheet" data-props-default="시/도 선택" data-props-type="bottomSheet">
|
||||
<button type="button" class="select-box">
|
||||
<span class="select-txt">선택</span>
|
||||
</button>
|
||||
<div class="select-options">
|
||||
<div class="select-header">
|
||||
<p>시/도 선택</p>
|
||||
<button type="button" class="select-close">
|
||||
<span class="hide-txt">닫기</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="select-scroll">
|
||||
<ul class="">
|
||||
<li class="option" data-value="option1">option1</li>
|
||||
<li class="option" data-value="option2">option2</li>
|
||||
<li class="option" data-value="option3">option3</li>
|
||||
<li class="option" data-value="option4">option4</li>
|
||||
<li class="option" data-value="option5">option5</li>
|
||||
<li class="option" data-value="option6">option6</li>
|
||||
<li class="option" data-value="option7">option7</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="select-group">
|
||||
<div id="select3" class="component-select bottom-sheet" data-props-default="시/군/구 선택" data-props-type="bottomSheet">
|
||||
<button type="button" class="select-box">
|
||||
<span class="select-txt">선택</span>
|
||||
</button>
|
||||
<div class="select-options">
|
||||
<div class="select-header">
|
||||
<p>시/군/구 선택</p>
|
||||
<button type="button" class="select-close">
|
||||
<span class="hide-txt">닫기</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="select-scroll">
|
||||
<ul class="">
|
||||
<li class="option" data-value="option1">option1</li>
|
||||
<li class="option" data-value="option2">option2</li>
|
||||
<li class="option" data-value="option3">option3</li>
|
||||
<li class="option" data-value="option4">option4</li>
|
||||
<li class="option" data-value="option5">option5</li>
|
||||
<li class="option" data-value="option6">option6</li>
|
||||
<li class="option" data-value="option7">option7</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="component-input">
|
||||
<div class="input-field">
|
||||
<input type="text" id="temp_input_00023" placeholder="세부 주소를 입력해 주세요">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
.is-invalid + .invalid-feedback {
|
||||
display: block;
|
||||
}
|
||||
|
||||
input[readonly] {
|
||||
background-color: #e9ecef;
|
||||
color: #6c757d;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div>
|
||||
<form
|
||||
method="get"
|
||||
name="reqForm"
|
||||
th:action="@{/user/info}" th:object="${userInfo}">
|
||||
|
||||
<input type="hidden" name="id" th:value="*{seq}">
|
||||
|
||||
<div>
|
||||
<label for="householdNum">임가번호</label>
|
||||
<input id="householdNum" name="householdNum" placeholder="아이디" readonly="readonly" th:field="*{householdNum}"
|
||||
type="text">
|
||||
<div class="invalid-feedback field-id"></div>
|
||||
<div class="component-btns">
|
||||
<div class="btns-row">
|
||||
<button type="button" class="btn btn-full btn-l btn-primary">
|
||||
<span class="btn-txt">변경</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label for="ownerName">경영주</label>
|
||||
<input id="ownerName" name="ownerName" placeholder="경영주 이름" th:field="*{ownerName}" type="text">
|
||||
<div class="invalid-feedback field-id"></div>
|
||||
</div>
|
||||
<div>
|
||||
<label for="ownerAge">만나이</label>
|
||||
<input id="ownerAge" name="ownerAge" placeholder="나이" th:field="*{ownerAge}" type="text">
|
||||
<div class="invalid-feedback field-id"></div>
|
||||
</div>
|
||||
<div>
|
||||
<label for="tel">가구연락처</label>
|
||||
<input id="tel" name="tel" placeholder="가구연락처" th:field="*{tel}" type="text">
|
||||
<div class="invalid-feedback field-id"></div>
|
||||
</div>
|
||||
<div>
|
||||
<label for="phone">핸드폰번호</label>
|
||||
<input id="phone" name="phone" placeholder="핸드폰번호" th:field="*{phone}" type="text">
|
||||
<div class="invalid-feedback field-id"></div>
|
||||
</div>
|
||||
<!-- <div>-->
|
||||
<!-- <label for="region">시.도</label>-->
|
||||
<!-- <input id="region" name="region" placeholder="시.도" th:field="*{region}" type="text">-->
|
||||
<!-- <div class="invalid-feedback field-id"></div>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div>-->
|
||||
<!-- <label for="city">시.군.도</label>-->
|
||||
<!-- <input id="city" name="city" placeholder="시.군.도" th:field="*{city}" type="text">-->
|
||||
<!-- <div class="invalid-feedback field-id"></div>-->
|
||||
<!-- </div>-->
|
||||
<div>
|
||||
<label for="addressDetail">전체 주소</label>
|
||||
<input id="addressDetail" name="addressDetail" placeholder="세부 주소" th:field="*{address}" type="text">
|
||||
<div class="invalid-feedback field-id"></div>
|
||||
</div>
|
||||
</form>
|
||||
<button onclick="updateUser();">수정하기</button>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<section layout:fragment="script">
|
||||
<script>
|
||||
const updateUser = () => {
|
||||
const f = document.reqForm;
|
||||
const obj = $(f).serializeObject();
|
||||
<script th:inline="javascript">
|
||||
let ENV = {
|
||||
httpUrl: {
|
||||
root: /*[[|#{uri.front.info.user.path}/password|]]*/'rootUrl',
|
||||
auth: /*[[|/api/front#{uri.front.info.user.path}/password/auth|]]*/'passwordAuthUrl',
|
||||
user: /*[[#{uri.front.info.user.path}]]*/'userUrl',
|
||||
|
||||
// 기존 에러 메세지 초기화
|
||||
$('.is-invalid').removeClass('is-invalid');
|
||||
},
|
||||
submitted: false,
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
method: 'PATCH',
|
||||
url: '/api/front/household/update',
|
||||
data: obj,
|
||||
beforeSend: function (xhr) {
|
||||
xhr.setRequestHeader(
|
||||
$("meta[name='_csrf_header']").attr("content"),
|
||||
$("meta[name='_csrf']").attr("content"));
|
||||
},
|
||||
success(res) {
|
||||
if (confirm(`'${res.ownerName} 님의' 정보가 수정되었습니다.`)) {
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
statusCode: {
|
||||
'422': (res) => {
|
||||
const fieldErrors = res.responseJSON.fieldErrors;
|
||||
$(fieldErrors).each(function (idx, error) {
|
||||
let target = $(f).find('[name=' + error.field + ']');
|
||||
target.addClass('is-invalid');
|
||||
let formControl = {
|
||||
authInfoUser() {
|
||||
const f = document.reqForm;
|
||||
|
||||
target.parent().find('.invalid-feedback').text(error.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
const obj = $(f).serializeObject();
|
||||
console.log(obj)
|
||||
ajaxUtil._ajaxAsync(
|
||||
ENV.httpUrl.auth,
|
||||
obj,
|
||||
function (rstData, status) {
|
||||
if(rstData.code ==='SUCCESS'){
|
||||
location.href = ENV.httpUrl.user;
|
||||
} else if (rstData.code === 'ERROR'){
|
||||
if(rstData.message ==='INVALID_PASSWORD'){
|
||||
ajaxUtil._alert('비밀번호가 일치하지 않습니다.', '비밀번호 확인');
|
||||
} else {
|
||||
ajaxUtil._alert('잠시 뒤에 다시 시도해 주세요.', '비밀번호 확인');
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user