From 53ab6b2ad770269deef3a4976cac065a1635ec5e Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 13:24:53 +0900 Subject: [PATCH 01/26] =?UTF-8?q?[chore]=20#10=20=EC=8B=9C=ED=81=90?= =?UTF-8?q?=EB=A6=AC=ED=8B=B0=20passwordEncoder=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../checkmate/global/config/auth/SecurityConfig.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java b/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java index 8f3c23b..9ddb99e 100644 --- a/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java +++ b/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java @@ -12,6 +12,8 @@ import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; @@ -47,4 +49,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .addFilterBefore(new ExceptionHandlerFilter(), JwtAuthenticationFilter.class) .build(); } + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } } \ No newline at end of file From 605162d15f812e1fd13e8f851b488cfcdd3ade41 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 15:05:22 +0900 Subject: [PATCH 02/26] =?UTF-8?q?[rename]=20#10=20RoomTypeConverter?= =?UTF-8?q?=EB=A5=BC=20Post=20=EB=8F=84=EB=A9=94=EC=9D=B8=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/gachon/checkmate/domain/member/entity/User.java | 2 +- .../domain/{member => post}/converter/RoomTypeConverter.java | 2 +- src/main/java/org/gachon/checkmate/domain/post/entity/Post.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/main/java/org/gachon/checkmate/domain/{member => post}/converter/RoomTypeConverter.java (86%) diff --git a/src/main/java/org/gachon/checkmate/domain/member/entity/User.java b/src/main/java/org/gachon/checkmate/domain/member/entity/User.java index 48a8d22..00678da 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/entity/User.java +++ b/src/main/java/org/gachon/checkmate/domain/member/entity/User.java @@ -5,7 +5,7 @@ import org.gachon.checkmate.domain.checkList.entity.CheckList; import org.gachon.checkmate.domain.member.converter.GenderTypeConverter; import org.gachon.checkmate.domain.member.converter.MbtiTypeConverter; -import org.gachon.checkmate.domain.member.converter.RoomTypeConverter; +import org.gachon.checkmate.domain.post.converter.RoomTypeConverter; import org.gachon.checkmate.domain.post.entity.Post; import org.gachon.checkmate.domain.scrap.entity.Scrap; import org.gachon.checkmate.global.common.BaseTimeEntity; diff --git a/src/main/java/org/gachon/checkmate/domain/member/converter/RoomTypeConverter.java b/src/main/java/org/gachon/checkmate/domain/post/converter/RoomTypeConverter.java similarity index 86% rename from src/main/java/org/gachon/checkmate/domain/member/converter/RoomTypeConverter.java rename to src/main/java/org/gachon/checkmate/domain/post/converter/RoomTypeConverter.java index c0ea666..4ad05df 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/converter/RoomTypeConverter.java +++ b/src/main/java/org/gachon/checkmate/domain/post/converter/RoomTypeConverter.java @@ -1,4 +1,4 @@ -package org.gachon.checkmate.domain.member.converter; +package org.gachon.checkmate.domain.post.converter; import jakarta.persistence.Converter; import org.gachon.checkmate.domain.member.entity.RoomType; diff --git a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java index f932a4b..02fc850 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java +++ b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java @@ -3,7 +3,7 @@ import jakarta.persistence.*; import lombok.*; import org.gachon.checkmate.domain.checkList.entity.PostCheckList; -import org.gachon.checkmate.domain.member.converter.RoomTypeConverter; +import org.gachon.checkmate.domain.post.converter.RoomTypeConverter; import org.gachon.checkmate.domain.member.entity.RoomType; import org.gachon.checkmate.domain.member.entity.User; import org.gachon.checkmate.domain.post.converter.ImportantKeyTypeConverter; From cfbc476c86405a0e0364311a00ea65b931673137 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 15:06:13 +0900 Subject: [PATCH 03/26] =?UTF-8?q?[remove]=20#10=20Member=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=EC=97=90=20RoomTypeConverter=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/gachon/checkmate/domain/member/entity/User.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/member/entity/User.java b/src/main/java/org/gachon/checkmate/domain/member/entity/User.java index 00678da..99f8c76 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/entity/User.java +++ b/src/main/java/org/gachon/checkmate/domain/member/entity/User.java @@ -30,8 +30,6 @@ public class User extends BaseTimeEntity { private String profile; private String school; private String major; - @Convert(converter = RoomTypeConverter.class) - private RoomType roomType; @Convert(converter = MbtiTypeConverter.class) private MbtiType mbtiType; @Convert(converter = GenderTypeConverter.class) From 1f30e8aa21394e684de2aa950a915f62c66e1036 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 17:58:18 +0900 Subject: [PATCH 04/26] =?UTF-8?q?[rename]=20#10=20RoomType=EC=9D=84=20Memb?= =?UTF-8?q?er=20=EB=8F=84=EB=A9=94=EC=9D=B8=EC=9C=BC=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../checkmate/domain/{member => post}/entity/RoomType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/org/gachon/checkmate/domain/{member => post}/entity/RoomType.java (87%) diff --git a/src/main/java/org/gachon/checkmate/domain/member/entity/RoomType.java b/src/main/java/org/gachon/checkmate/domain/post/entity/RoomType.java similarity index 87% rename from src/main/java/org/gachon/checkmate/domain/member/entity/RoomType.java rename to src/main/java/org/gachon/checkmate/domain/post/entity/RoomType.java index 6e9763a..34c7c30 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/entity/RoomType.java +++ b/src/main/java/org/gachon/checkmate/domain/post/entity/RoomType.java @@ -1,4 +1,4 @@ -package org.gachon.checkmate.domain.member.entity; +package org.gachon.checkmate.domain.post.entity; import lombok.AccessLevel; import lombok.AllArgsConstructor; From c6632ab93fa304b3d9e6d39a2771fdb5fcc3f541 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 17:59:09 +0900 Subject: [PATCH 05/26] =?UTF-8?q?[rename]=20#10=20RoomType/Converter?= =?UTF-8?q?=EB=A5=BC=20Post=20=EB=8F=84=EB=A9=94=EC=9D=B8=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../checkmate/domain/post/converter/RoomTypeConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gachon/checkmate/domain/post/converter/RoomTypeConverter.java b/src/main/java/org/gachon/checkmate/domain/post/converter/RoomTypeConverter.java index 4ad05df..cf9c7ed 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/converter/RoomTypeConverter.java +++ b/src/main/java/org/gachon/checkmate/domain/post/converter/RoomTypeConverter.java @@ -1,7 +1,7 @@ package org.gachon.checkmate.domain.post.converter; import jakarta.persistence.Converter; -import org.gachon.checkmate.domain.member.entity.RoomType; +import org.gachon.checkmate.domain.post.entity.RoomType; import org.gachon.checkmate.global.utils.AbstractEnumCodeAttributeConverter; @Converter From d2228eb90f0a94912ae708d9bf0b7a32fec03b22 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 17:59:50 +0900 Subject: [PATCH 06/26] =?UTF-8?q?[chore]=20#10=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20URL=20webSecurityCustomizer=EC=97=90=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/gachon/checkmate/global/config/auth/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java b/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java index 9ddb99e..19766d8 100644 --- a/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java +++ b/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java @@ -25,7 +25,7 @@ public class SecurityConfig { private final CorsConfig corsConfig; private final JwtProvider jwtProvider; - private static final String[] whiteList = {"/", "api/member/email"}; + private static final String[] whiteList = {"/", "api/member/email", "api/member/signup"}; @Bean public WebSecurityCustomizer webSecurityCustomizer() { From 380e2a411a46a43b22f3bfca0f2b093f66e59762 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 18:00:49 +0900 Subject: [PATCH 07/26] =?UTF-8?q?[feat]=20#10=20User=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=EC=97=90=20=EB=B9=8C=EB=8D=94=EB=A1=9C=20createUser?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gachon/checkmate/domain/member/entity/User.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/member/entity/User.java b/src/main/java/org/gachon/checkmate/domain/member/entity/User.java index 99f8c76..6983f05 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/entity/User.java +++ b/src/main/java/org/gachon/checkmate/domain/member/entity/User.java @@ -42,4 +42,17 @@ public class User extends BaseTimeEntity { @OneToMany(mappedBy = "user") @Builder.Default private List scrapList = new ArrayList<>(); + + public static User createUser(String email, String storedPassword, String name, String school, String major, MbtiType mbti, GenderType gender){ + return User.builder() + .email(email) + .password(storedPassword) + .name(name) + .profile(ProfileImageType.PROFILE_1.getImageUrl()) + .school(school) + .major(major) + .mbtiType(mbti) + .gender(gender) + .build(); + } } From dd6d30dafa023301a8597f3aa683da6c2c1c601f Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 18:01:02 +0900 Subject: [PATCH 08/26] =?UTF-8?q?[feat]=20#10=20UserRepository=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/repository/UserRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/member/repository/UserRepository.java diff --git a/src/main/java/org/gachon/checkmate/domain/member/repository/UserRepository.java b/src/main/java/org/gachon/checkmate/domain/member/repository/UserRepository.java new file mode 100644 index 0000000..64c78a6 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/member/repository/UserRepository.java @@ -0,0 +1,8 @@ +package org.gachon.checkmate.domain.member.repository; + +import org.gachon.checkmate.domain.member.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserRepository extends JpaRepository { + +} From 7fe6cabe599ecd5c15fd0a86e52eafe1736ddf11 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 18:01:23 +0900 Subject: [PATCH 09/26] =?UTF-8?q?[feat]=20#10=20ProfileImageType=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/entity/ProfileImageType.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/member/entity/ProfileImageType.java diff --git a/src/main/java/org/gachon/checkmate/domain/member/entity/ProfileImageType.java b/src/main/java/org/gachon/checkmate/domain/member/entity/ProfileImageType.java new file mode 100644 index 0000000..052524c --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/member/entity/ProfileImageType.java @@ -0,0 +1,16 @@ +package org.gachon.checkmate.domain.member.entity; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +public enum ProfileImageType { + + PROFILE_1("https://checkmate-dormitory-bucket.s3.ap-northeast-2.amazonaws.com/checkmate-profile1.png"), + PROFILE_2("https://example.com/profile2.jpg"), + PROFILE_3("https://example.com/profile3.jpg"); + + private final String imageUrl; +} From b8f39837a2627906e35689fec8e52fbbf5ca101b Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 18:01:42 +0900 Subject: [PATCH 10/26] =?UTF-8?q?[feat]=20#10=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20request=20dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/MemberSignUpRequestDto.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/member/dto/request/MemberSignUpRequestDto.java diff --git a/src/main/java/org/gachon/checkmate/domain/member/dto/request/MemberSignUpRequestDto.java b/src/main/java/org/gachon/checkmate/domain/member/dto/request/MemberSignUpRequestDto.java new file mode 100644 index 0000000..9df7b54 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/member/dto/request/MemberSignUpRequestDto.java @@ -0,0 +1,15 @@ +package org.gachon.checkmate.domain.member.dto.request; + +import org.gachon.checkmate.domain.member.entity.GenderType; +import org.gachon.checkmate.domain.member.entity.MbtiType; + +public record MemberSignUpRequestDto( + String email, + String password, + String name, + String school, + String major, + MbtiType mbtiType, + GenderType genderType +) { +} From 995afff5ed78a8e12e941bf608b36e649dc1ee12 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 18:01:50 +0900 Subject: [PATCH 11/26] =?UTF-8?q?[feat]=20#10=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20response=20dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/MemberSignUpResponseDto.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignUpResponseDto.java diff --git a/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignUpResponseDto.java b/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignUpResponseDto.java new file mode 100644 index 0000000..a652160 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignUpResponseDto.java @@ -0,0 +1,20 @@ +package org.gachon.checkmate.domain.member.dto.response; + +import lombok.Builder; + +@Builder +public record MemberSignUpResponseDto( + String name, + String accessToken, + String refreshToken +) { + public static MemberSignUpResponseDto of(String name, + String accessToken, + String refreshToken) { + return MemberSignUpResponseDto.builder() + .name(name) + .accessToken(accessToken) + .refreshToken(refreshToken) + .build(); + } +} From 827b6fbf51cad68c90534a0c1e400eb3202eac5d Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 18:02:12 +0900 Subject: [PATCH 12/26] =?UTF-8?q?[feat]=20#10=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20API=20controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/controller/MemberController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java b/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java index 58e883f..e654ef0 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java +++ b/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java @@ -2,7 +2,9 @@ import lombok.RequiredArgsConstructor; import org.gachon.checkmate.domain.member.dto.request.EmailPostRequestDto; +import org.gachon.checkmate.domain.member.dto.request.MemberSignUpRequestDto; import org.gachon.checkmate.domain.member.dto.response.EmailResponseDto; +import org.gachon.checkmate.domain.member.dto.response.MemberSignUpResponseDto; import org.gachon.checkmate.domain.member.service.MemberService; import org.gachon.checkmate.global.common.SuccessResponse; import org.springframework.http.ResponseEntity; @@ -23,4 +25,11 @@ public ResponseEntity> sendMail(@RequestBody final EmailPostR final EmailResponseDto emailResponseDto = memberService.sendMail(emailPostRequestDto); return SuccessResponse.ok(emailResponseDto); } + + @PostMapping("/signup") + public ResponseEntity> signUp(@RequestBody final MemberSignUpRequestDto memberSignUpRequestDto){ + final MemberSignUpResponseDto memberSignUpResponseDto = memberService.signUp(memberSignUpRequestDto); + return SuccessResponse.ok(memberSignUpResponseDto); + } + } From 03999b7c355b90a8ba691cb0a5f90b20a3abca73 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 18:02:19 +0900 Subject: [PATCH 13/26] =?UTF-8?q?[feat]=20#10=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20API=20service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/service/MemberService.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java index 5d27983..cd41e25 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java +++ b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java @@ -3,9 +3,14 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.gachon.checkmate.domain.member.dto.request.EmailPostRequestDto; +import org.gachon.checkmate.domain.member.dto.request.MemberSignUpRequestDto; import org.gachon.checkmate.domain.member.dto.response.EmailResponseDto; +import org.gachon.checkmate.domain.member.dto.response.MemberSignUpResponseDto; +import org.gachon.checkmate.domain.member.entity.User; +import org.gachon.checkmate.domain.member.repository.UserRepository; import org.gachon.checkmate.global.config.auth.jwt.JwtProvider; import org.gachon.checkmate.global.config.mail.MailProvider; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,10 +22,44 @@ public class MemberService { private final JwtProvider jwtProvider; private final MailProvider mailProvider; + private final PasswordEncoder passwordEncoder; + private final UserRepository userRepository; public EmailResponseDto sendMail(EmailPostRequestDto emailPostRequestDto) { String authNum = mailProvider.sendMail(emailPostRequestDto.email(), "email"); return new EmailResponseDto(authNum); } + public MemberSignUpResponseDto signUp(MemberSignUpRequestDto memberSignUpRequestDto) { + Long newMemberId = createMember(memberSignUpRequestDto); + String accessToken = issueNewToken(newMemberId); + String refreshToken = issueNewToken(newMemberId); + return MemberSignUpResponseDto.of(memberSignUpRequestDto.name(), accessToken, refreshToken); + } + + private String issueNewToken(Long memberId) { + return jwtProvider.getIssueToken(memberId, true); + } + + private Long createMember(MemberSignUpRequestDto memberSignUpRequestDto) { + User newUser = User.createUser( + memberSignUpRequestDto.email(), + encodedPassword(memberSignUpRequestDto.password()), + memberSignUpRequestDto.name(), + memberSignUpRequestDto.school(), + memberSignUpRequestDto.major(), + memberSignUpRequestDto.mbtiType(), + memberSignUpRequestDto.genderType() + ); + return userRepository.save(newUser).getId(); + } + + private String encodedPassword(String rawPassword) { + return passwordEncoder.encode(rawPassword); + } + + private boolean authenticatePassword(String enteredPassword, String storedPassword) { + return passwordEncoder.matches(enteredPassword, storedPassword); + } + } From 89123c2e00e9e37e463573e0ef79aaa7a3686a1a Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 18:02:54 +0900 Subject: [PATCH 14/26] =?UTF-8?q?[rename]=20#10=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20imp?= =?UTF-8?q?ort=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/gachon/checkmate/domain/post/entity/Post.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java index 02fc850..3533425 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java +++ b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java @@ -4,7 +4,6 @@ import lombok.*; import org.gachon.checkmate.domain.checkList.entity.PostCheckList; import org.gachon.checkmate.domain.post.converter.RoomTypeConverter; -import org.gachon.checkmate.domain.member.entity.RoomType; import org.gachon.checkmate.domain.member.entity.User; import org.gachon.checkmate.domain.post.converter.ImportantKeyTypeConverter; import org.gachon.checkmate.domain.post.converter.SimilarityKeyTypeConverter; From 15f3fd39dfe778cf6ef13e26e2e25974f6b84b79 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 18:16:43 +0900 Subject: [PATCH 15/26] =?UTF-8?q?[feat]=20#10=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20response=20dto=EC=97=90=20memberId=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/dto/response/MemberSignUpResponseDto.java | 5 ++++- .../checkmate/domain/member/service/MemberService.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignUpResponseDto.java b/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignUpResponseDto.java index a652160..052daa9 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignUpResponseDto.java +++ b/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignUpResponseDto.java @@ -4,14 +4,17 @@ @Builder public record MemberSignUpResponseDto( + Long memberId, String name, String accessToken, String refreshToken ) { - public static MemberSignUpResponseDto of(String name, + public static MemberSignUpResponseDto of(Long memberId, + String name, String accessToken, String refreshToken) { return MemberSignUpResponseDto.builder() + .memberId(memberId) .name(name) .accessToken(accessToken) .refreshToken(refreshToken) diff --git a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java index cd41e25..8b24b1a 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java +++ b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java @@ -34,7 +34,7 @@ public MemberSignUpResponseDto signUp(MemberSignUpRequestDto memberSignUpRequest Long newMemberId = createMember(memberSignUpRequestDto); String accessToken = issueNewToken(newMemberId); String refreshToken = issueNewToken(newMemberId); - return MemberSignUpResponseDto.of(memberSignUpRequestDto.name(), accessToken, refreshToken); + return MemberSignUpResponseDto.of(newMemberId, memberSignUpRequestDto.name(), accessToken, refreshToken); } private String issueNewToken(Long memberId) { From c7e5ad669ff3c35a9d15aa8e425cadebebba8cab Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 19:15:05 +0900 Subject: [PATCH 16/26] =?UTF-8?q?[feat]=20#10=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20request=20dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/dto/request/MemberSignInRequestDto.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/member/dto/request/MemberSignInRequestDto.java diff --git a/src/main/java/org/gachon/checkmate/domain/member/dto/request/MemberSignInRequestDto.java b/src/main/java/org/gachon/checkmate/domain/member/dto/request/MemberSignInRequestDto.java new file mode 100644 index 0000000..153d60a --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/member/dto/request/MemberSignInRequestDto.java @@ -0,0 +1,7 @@ +package org.gachon.checkmate.domain.member.dto.request; + +public record MemberSignInRequestDto( + String email, + String password +) { +} From 6c80e1cbdd415b5fad1e45ff5e0f95be1ac0f775 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 19:15:12 +0900 Subject: [PATCH 17/26] =?UTF-8?q?[feat]=20#10=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20response=20dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/MemberSignInResponseDto.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignInResponseDto.java diff --git a/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignInResponseDto.java b/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignInResponseDto.java new file mode 100644 index 0000000..b594764 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/member/dto/response/MemberSignInResponseDto.java @@ -0,0 +1,20 @@ +package org.gachon.checkmate.domain.member.dto.response; + +import lombok.Builder; + +@Builder +public record MemberSignInResponseDto( + Long memberId, + String accessToken, + String refreshToken +) { + public static MemberSignInResponseDto of(Long memberId, + String accessToken, + String refreshToken) { + return MemberSignInResponseDto.builder() + .memberId(memberId) + .accessToken(accessToken) + .refreshToken(refreshToken) + .build(); + } +} From 37445446fbb2d746e45dbeaac31a8a19f27af59e Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 19:16:17 +0900 Subject: [PATCH 18/26] =?UTF-8?q?[feat]=20#10=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=20service=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/repository/UserRepository.java | 3 +++ .../domain/member/service/MemberService.java | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/member/repository/UserRepository.java b/src/main/java/org/gachon/checkmate/domain/member/repository/UserRepository.java index 64c78a6..15160fb 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/repository/UserRepository.java +++ b/src/main/java/org/gachon/checkmate/domain/member/repository/UserRepository.java @@ -3,6 +3,9 @@ import org.gachon.checkmate.domain.member.entity.User; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface UserRepository extends JpaRepository { + Optional findByEmail(String email); } diff --git a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java index 8b24b1a..35b1acd 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java +++ b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java @@ -3,17 +3,24 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.gachon.checkmate.domain.member.dto.request.EmailPostRequestDto; +import org.gachon.checkmate.domain.member.dto.request.MemberSignInRequestDto; import org.gachon.checkmate.domain.member.dto.request.MemberSignUpRequestDto; import org.gachon.checkmate.domain.member.dto.response.EmailResponseDto; +import org.gachon.checkmate.domain.member.dto.response.MemberSignInResponseDto; import org.gachon.checkmate.domain.member.dto.response.MemberSignUpResponseDto; import org.gachon.checkmate.domain.member.entity.User; import org.gachon.checkmate.domain.member.repository.UserRepository; import org.gachon.checkmate.global.config.auth.jwt.JwtProvider; import org.gachon.checkmate.global.config.mail.MailProvider; +import org.gachon.checkmate.global.error.exception.EntityNotFoundException; +import org.gachon.checkmate.global.error.exception.UnauthorizedException; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static org.gachon.checkmate.global.error.ErrorCode.INVALID_PASSWORD; +import static org.gachon.checkmate.global.error.ErrorCode.USER_NOT_FOUND; + @Slf4j @RequiredArgsConstructor @Transactional @@ -37,6 +44,16 @@ public MemberSignUpResponseDto signUp(MemberSignUpRequestDto memberSignUpRequest return MemberSignUpResponseDto.of(newMemberId, memberSignUpRequestDto.name(), accessToken, refreshToken); } + public MemberSignInResponseDto signIn(MemberSignInRequestDto memberSignInRequestDto){ + User user = getUserFromEmail(memberSignInRequestDto.email()); + if (!authenticatePassword(memberSignInRequestDto.password(), user.getPassword())) { + throw new UnauthorizedException(INVALID_PASSWORD); + } + String accessToken = issueNewToken(user.getId()); + String refreshToken = issueNewToken(user.getId()); + return MemberSignInResponseDto.of(user.getId(), accessToken, refreshToken); + } + private String issueNewToken(Long memberId) { return jwtProvider.getIssueToken(memberId, true); } @@ -62,4 +79,10 @@ private boolean authenticatePassword(String enteredPassword, String storedPasswo return passwordEncoder.matches(enteredPassword, storedPassword); } + private User getUserFromEmail(String email) { + return userRepository.findByEmail(email) + .orElseThrow(() -> new EntityNotFoundException(USER_NOT_FOUND)); + } + + } From 3ede85906d4ef4b9c4755a30951788c47544b866 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 19:16:29 +0900 Subject: [PATCH 19/26] =?UTF-8?q?[feat]=20#10=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=20controller=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/controller/MemberController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java b/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java index e654ef0..c465f92 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java +++ b/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java @@ -2,8 +2,10 @@ import lombok.RequiredArgsConstructor; import org.gachon.checkmate.domain.member.dto.request.EmailPostRequestDto; +import org.gachon.checkmate.domain.member.dto.request.MemberSignInRequestDto; import org.gachon.checkmate.domain.member.dto.request.MemberSignUpRequestDto; import org.gachon.checkmate.domain.member.dto.response.EmailResponseDto; +import org.gachon.checkmate.domain.member.dto.response.MemberSignInResponseDto; import org.gachon.checkmate.domain.member.dto.response.MemberSignUpResponseDto; import org.gachon.checkmate.domain.member.service.MemberService; import org.gachon.checkmate.global.common.SuccessResponse; @@ -32,4 +34,10 @@ public ResponseEntity> signUp(@RequestBody final MemberSignUp return SuccessResponse.ok(memberSignUpResponseDto); } + @PostMapping("/signin") + public ResponseEntity> signIn(@RequestBody final MemberSignInRequestDto memberSignInRequestDto){ + final MemberSignInResponseDto memberSignInResponseDto = memberService.signIn(memberSignInRequestDto); + return SuccessResponse.ok(memberSignInResponseDto); + } + } From 62e7fc7e59dcdf624ed6661e09b77382053bb50a Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 19:16:40 +0900 Subject: [PATCH 20/26] =?UTF-8?q?[feat]=20#10=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EA=B4=80=EB=A0=A8=20Errorcode=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/gachon/checkmate/global/error/ErrorCode.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java index 983ca6a..1a63281 100644 --- a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java +++ b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java @@ -25,6 +25,7 @@ public enum ErrorCode { INVALID_REFRESH_TOKEN_VALUE(HttpStatus.UNAUTHORIZED, "리프레시 토큰의 값이 올바르지 않습니다."), EXPIRED_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "리프레시 토큰이 만료되었습니다. 다시 로그인해 주세요."), NOT_MATCH_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "일치하지 않는 리프레시 토큰입니다."), + INVALID_PASSWORD(HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지 않습니다."), /** * 403 Forbidden @@ -36,6 +37,7 @@ public enum ErrorCode { */ ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND, "엔티티를 찾을 수 없습니다."), CHECK_LIST_NOT_FOUND(HttpStatus.NOT_FOUND, "체크리스트를 찾을 수 없습니다."), + USER_NOT_FOUND(HttpStatus.NOT_FOUND, "해당하는 유저를 찾을 수 없습니다."), /** * 405 Method Not Allowed From a0b7cbb336fdfc52af899a532074c2d76b057149 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 19:17:03 +0900 Subject: [PATCH 21/26] =?UTF-8?q?[chore]=20#10=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20URL=20webSecurityCustomizer=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/gachon/checkmate/global/config/auth/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java b/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java index 19766d8..92ef638 100644 --- a/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java +++ b/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java @@ -25,7 +25,7 @@ public class SecurityConfig { private final CorsConfig corsConfig; private final JwtProvider jwtProvider; - private static final String[] whiteList = {"/", "api/member/email", "api/member/signup"}; + private static final String[] whiteList = {"/", "api/member/email", "api/member/signup", "api/member/signin"}; @Bean public WebSecurityCustomizer webSecurityCustomizer() { From ffe5cebb072da8ad2489f5de83b7ae12486a50e7 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 19:24:18 +0900 Subject: [PATCH 22/26] =?UTF-8?q?[feat]=20#10=20=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=A0=84=EC=86=A1=20=EC=8B=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=A9=94=EC=9D=BC=20=EC=A4=91=EB=B3=B5=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/repository/UserRepository.java | 1 + .../domain/member/service/MemberService.java | 13 ++++++++++--- .../gachon/checkmate/global/error/ErrorCode.java | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/member/repository/UserRepository.java b/src/main/java/org/gachon/checkmate/domain/member/repository/UserRepository.java index 15160fb..5d5013d 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/repository/UserRepository.java +++ b/src/main/java/org/gachon/checkmate/domain/member/repository/UserRepository.java @@ -8,4 +8,5 @@ public interface UserRepository extends JpaRepository { Optional findByEmail(String email); + boolean existsByEmail(String email); } diff --git a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java index 35b1acd..a2b27ac 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java +++ b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java @@ -12,14 +12,14 @@ import org.gachon.checkmate.domain.member.repository.UserRepository; import org.gachon.checkmate.global.config.auth.jwt.JwtProvider; import org.gachon.checkmate.global.config.mail.MailProvider; +import org.gachon.checkmate.global.error.exception.ConflictException; import org.gachon.checkmate.global.error.exception.EntityNotFoundException; import org.gachon.checkmate.global.error.exception.UnauthorizedException; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static org.gachon.checkmate.global.error.ErrorCode.INVALID_PASSWORD; -import static org.gachon.checkmate.global.error.ErrorCode.USER_NOT_FOUND; +import static org.gachon.checkmate.global.error.ErrorCode.*; @Slf4j @RequiredArgsConstructor @@ -33,6 +33,7 @@ public class MemberService { private final UserRepository userRepository; public EmailResponseDto sendMail(EmailPostRequestDto emailPostRequestDto) { + checkDuplicateEmail(emailPostRequestDto.email()); String authNum = mailProvider.sendMail(emailPostRequestDto.email(), "email"); return new EmailResponseDto(authNum); } @@ -44,7 +45,7 @@ public MemberSignUpResponseDto signUp(MemberSignUpRequestDto memberSignUpRequest return MemberSignUpResponseDto.of(newMemberId, memberSignUpRequestDto.name(), accessToken, refreshToken); } - public MemberSignInResponseDto signIn(MemberSignInRequestDto memberSignInRequestDto){ + public MemberSignInResponseDto signIn(MemberSignInRequestDto memberSignInRequestDto) { User user = getUserFromEmail(memberSignInRequestDto.email()); if (!authenticatePassword(memberSignInRequestDto.password(), user.getPassword())) { throw new UnauthorizedException(INVALID_PASSWORD); @@ -54,6 +55,12 @@ public MemberSignInResponseDto signIn(MemberSignInRequestDto memberSignInRequest return MemberSignInResponseDto.of(user.getId(), accessToken, refreshToken); } + private void checkDuplicateEmail(String email) { + if (userRepository.existsByEmail(email)) { + throw new ConflictException(DUPLICATE_EMAIL); + } + } + private String issueNewToken(Long memberId) { return jwtProvider.getIssueToken(memberId, true); } diff --git a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java index 1a63281..61946f4 100644 --- a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java +++ b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java @@ -48,6 +48,7 @@ public enum ErrorCode { * 409 Conflict */ CONFLICT(HttpStatus.CONFLICT, "이미 존재하는 리소스입니다."), + DUPLICATE_EMAIL(HttpStatus.CONFLICT, "이미 가입된 이메일입니다."), /** * 500 Internal Server Error From f55185dc8fe2dc5df3d74e3762b7787ff2769158 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 19:36:33 +0900 Subject: [PATCH 23/26] =?UTF-8?q?[fix]=20#10=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/service/MemberService.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java index a2b27ac..41cb26a 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java +++ b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java @@ -40,19 +40,23 @@ public EmailResponseDto sendMail(EmailPostRequestDto emailPostRequestDto) { public MemberSignUpResponseDto signUp(MemberSignUpRequestDto memberSignUpRequestDto) { Long newMemberId = createMember(memberSignUpRequestDto); - String accessToken = issueNewToken(newMemberId); - String refreshToken = issueNewToken(newMemberId); + String accessToken = issueNewAccessToken(newMemberId); + String refreshToken = issueNewRefreshToken(newMemberId); return MemberSignUpResponseDto.of(newMemberId, memberSignUpRequestDto.name(), accessToken, refreshToken); } public MemberSignInResponseDto signIn(MemberSignInRequestDto memberSignInRequestDto) { User user = getUserFromEmail(memberSignInRequestDto.email()); - if (!authenticatePassword(memberSignInRequestDto.password(), user.getPassword())) { + validatePassword(memberSignInRequestDto.password(), user.getPassword()); + String accessToken = issueNewAccessToken(user.getId()); + String refreshToken = issueNewRefreshToken(user.getId()); + return MemberSignInResponseDto.of(user.getId(), accessToken, refreshToken); + } + + private void validatePassword(String enteredPassword, String storedPassword) { + if (!authenticatePassword(enteredPassword, storedPassword)) { throw new UnauthorizedException(INVALID_PASSWORD); } - String accessToken = issueNewToken(user.getId()); - String refreshToken = issueNewToken(user.getId()); - return MemberSignInResponseDto.of(user.getId(), accessToken, refreshToken); } private void checkDuplicateEmail(String email) { @@ -61,10 +65,14 @@ private void checkDuplicateEmail(String email) { } } - private String issueNewToken(Long memberId) { + private String issueNewAccessToken(Long memberId) { return jwtProvider.getIssueToken(memberId, true); } + private String issueNewRefreshToken(Long memberId) { + return jwtProvider.getIssueToken(memberId, false); + } + private Long createMember(MemberSignUpRequestDto memberSignUpRequestDto) { User newUser = User.createUser( memberSignUpRequestDto.email(), From 7e35edb834cf0e9fe3d34a50a85125c13e37c5d1 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 20:33:27 +0900 Subject: [PATCH 24/26] =?UTF-8?q?[feat]=20#10=20=EB=B9=84=EB=B0=80?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=9E=AC=EC=84=A4=EC=A0=95=20controller?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/controller/MemberController.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java b/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java index c465f92..c83b1e5 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java +++ b/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java @@ -4,16 +4,14 @@ import org.gachon.checkmate.domain.member.dto.request.EmailPostRequestDto; import org.gachon.checkmate.domain.member.dto.request.MemberSignInRequestDto; import org.gachon.checkmate.domain.member.dto.request.MemberSignUpRequestDto; +import org.gachon.checkmate.domain.member.dto.request.PasswordResetRequestDto; import org.gachon.checkmate.domain.member.dto.response.EmailResponseDto; import org.gachon.checkmate.domain.member.dto.response.MemberSignInResponseDto; import org.gachon.checkmate.domain.member.dto.response.MemberSignUpResponseDto; import org.gachon.checkmate.domain.member.service.MemberService; import org.gachon.checkmate.global.common.SuccessResponse; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RequiredArgsConstructor @RequestMapping("/api/member") @@ -40,4 +38,9 @@ public ResponseEntity> signIn(@RequestBody final MemberSignIn return SuccessResponse.ok(memberSignInResponseDto); } + @PatchMapping("/reset") + public ResponseEntity> setPassword(@RequestBody final PasswordResetRequestDto passwordResetRequestDto){ + memberService.setPassword(passwordResetRequestDto); + return SuccessResponse.ok(null); + } } From af61e61a4961f8634df40578b52067fe80e3acbd Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sat, 30 Dec 2023 20:33:37 +0900 Subject: [PATCH 25/26] =?UTF-8?q?[feat]=20#10=20=EB=B9=84=EB=B0=80?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=9E=AC=EC=84=A4=EC=A0=95=20service=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/dto/request/PasswordResetRequestDto.java | 7 +++++++ .../org/gachon/checkmate/domain/member/entity/User.java | 4 ++++ .../checkmate/domain/member/service/MemberService.java | 6 ++++++ 3 files changed, 17 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/member/dto/request/PasswordResetRequestDto.java diff --git a/src/main/java/org/gachon/checkmate/domain/member/dto/request/PasswordResetRequestDto.java b/src/main/java/org/gachon/checkmate/domain/member/dto/request/PasswordResetRequestDto.java new file mode 100644 index 0000000..2dcb57f --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/member/dto/request/PasswordResetRequestDto.java @@ -0,0 +1,7 @@ +package org.gachon.checkmate.domain.member.dto.request; + +public record PasswordResetRequestDto( + String email, + String newPassword +) { +} diff --git a/src/main/java/org/gachon/checkmate/domain/member/entity/User.java b/src/main/java/org/gachon/checkmate/domain/member/entity/User.java index 6983f05..40967b3 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/entity/User.java +++ b/src/main/java/org/gachon/checkmate/domain/member/entity/User.java @@ -55,4 +55,8 @@ public static User createUser(String email, String storedPassword, String name, .gender(gender) .build(); } + + public void setPassword(String newPassword) { + this.password = newPassword; + } } diff --git a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java index 41cb26a..037baeb 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java +++ b/src/main/java/org/gachon/checkmate/domain/member/service/MemberService.java @@ -5,6 +5,7 @@ import org.gachon.checkmate.domain.member.dto.request.EmailPostRequestDto; import org.gachon.checkmate.domain.member.dto.request.MemberSignInRequestDto; import org.gachon.checkmate.domain.member.dto.request.MemberSignUpRequestDto; +import org.gachon.checkmate.domain.member.dto.request.PasswordResetRequestDto; import org.gachon.checkmate.domain.member.dto.response.EmailResponseDto; import org.gachon.checkmate.domain.member.dto.response.MemberSignInResponseDto; import org.gachon.checkmate.domain.member.dto.response.MemberSignUpResponseDto; @@ -53,6 +54,11 @@ public MemberSignInResponseDto signIn(MemberSignInRequestDto memberSignInRequest return MemberSignInResponseDto.of(user.getId(), accessToken, refreshToken); } + public void setPassword(PasswordResetRequestDto passwordResetRequestDto){ + User user = getUserFromEmail(passwordResetRequestDto.email()); + user.setPassword(encodedPassword(passwordResetRequestDto.newPassword())); + } + private void validatePassword(String enteredPassword, String storedPassword) { if (!authenticatePassword(enteredPassword, storedPassword)) { throw new UnauthorizedException(INVALID_PASSWORD); From 71817569141d58d84ba0072fe8b9b28b5255b0f8 Mon Sep 17 00:00:00 2001 From: ziiyouth Date: Sun, 31 Dec 2023 13:56:28 +0900 Subject: [PATCH 26/26] =?UTF-8?q?[fix]=20#10=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EC=9D=91=EB=8B=B5=EA=B0=92=20=EC=BD=94=EB=93=9C=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 --- .../checkmate/domain/member/controller/MemberController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java b/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java index c83b1e5..befbfff 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java +++ b/src/main/java/org/gachon/checkmate/domain/member/controller/MemberController.java @@ -29,7 +29,7 @@ public ResponseEntity> sendMail(@RequestBody final EmailPostR @PostMapping("/signup") public ResponseEntity> signUp(@RequestBody final MemberSignUpRequestDto memberSignUpRequestDto){ final MemberSignUpResponseDto memberSignUpResponseDto = memberService.signUp(memberSignUpRequestDto); - return SuccessResponse.ok(memberSignUpResponseDto); + return SuccessResponse.created(memberSignUpResponseDto); } @PostMapping("/signin")