Skip to content

Commit

Permalink
Merge pull request #4 from kusitms-28th-Meetup-E/feat/auth
Browse files Browse the repository at this point in the history
feat : local signUp #3
  • Loading branch information
seungueonn authored Nov 1, 2023
2 parents 5554793 + d6207f1 commit 4d8fba7
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 10 deletions.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package gwangjang.server.domain.auth.application.dto.request;

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class LocalSignUpRequest {
private String id;
private String pw;
private String nickname;
private String gender;
private String email;
private String birthDate;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gwangjang.server.domain.auth.application.mapper;

import gwangjang.server.domain.auth.application.dto.request.LocalSignUpRequest;
import gwangjang.server.domain.auth.application.dto.response.GoogleUserResponse;
import gwangjang.server.domain.auth.application.dto.response.KakaoUserResponse;
import gwangjang.server.domain.member.domain.entity.Member;
Expand All @@ -8,6 +9,8 @@
import gwangjang.server.domain.member.domain.entity.constant.SocialProvider;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class MemberMapper {

Expand Down Expand Up @@ -46,4 +49,14 @@ public Member createGoogleMember(GoogleUserResponse googleUserResponse){

return newMember;
}

public Member createLocalMember(LocalSignUpRequest localSignUpRequest) {
return Member.builder()
.socialId(SocialProvider.LOCAL + "@" + UUID.randomUUID())
.provider(SocialProvider.LOCAL)
.email(localSignUpRequest.getEmail())
.role(Role.USER)
.registrationStatus(RegistrationStatus.COMPLETED)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package gwangjang.server.domain.auth.application.service;

import gwangjang.server.domain.auth.application.dto.request.LocalSignInRequest;
import gwangjang.server.domain.auth.application.dto.request.LocalSignUpRequest;
import gwangjang.server.domain.auth.application.dto.request.SignUpRequest;
import gwangjang.server.domain.auth.application.dto.response.SignInResponse;
import gwangjang.server.domain.auth.application.mapper.MemberMapper;
import gwangjang.server.domain.auth.exception.EmailDuplicationException;
import gwangjang.server.domain.auth.exception.NicknameDuplicationException;
import gwangjang.server.domain.member.domain.service.MemberSaveService;
import gwangjang.server.global.security.jwt.service.TokenUtil;
import gwangjang.server.domain.member.domain.entity.Member;
import gwangjang.server.domain.member.domain.entity.constant.RegistrationStatus;
Expand All @@ -22,7 +27,9 @@ public class SignUpUserCase {

private final TokenUtil tokenUtil;
private final MemberGetService memberGetService;
private final MemberSaveService memberSaveService;
private final MemberCheckService memberCheckService;
private final MemberMapper memberMapper;

// 추가 정보 기입
public SignInResponse signUp(String token, SignUpRequest signUpRequest) {
Expand All @@ -41,6 +48,28 @@ public SignInResponse signUp(String token, SignUpRequest signUpRequest) {
member.getRegistrationStatus().equals(RegistrationStatus.COMPLETED),member.getRole().getKey());
// //5. refresh token 저장
tokenUtil.storeRefreshToken(member.getSocialId(), tokenResponse);
//
return SignInResponse.from(tokenResponse, member.getRegistrationStatus());
}
// 추가 정보 기입
public SignInResponse localSignUp(LocalSignUpRequest localSignUpRequest) {


//2. signUp 처리
String nickname=localSignUpRequest.getNickname();
if(memberCheckService.checkNickname(nickname)) throw new NicknameDuplicationException(); //닉네임 중복검사 (이중체크)

String email = localSignUpRequest.getEmail();
if(memberCheckService.checkEmail(email)) throw new EmailDuplicationException();

Member member = memberSaveService.saveMember(memberMapper.createLocalMember(localSignUpRequest));
//3. security 처리
AuthenticationUtil.makeAuthentication(member);
//4. token 만들기
TokenInfoResponse tokenResponse = tokenUtil.createToken(member.getSocialId(),
member.getRegistrationStatus().equals(RegistrationStatus.COMPLETED),member.getRole().getKey());
// //5. refresh token 저장
tokenUtil.storeRefreshToken(member.getSocialId(), tokenResponse);
//
return SignInResponse.from(tokenResponse, member.getRegistrationStatus());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gwangjang.server.domain.auth.exception;

import gwangjang.server.global.response.ErrorCode;
import org.springframework.http.HttpStatus;

public class EmailDuplicationException extends AuthException {
public EmailDuplicationException(){
super(ErrorCode.NICKNAME_DUPLICATION_ERROR,
HttpStatus.BAD_REQUEST);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package gwangjang.server.domain.auth.presentation;

import gwangjang.server.domain.auth.application.dto.request.LocalSignInRequest;
import gwangjang.server.domain.auth.application.dto.request.SignInRequest;
import gwangjang.server.domain.auth.application.dto.request.SignUpRequest;
import gwangjang.server.domain.auth.application.dto.request.TestRequest;
import gwangjang.server.domain.auth.application.dto.request.*;
import gwangjang.server.domain.auth.application.dto.response.CheckNicknameResponse;
import gwangjang.server.domain.auth.application.dto.response.ReissueTokenResponse;
import gwangjang.server.domain.auth.application.dto.response.SignInResponse;
Expand All @@ -19,6 +16,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;


Expand Down Expand Up @@ -49,18 +47,23 @@ public ResponseEntity<SuccessResponse<SignInResponse>> signIn(
@PostMapping("/signIn/{provider}")
public ResponseEntity<SuccessResponse<SignInResponse>> socialSignIn(@PathVariable String provider,
@Valid @RequestBody SignInRequest signInRequest) {
log.info("kakao login Hi");
return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.signIn(signInRequest.getToken(), provider)));
}


@PutMapping("/signUp")
public ResponseEntity<SuccessResponse<SignInResponse>> socialSignUp(@RequestHeader(value = "Authorization") String token,
@Valid @RequestBody SignUpRequest signUpRequest) {
@PutMapping("/signUp/{provider}")
public ResponseEntity<SuccessResponse<SignInResponse>> socialSignUp(@PathVariable String provider,
@RequestHeader(value = "Authorization") String token,
@Valid @RequestBody SignUpRequest signUpRequest) {
token = (token != null && token.startsWith("Bearer ")) ? token.substring(7) : token;
return ResponseEntity.ok(SuccessResponse.create(SIGN_UP_SUCCESS.getMessage(), this.signUpService.signUp(token, signUpRequest)));
}

@PostMapping("/signUp")
public ResponseEntity<SuccessResponse<SignInResponse>> signUp(@Valid @RequestBody LocalSignUpRequest signUpRequest) {
return ResponseEntity.ok(SuccessResponse.create(SIGN_UP_SUCCESS.getMessage(), this.signUpService.localSignUp(signUpRequest)));
}

@GetMapping("/reissue")
public ResponseEntity<SuccessResponse<ReissueTokenResponse>> reissue(@RequestHeader(value = "RefreshToken") String token) {
ReissueTokenResponse reissueToken = reissueTokenService.reissueToken(token);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gwangjang.server.domain.member.domain.entity;

import gwangjang.server.domain.auth.application.dto.request.SignUpRequest;
import gwangjang.server.domain.member.domain.entity.constant.Gender;
import gwangjang.server.domain.member.domain.entity.constant.RegistrationStatus;
import gwangjang.server.domain.member.domain.entity.constant.Role;
import gwangjang.server.domain.member.domain.entity.constant.SocialProvider;
Expand Down Expand Up @@ -45,11 +46,14 @@ public class Member {
@Enumerated(EnumType.STRING)
private Role role;

private String nickname;

private String loginId;
private String loginPw;

private String nickname;

private String birth;
private String gender;

public void tempSignUp() {
this.registrationStatus = RegistrationStatus.COMPLETED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

public interface MemberCustomRepository {
boolean checkNickname(String nickname);
boolean checkEmail(String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@ public boolean checkNickname(String nickname) {
.fetchFirst() != null;
}

@Override
public boolean checkEmail(String email) {
return queryFactory
.selectOne()
.from(member)
.where(member.email.eq(email))
.fetchFirst() != null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ public class MemberCheckService {
public boolean checkNickname(String nickname) {
return memberRepository.checkNickname(nickname);
}
public boolean checkEmail(String email) {
return memberRepository.checkEmail(email);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum ErrorCode {
TOKEN_INVALID_ERROR("AU0002", "입력 토큰이 유효하지 않습니다."),
APPID_INVALID_ERROR("AU0003", "appId가 유효하지 않습니다"),
NICKNAME_DUPLICATION_ERROR("AU0004", "닉네임이 중복됩니다."),
EMAIL_DUPLICATION_ERROR("AU0005", "닉네임이 중복됩니다."),

NOT_FOUND_BY_LOGIN_ID_ERROR("L001","해당 id인 유저가 존재하지 않습니다"),
INCORRECT_PASSWORD("L002","비밀번호가 틀렸습니다");
Expand Down

0 comments on commit 4d8fba7

Please sign in to comment.