-
Notifications
You must be signed in to change notification settings - Fork 4
[feat] 자체 회원가입 처리 구현 #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[feat] 자체 회원가입 처리 구현 #108
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/arom/with_travel/domain/member/controller/AuthController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.arom.with_travel.domain.member.controller; | ||
|
|
||
| import com.arom.with_travel.domain.member.dto.request.LocalLoginRequest; | ||
| import com.arom.with_travel.domain.member.dto.request.SignupWithSurveyRequestDto; | ||
| import com.arom.with_travel.domain.member.dto.response.LoginResponse; | ||
| import com.arom.with_travel.domain.member.service.LocalAuthService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/v1/auth") | ||
| @RequiredArgsConstructor | ||
| public class AuthController { | ||
|
|
||
| private final LocalAuthService authService; | ||
|
|
||
| // 이메일 중복 체크 | ||
| @GetMapping("/email-available") | ||
| public boolean emailAvailable(@RequestParam String email) { | ||
| return authService.isEmailAvailable(email); | ||
| } | ||
|
|
||
| // 이메일 등록(회원가입) | ||
| @PostMapping("/register") | ||
| public ResponseEntity<LoginResponse> register(@Valid @RequestBody SignupWithSurveyRequestDto req) { | ||
| return ResponseEntity.ok(authService.registerWithSurvey(req)); | ||
| } | ||
|
|
||
| // 로그인 | ||
| @PostMapping("/login") | ||
| public LoginResponse login(@Valid @RequestBody LocalLoginRequest req) { | ||
| return authService.login(req); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/arom/with_travel/domain/member/dto/request/LocalLoginRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.arom.with_travel.domain.member.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.Email; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Size; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| public class LocalLoginRequest { | ||
| @NotBlank @Email | ||
| private String email; | ||
|
|
||
| @NotBlank @Size(min=8, max=64) | ||
| private String password; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/arom/with_travel/domain/member/dto/response/LoginResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.arom.with_travel.domain.member.dto.response; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class LoginResponse { | ||
| private String accessToken; | ||
| private String refreshToken; | ||
| private boolean infoChecked; | ||
| } |
100 changes: 100 additions & 0 deletions
100
src/main/java/com/arom/with_travel/domain/member/service/LocalAuthService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package com.arom.with_travel.domain.member.service; | ||
|
|
||
| import com.arom.with_travel.domain.member.Member; | ||
| import com.arom.with_travel.domain.member.dto.request.LocalLoginRequest; | ||
| import com.arom.with_travel.domain.member.dto.request.MemberSignupRequestDto; | ||
| import com.arom.with_travel.domain.member.dto.request.SignupWithSurveyRequestDto; | ||
| import com.arom.with_travel.domain.member.dto.response.LoginResponse; | ||
| import com.arom.with_travel.domain.member.repository.MemberRepository; | ||
| import com.arom.with_travel.domain.survey.Survey; | ||
| import com.arom.with_travel.domain.survey.dto.request.SurveyRequestDto; | ||
| import com.arom.with_travel.domain.survey.repository.SurveyRepository; | ||
| import com.arom.with_travel.global.exception.BaseException; | ||
| import com.arom.with_travel.global.exception.error.ErrorCode; | ||
| import com.arom.with_travel.global.jwt.dto.response.AuthTokenResponse; | ||
| import com.arom.with_travel.global.security.token.provider.JwtProvider; | ||
| import com.arom.with_travel.global.security.token.service.TokenService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| public class LocalAuthService { | ||
|
|
||
| private final MemberRepository memberRepository; | ||
| private final SurveyRepository surveyRepository; | ||
| private final TokenService tokenService; | ||
| private final PasswordEncoder passwordEncoder; | ||
| private final JwtProvider jwtProvider; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public boolean isEmailAvailable(String email) { | ||
| boolean duplicated = memberRepository.existsByEmail(email); | ||
| return !duplicated; | ||
| } | ||
|
|
||
| // 신규 회원 추가 정보 + 설문 통합 등록 | ||
| public LoginResponse registerWithSurvey(SignupWithSurveyRequestDto req) { | ||
|
|
||
| String email = req.getExtraInfo().getEmail(); | ||
| if(!isEmailAvailable(email)) { | ||
| throw BaseException.from(ErrorCode.DUPLICATED_EMAIL); | ||
| } | ||
|
|
||
| MemberSignupRequestDto extra = req.getExtraInfo(); | ||
| String encodedPassword = passwordEncoder.encode(extra.getPassword()); | ||
|
|
||
| Member member = Member.builder() | ||
| .email(extra.getEmail()) | ||
| .password(encodedPassword) | ||
| .name(extra.getName()) | ||
| .phone(extra.getPhone()) | ||
| .birth(extra.getBirthdate()) | ||
| .gender(extra.getGender()) | ||
| .nickname(extra.getNickname()) | ||
| .introduction(extra.getIntroduction()) | ||
| .role(Member.Role.USER) | ||
| .additionalDataChecked(false) | ||
| .build(); | ||
|
|
||
| member = memberRepository.save(member); | ||
|
|
||
| SurveyRequestDto s = req.getSurvey(); | ||
| Survey survey = Survey.create(member, s); | ||
| surveyRepository.save(survey); | ||
| member.setSurvey(survey); | ||
|
|
||
| member.markAdditionalDataChecked(); | ||
|
|
||
| AuthTokenResponse tokenPair = tokenService.issueTokenPair(member.getEmail()); | ||
|
|
||
| return new LoginResponse( | ||
| tokenPair.getAccessToken(), | ||
| tokenPair.getRefreshToken(), | ||
| member.getAdditionalDataChecked() | ||
| ); | ||
| } | ||
|
|
||
| private Member getUserByLoginEmailOrElseThrow(String loginEmail) { | ||
| return memberRepository.findByEmail(loginEmail) | ||
| .orElseThrow(() -> BaseException.from(ErrorCode.MEMBER_NOT_FOUND)); | ||
| } | ||
|
|
||
| // 로그인: raw, hashed 비번 비교 → 토큰 발급 | ||
| @Transactional(readOnly = true) | ||
| public LoginResponse login(LocalLoginRequest req) { | ||
| Member m = memberRepository.findByEmail(req.getEmail()) | ||
| .orElseThrow(() -> BaseException.from(ErrorCode.LOGIN_FAIL)); | ||
|
|
||
| if (m.getPassword() == null || !passwordEncoder.matches(req.getPassword(), m.getPassword())) { | ||
| throw BaseException.from(ErrorCode.LOGIN_FAIL); | ||
| } | ||
|
|
||
| String access = jwtProvider.generateAccessToken(m); | ||
| String refresh = jwtProvider.generateRefreshToken(m); | ||
| return new LoginResponse(access, refresh, Boolean.TRUE.equals(m.getAdditionalDataChecked())); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updateExtraInfo 메서드가 이제 기본 정보(email, password, name, phone)까지 업데이트하므로 메서드명이 부적절합니다. updateMemberInfo 또는 updateAllInfo와 같이 더 명확한 이름으로 변경하는 것을 권장합니다.