front 로그인 작업 중 (2)
This commit is contained in:
@@ -27,7 +27,6 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class FrontDetailService implements UserDetailsService {
|
||||
|
||||
private final FindUserPortIn findUserPortIn;
|
||||
private final GetHouseholdPortIn getHouseholdPortIn;
|
||||
@Value("${app.front.password.validity.period.days}")
|
||||
private long passwordValidPeriodDays;
|
||||
@@ -40,24 +39,16 @@ public class FrontDetailService implements UserDetailsService {
|
||||
.operate(new GetHouseholdCmd(username))
|
||||
.orElseThrow(() -> new UsernameNotFoundException("Invalid username or password."));
|
||||
|
||||
FindUser findUser =
|
||||
findUserPortIn
|
||||
.operate(new FindUserCmd(username))
|
||||
.orElseThrow(() -> new UsernameNotFoundException("Invalid username or password."));
|
||||
|
||||
boolean accountLocked = Optional.ofNullable(findUser.getAccountLocked()).orElse(false);
|
||||
boolean accountDisabled = Optional.ofNullable(findUser.getAccountDisabled()).orElse(false);
|
||||
|
||||
return new FrontUser(
|
||||
findUser.getId(),
|
||||
findUser.getPassword(),
|
||||
!accountDisabled,
|
||||
return new FrontHouseholdUser(
|
||||
getHousehold.getHouseholdNum(),
|
||||
getHousehold.getPassword(),
|
||||
true,
|
||||
true,
|
||||
!accountLocked,
|
||||
getAuthorities(findUser.getRoles()),
|
||||
findUser.getNickname(),
|
||||
passwordValidPeriodDays - getDaysPassedFrom(findUser.getPasswordUpdatedAt()));
|
||||
true,
|
||||
true,
|
||||
getAuthorities(getHousehold.getRoles()),
|
||||
getHousehold.getOwnerName()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package app.module.front.config.application.security;
|
||||
|
||||
import java.util.Collection;
|
||||
import lombok.Getter;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
|
||||
@Getter
|
||||
public class FrontHouseholdUser extends User {
|
||||
|
||||
private String ownerName;
|
||||
|
||||
public FrontHouseholdUser(
|
||||
String householdNum,
|
||||
String password,
|
||||
boolean enabled,
|
||||
boolean accountNonExpired,
|
||||
boolean credentialsNonExpired,
|
||||
boolean accountNonLocked,
|
||||
Collection<? extends GrantedAuthority> authorities,
|
||||
String ownerName) {
|
||||
super(
|
||||
householdNum,
|
||||
password,
|
||||
enabled,
|
||||
accountNonExpired,
|
||||
credentialsNonExpired,
|
||||
accountNonLocked,
|
||||
authorities);
|
||||
this.ownerName = ownerName;
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,10 @@ public class FrontSecurityConfig {
|
||||
.rememberMe(
|
||||
remMe ->
|
||||
remMe
|
||||
.tokenValiditySeconds(1209600)
|
||||
// 자동 로그인 영구 유지 (로그아웃 시까지 유지)
|
||||
// Integer.MAX_VALUE ≒ 68년 유효
|
||||
// 단, 쿠키 삭제되면 무효됨
|
||||
.tokenValiditySeconds(Integer.MAX_VALUE)
|
||||
.userDetailsService(frontDetailService)
|
||||
.tokenRepository(persistentTokenRepository()))
|
||||
.logout(
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package app.module.front.usecase.household.updateFrontHousehold.adapters.web;
|
||||
|
||||
import app.module.core.usecase.household.updateFrontHousehold.ports.UpdateFrontHouseholdPortIn;
|
||||
import app.module.core.usecase.household.updateFrontHousehold.ports.application.domain.UpdateFrontHouseholdCmd;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import app.module.front.usecase.household.updateFrontHousehold.adapters.web.model.UpdateFrontHouseholdReqVO;
|
||||
import app.module.front.usecase.household.updateFrontHousehold.adapters.web.model.UpdateFrontHouseholdResVO;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class UpdateFrontHouseholdController {
|
||||
private final UpdateFrontHouseholdPortIn updateFrontHouseholdPortIn;
|
||||
|
||||
@PatchMapping(path = "/api/front/household/update")
|
||||
ResponseEntity<?> operate(
|
||||
@Valid UpdateFrontHouseholdReqVO reqVO, BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
.body(bindingResult);
|
||||
}
|
||||
|
||||
updateFrontHouseholdPortIn.operate(new UpdateFrontHouseholdCmd(
|
||||
reqVO.getId(),
|
||||
reqVO.getHouseholdNum(),
|
||||
reqVO.getOwnerName(),
|
||||
reqVO.getOwnerAge(),
|
||||
reqVO.getTel(),
|
||||
reqVO.getPhone(),
|
||||
reqVO.getRegion(),
|
||||
reqVO.getCity(),
|
||||
reqVO.getAddressDetail()
|
||||
));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(reqVO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package app.module.front.usecase.household.updateFrontHousehold.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class UpdateFrontHouseholdReqVO {
|
||||
private Long id;
|
||||
private String householdNum;
|
||||
private String ownerName;
|
||||
private Integer ownerAge;
|
||||
private String tel;
|
||||
private String phone;
|
||||
private String region;
|
||||
private String city;
|
||||
private String addressDetail;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.module.front.usecase.household.updateFrontHousehold.adapters.web.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class UpdateFrontHouseholdResVO {
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package app.module.front.usecase.user.updateUserUI.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 app.module.core.usecase.user.findUser.ports.FindUserPortIn;
|
||||
import app.module.core.usecase.user.findUser.ports.application.domain.FindUserCmd;
|
||||
import app.module.front.usecase.user.updateUserUI.adapters.web.model.UpdateUserUIReqVO;
|
||||
@@ -14,13 +16,13 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
@RequiredArgsConstructor
|
||||
class UpdateUserUIController {
|
||||
|
||||
private final FindUserPortIn findUserPortIn;
|
||||
private final GetHouseholdPortIn getHouseholdPortIn;
|
||||
|
||||
@GetMapping(path = "/user/info")
|
||||
String operate(Model model, @ModelAttribute("reqVO") UpdateUserUIReqVO reqVO) {
|
||||
|
||||
model.addAttribute("userInfo",
|
||||
findUserPortIn.operate(new FindUserCmd(CommonUtil.getLoginUsername())).orElseThrow());
|
||||
getHouseholdPortIn.operate(new GetHouseholdCmd(CommonUtil.getLoginUsername())).orElseThrow());
|
||||
|
||||
return "user/info";
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
<a href="/login">[로그인]</a>
|
||||
</p>
|
||||
<p sec:authorize="isAuthenticated()" th:remove="tag">
|
||||
<strong th:text="${#authentication.principal.nickname}">로그인 사용자명</strong>
|
||||
<strong th:text="${#authentication.principal.ownerName}">로그인 사용자명</strong>
|
||||
<a href="/logout">[로그아웃]</a>
|
||||
<a href="/user/info">[정보수정]</a>
|
||||
</p>
|
||||
|
||||
@@ -35,48 +35,47 @@
|
||||
method="get"
|
||||
name="reqForm"
|
||||
th:action="@{/user/info}" th:object="${userInfo}">
|
||||
<input type="hidden" name="id" th:value="*{id}">
|
||||
<div>
|
||||
<label class="form-label d-block" for="profileImgFile">프로필 이미지</label>
|
||||
<div class="input-group w-50">
|
||||
<input accept="image/*" class="form-control"
|
||||
id="profileImgFile"
|
||||
name="profileImgFile"
|
||||
onchange="uiUtil.uploadFile('PROFILE_IMG', this);"
|
||||
type="file">
|
||||
<div class="invalid-feedback field-profileImgFile">
|
||||
에러 메세지
|
||||
</div>
|
||||
</div>
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
<div>
|
||||
<label for="userId">아이디</label>
|
||||
<input id="userId" name="id" placeholder="아이디" readonly="readonly" th:field="*{id}"
|
||||
<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>
|
||||
<div>
|
||||
<label for="nickname">닉네임</label>
|
||||
<input id="nickname" name="nickname" placeholder="닉네임" th:field="*{nickname}" type="text">
|
||||
<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="userPwd">새 비밀번호</label>
|
||||
<input id="userPwd" name="password" placeholder="변경할 패스워드를 입력해주세요." th:field="*{password}"
|
||||
type="password">
|
||||
<div class="invalid-feedback field-password"></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="userPwdRe">새 비밀번호 재확인</label>
|
||||
<input id="userPwdRe" name="passwordRe" placeholder="변경할 패스워드를 재입력해주세요."
|
||||
type="password">
|
||||
<div class="invalid-feedback field-passwordRe"></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="userEmail">이메일</label>
|
||||
<input id="userEmail" name="email" placeholder="이메일을 입력해주세요." th:field="*{email}"
|
||||
type="text">
|
||||
<div class="invalid-feedback field-email"></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="*{addressDetail}" type="text">
|
||||
<div class="invalid-feedback field-id"></div>
|
||||
</div>
|
||||
</form>
|
||||
<button onclick="updateUser();">수정하기</button>
|
||||
@@ -94,7 +93,7 @@
|
||||
|
||||
$.ajax({
|
||||
method: 'PATCH',
|
||||
url: '/api/front/user/update',
|
||||
url: '/api/front/household/update',
|
||||
data: obj,
|
||||
beforeSend: function (xhr) {
|
||||
xhr.setRequestHeader(
|
||||
@@ -102,7 +101,7 @@
|
||||
$("meta[name='_csrf']").attr("content"));
|
||||
},
|
||||
success(res) {
|
||||
if (confirm(`'${res.id}' 정보가 수정되었습니다.`)) {
|
||||
if (confirm(`'${res.ownerName} 님의' 정보가 수정되었습니다.`)) {
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
@@ -121,21 +120,6 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<script th:inline="javascript">
|
||||
const showProfileImage = () => {
|
||||
const f = document.reqForm;
|
||||
const uploadFile = [[${userInfo.uploadFile}]];
|
||||
|
||||
if (uploadFile != null) {
|
||||
const input = $(f.profileImgFile);
|
||||
input.parent().append(
|
||||
`<input type="hidden" name="fileMappingId" value="${uploadFile.id}"/>`);
|
||||
uiUtil.showFileInfo(input, uploadFile, true);
|
||||
}
|
||||
}
|
||||
|
||||
showProfileImage();
|
||||
</script>
|
||||
</section>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user