diff --git a/build.gradle b/build.gradle index b23fe1c..9f4ab98 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,9 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + // thymeleaf implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.5.3' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-mail' diff --git a/src/main/java/gubun/financialledger/common/config/WebConfig.java b/src/main/java/gubun/financialledger/common/config/WebConfig.java index e4e1471..a36b7da 100644 --- a/src/main/java/gubun/financialledger/common/config/WebConfig.java +++ b/src/main/java/gubun/financialledger/common/config/WebConfig.java @@ -16,6 +16,8 @@ public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/menu/3").setViewName("index"); registry.addViewController("/menu/4").setViewName("index"); + registry.addViewController("/test").setViewName("test"); + //security registry.addViewController("/login").setViewName("login"); registry.addViewController("/register").setViewName("register"); diff --git a/src/main/java/gubun/financialledger/user/auth/PrincipalDetails.java b/src/main/java/gubun/financialledger/user/auth/PrincipalDetails.java index 21a9896..7dfab3e 100644 --- a/src/main/java/gubun/financialledger/user/auth/PrincipalDetails.java +++ b/src/main/java/gubun/financialledger/user/auth/PrincipalDetails.java @@ -50,6 +50,15 @@ public String getPassword() { return user.getPassword(); } + // 추가 + public String getProvider() { + return user.getProvider(); + } + + public String getEmail() { + return user.getEmail(); + } + @Override public String getUsername() { return user.getUsername(); diff --git a/src/main/java/gubun/financialledger/user/controller/LoginController.java b/src/main/java/gubun/financialledger/user/controller/LoginController.java new file mode 100644 index 0000000..2103d23 --- /dev/null +++ b/src/main/java/gubun/financialledger/user/controller/LoginController.java @@ -0,0 +1,20 @@ +package gubun.financialledger.user.controller; + +import gubun.financialledger.user.auth.PrincipalDetails; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.servlet.ModelAndView; + +@Controller +public class LoginController { + + // 메인페이지 로그인한 유저 정보 전달 + @GetMapping("/") + public ModelAndView currentUser(@AuthenticationPrincipal PrincipalDetails user) { + ModelAndView mv = new ModelAndView(); + mv.setViewName("index"); + mv.addObject("user", user); + return mv; + } +} diff --git a/src/main/java/gubun/financialledger/user/controller/ProfileController.java b/src/main/java/gubun/financialledger/user/controller/ProfileController.java new file mode 100644 index 0000000..6d45602 --- /dev/null +++ b/src/main/java/gubun/financialledger/user/controller/ProfileController.java @@ -0,0 +1,53 @@ +package gubun.financialledger.user.controller; + +import gubun.financialledger.user.auth.PrincipalDetails; +import gubun.financialledger.user.dto.IdInquiryForm; +import gubun.financialledger.user.dto.UserUpdateForm; +import gubun.financialledger.user.entity.User; +import gubun.financialledger.user.service.UserService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.stereotype.Controller; +import org.springframework.validation.BindingResult; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; + +import java.security.Principal; +import java.util.Optional; + +@Slf4j +@Controller +@RequestMapping("/profile") +@RequiredArgsConstructor +public class ProfileController { + + private final UserService userService; + + @GetMapping + public ModelAndView currentUser(@AuthenticationPrincipal PrincipalDetails user) { + ModelAndView mv = new ModelAndView(); + mv.setViewName("profile"); + mv.addObject("user", user); + return mv; + } + + @ResponseBody + @PutMapping("/users") + public String userUpdate( + @AuthenticationPrincipal PrincipalDetails user, + @Validated @ModelAttribute("form") UserUpdateForm form, BindingResult bindingResult + ) { + //구현중 + return "success"; + } + + @ResponseBody + @DeleteMapping("/users") + public String deleteUser( + @RequestBody String username) { + userService.deleteUser(username); + return "redirect:/"; + } +} diff --git a/src/main/java/gubun/financialledger/user/dto/UserUpdateForm.java b/src/main/java/gubun/financialledger/user/dto/UserUpdateForm.java new file mode 100644 index 0000000..31da99e --- /dev/null +++ b/src/main/java/gubun/financialledger/user/dto/UserUpdateForm.java @@ -0,0 +1,31 @@ +package gubun.financialledger.user.dto; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Pattern; + +@Data +public class UserUpdateForm { + + @NotBlank(message = "비밀번호를 작성해주세요.") + @Pattern( + regexp = "^.*(?=^.{8,15}$)(?=.*\\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&+=]).*$", + message = "비밀번호는 숫자, 문자, 특수문자 포함의 8~15자 이내로 작성해주세요." + ) + private String currentPassword; + + @NotBlank(message = "비밀번호를 작성해주세요.") + @Pattern( + regexp = "^.*(?=^.{8,15}$)(?=.*\\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&+=]).*$", + message = "비밀번호는 숫자, 문자, 특수문자 포함의 8~15자 이내로 작성해주세요." + ) + private String password; + + @NotBlank(message = "비밀번호를 작성해주세요.") + @Pattern( + regexp = "^.*(?=^.{8,15}$)(?=.*\\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&+=]).*$", + message = "비밀번호는 숫자, 문자, 특수문자 포함의 8~15자 이내로 작성해주세요." + ) + private String repeatPassword; +} diff --git a/src/main/java/gubun/financialledger/user/entity/User.java b/src/main/java/gubun/financialledger/user/entity/User.java index dee26d2..adb312d 100644 --- a/src/main/java/gubun/financialledger/user/entity/User.java +++ b/src/main/java/gubun/financialledger/user/entity/User.java @@ -54,4 +54,7 @@ public User(UserRole role, String email, String password, String username, Boole public void updatePassword(String password){ this.password = password; } + public void deleteUser(Boolean isDeleted){ + this.isDeleted = isDeleted; + } } diff --git a/src/main/java/gubun/financialledger/user/service/UserService.java b/src/main/java/gubun/financialledger/user/service/UserService.java index d315b87..e76b2b5 100644 --- a/src/main/java/gubun/financialledger/user/service/UserService.java +++ b/src/main/java/gubun/financialledger/user/service/UserService.java @@ -38,4 +38,15 @@ public Optional isValidatedUser(String username, String email){ public void updatePassword(User user, String password){ user.updatePassword(passwordEncoder.encode(password)); } + + @Transactional + public void deleteUser(String username) { + Optional user = userRepository.findByUsername(username); + if(user.isPresent()) { + User u = user.get(); + u.deleteUser(true); + userRepository.save(u); + } + // 탈퇴 시 logout 진행 + } } diff --git a/src/main/resources/static/images/default_logo.png b/src/main/resources/static/images/default_logo.png new file mode 100644 index 0000000..fd673db Binary files /dev/null and b/src/main/resources/static/images/default_logo.png differ diff --git a/src/main/resources/static/images/google_logo.png b/src/main/resources/static/images/google_logo.png new file mode 100644 index 0000000..25e20ab Binary files /dev/null and b/src/main/resources/static/images/google_logo.png differ diff --git a/src/main/resources/static/images/kakao_logo.png b/src/main/resources/static/images/kakao_logo.png new file mode 100644 index 0000000..43889bf Binary files /dev/null and b/src/main/resources/static/images/kakao_logo.png differ diff --git a/src/main/resources/static/js/subpages/userProfile.js b/src/main/resources/static/js/subpages/userProfile.js new file mode 100644 index 0000000..b016067 --- /dev/null +++ b/src/main/resources/static/js/subpages/userProfile.js @@ -0,0 +1,62 @@ +function changePassword(){ + $("#userUpdateBtn").show(); + $("#cancelBtn").show(); + $("#changePasswordBtn").hide(); + $("#deleteUserBtn").hide(); + $("#pw0").show(); + $("#pw1").show(); + $("#pw2").show(); +} + +function cancelUpdate(){ + $("#userUpdateBtn").hide(); + $("#cancelBtn").hide(); + $("#changePasswordBtn").show(); + $("#deleteUserBtn").show(); + $("#pw0").hide(); + $("#pw1").hide(); + $("#pw2").hide(); +} + +function deleteUser(){ + console.log("deleteUser"); + $.ajax({ + url: "/profile/users", + dataType: "json", + contentType: "application/json; charset=UTF-8", + type: "DELETE", + data: $("#inputUsername").val(), + beforeSend: function (jqXHR, settings) { + //CSRF 해결 + let header = $("meta[name='_csrf_header']").attr("content"); + let token = $("meta[name='_csrf']").attr("content"); + jqXHR.setRequestHeader(header, token); + }, + done: function (data) { + console.log(data); + if(data === "success"){ + alert("회원탈퇴에 성공하였습니다."); + } else { + alert("회원탈퇴에 실패하였습니다."); + } + }, + + }); +} + +function userUpdate(){ + console.log("userUpdate"); + + // [Step1] : userUpdateValidation + let inputPassword = $("inputPassword").val() + let inputPasswordCheck = $("inputPasswordCheck").val(); + + //새 비밀번호 검증 check 검증 -> Spring Valid로 하도록 변경 + // if (inputPassword != inputPasswordCheck) { + // + // alert("새 비밀번호가 일치 하지 않습니다."); + // return; + // } + //구현중.. +} + diff --git a/src/main/resources/templates/fragments/config.html b/src/main/resources/templates/fragments/config.html new file mode 100644 index 0000000..6f9511e --- /dev/null +++ b/src/main/resources/templates/fragments/config.html @@ -0,0 +1,29 @@ + + + + + + + + + + 가계부 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/fragments/footer.html b/src/main/resources/templates/fragments/footer.html new file mode 100644 index 0000000..1066f5b --- /dev/null +++ b/src/main/resources/templates/fragments/footer.html @@ -0,0 +1,12 @@ + + +
+
+
+ +
+
+
+ \ No newline at end of file diff --git a/src/main/resources/templates/fragments/logoutModal.html b/src/main/resources/templates/fragments/logoutModal.html new file mode 100644 index 0000000..69bd09f --- /dev/null +++ b/src/main/resources/templates/fragments/logoutModal.html @@ -0,0 +1,21 @@ + + + + \ No newline at end of file diff --git a/src/main/resources/templates/fragments/sidebar.html b/src/main/resources/templates/fragments/sidebar.html new file mode 100644 index 0000000..41b9503 --- /dev/null +++ b/src/main/resources/templates/fragments/sidebar.html @@ -0,0 +1,106 @@ + + +
+ + + +
+ diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index b14e2cb..89ddbff 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -1,8 +1,8 @@ @@ -27,512 +27,469 @@ - -
- - - + - -
- -
+ + + + - -
+ +
+ - - - - -
- -
-

가계부

- 보고서 출력 -
- -
- -
-
-
-
-
-
- 이번달 수입
-
$40,000
-
-
- -
+ + + 설정 + + + + + 로그아웃 + +
+ + + + + +
+ +
+

가계부

+ 보고서 출력 +
+ +
+ +
+
+
+
+
+
+ 이번달 수입
+
$40,000
+
+
+
- -
-
-
-
-
-
- 이번달 지출
-
$215,000
-
-
- -
+
+ +
+
+
+
+
+
+ 이번달 지출
+
$215,000
+
+
+
- -
-
-
-
-
-
예산 +
+ +
+
+
+
+
+
예산 +
+
+
+
50%
-
-
-
50%
-
-
-
-
-
+
+
+
-
- -
+
+
+
- -
-
-
-
-
-
- 하루일기
-
1
-
-
- -
+
+ +
+
+
+
+
+
+ 하루일기
+
1
+
+
+
- -
- -
-
- -
+ +
+ +
+
+ +
-
지출 요약
- - -
-
- -
+ +
+
+ +
-
수입 요약
-
- - -
-
-
-
- + + +
+
+ +
+
+ +
+
- -
- - - - - + + + + + - -