Skip to content

Commit

Permalink
[FEAT] 개발서버에서 핸드폰 로직 없이 프로필 생성할 수 있도록 로직 추가 (#239)
Browse files Browse the repository at this point in the history
* hotfix: get contentType from extension

* hotfix: open to jpg

* hotfix: add style for registration email

* hotfix: member name including

* Release 2023-09-02 17:45:00 (#203)

* chore: add sort (#199)

* chore: sort in word list (#200)

* chore: add comparable (#201)

* [CHORE] 정렬 수정 (#202)

* add: lambda sort

* chore: delete other sort

* [CHORE] 커피챗 보라색 제외하기 (#228) (#229)

* chore: logo color - 보라색 제외하기

* chore: index 이전처럼 띄어쓰도록

* Revert "feat: 유저 프로필 수정 1회만 가능하게 코드 추가"

This reverts commit e513113.

* add: 개발서버 핸드폰 로직 건너뛰는 토큰 dev-register-magic-number

* feat: 개발 controller 로직

* feat: 소셜로그인으로만 회원가입 가능한 service 로직 생성

* feat: token로직 검사

* chore: 오타 수정

* add: dev-register-magic-number in property file

---------

Co-authored-by: JungWoo Song <[email protected]>
Co-authored-by: bluayer <[email protected]>
Co-authored-by: Lee SeungHeon <[email protected]>
  • Loading branch information
4 people authored Oct 13, 2023
1 parent f89e98d commit c5e23d9
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/sopt/makers/internal/config/AuthConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public class AuthConfig {
@Value("${oauth.apple.register-token}")
private String magicRegisterToken;

@Value("${oauth.dev-register-magic-number}")
private String devRegisterMagicNumber;

@Value("${oauth.apple.key.url}")
private String applePublicKeysUrl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.sopt.makers.internal.dto.auth.*;
import org.sopt.makers.internal.exception.ForbiddenClientException;
import org.sopt.makers.internal.service.AuthService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -16,6 +17,8 @@
@RequestMapping("/api/v1")
public class AuthController {

@Value("${spring.profiles.active}")
private String activeProfile;
private final AuthService authService;
private final AuthConfig authConfig;

Expand Down Expand Up @@ -46,6 +49,8 @@ public ResponseEntity<AccessTokenResponse> registerByFacebook (@RequestBody Regi
String accessToken;
if (request.registerToken().equals(authConfig.getMagicRegisterToken())) {
accessToken = authService.registerByFbAndMagicRegisterToken(request.registerToken(), request.code());
} else if (activeProfile.equals("dev") && request.registerToken().equals(authConfig.getDevRegisterMagicNumber())) {
accessToken = authService.registerBySocialAndDevMagicRegisterToken(request.registerToken(), request.code(), "facebook");
} else {
accessToken = authService.registerByFb(request.registerToken(), request.code());
}
Expand All @@ -65,6 +70,8 @@ public ResponseEntity<AccessTokenResponse> registerByGoogle (@PathVariable Strin
String accessToken;
if (request.registerToken().equals(authConfig.getMagicRegisterToken())) {
accessToken = authService.registerByGoogleAndMagicRegisterToken(request.registerToken(), request.code(), status);
} else if (activeProfile.equals("dev") && request.registerToken().equals(authConfig.getDevRegisterMagicNumber())) {
accessToken = authService.registerBySocialAndDevMagicRegisterToken(request.registerToken(), request.code(), "google");
} else {
accessToken = authService.registerByGoogle(request.registerToken(), request.code(), status);
}
Expand All @@ -84,6 +91,8 @@ public ResponseEntity<AccessTokenResponse> registerByApple (@PathVariable String
String accessToken;
if (request.registerToken().equals(authConfig.getMagicRegisterToken())) {
accessToken = authService.registerByAppleAndMagicRegisterToken(request.registerToken(), request.code(), status);
} else if (activeProfile.equals("dev") && request.registerToken().equals(authConfig.getDevRegisterMagicNumber())) {
accessToken = authService.registerBySocialAndDevMagicRegisterToken(request.registerToken(), request.code(), "apple");
} else {
accessToken = authService.registerByApple(request.registerToken(), request.code(), status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ public boolean verifyMagicRegisterToken (String token) {
return authConfig.getMagicRegisterToken().equals(token);
}

public boolean verifyDevMagicRegisterToken (String token) {
return authConfig.getDevRegisterMagicNumber().equals(token);
}

private Claims getClaimsFromToken (String token) throws SignatureException {
return Jwts.parserBuilder()
.setSigningKey(DatatypeConverter.parseBase64Binary(authConfig.getJwtSecretKey()))
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/sopt/makers/internal/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,4 @@ public void saveMemberProfile(
this.careers.clear(); this.careers.addAll(careers);
this.hasProfile = true;
}

public void editActivityChangeToFalse() {
this.editActivitiesAble = false;
}
}
}
40 changes: 40 additions & 0 deletions src/main/java/org/sopt/makers/internal/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,46 @@ public String registerByGoogleAndMagicRegisterToken(String registerToken, String
return tokenManager.createAuthToken(member.getId());
}

@Transactional
public String registerBySocialAndDevMagicRegisterToken(String registerToken, String code, String socialType) {
val isMagic = tokenManager.verifyDevMagicRegisterToken(registerToken);
if (!isMagic) throw new WrongTokenException("tokenInvalid");

String authUserId = null;
if(Objects.equals(socialType, "facebook")) {
val fbAccessToken = fbTokenManager.getAccessTokenByCode(code, "register");
if (fbAccessToken == null) throw new AuthFailureException("facebook 인증에 실패했습니다.");
val fbUserInfo = fbTokenManager.getUserInfo(fbAccessToken);
authUserId = fbUserInfo.userId();
}
else if(Objects.equals(socialType, "google")) {
val googleAccessTokenResponse = googleTokenManager.getAccessTokenByCode(code, "register");
if (googleAccessTokenResponse == null) throw new AuthFailureException("google 인증에 실패했습니다.");
val googleAccessToken = googleAccessTokenResponse.idToken();

val googleUserInfo = googleTokenManager.getUserInfo(googleAccessToken);
if (googleUserInfo == null) throw new WrongTokenException("Google AccessToken Invalid");
authUserId = googleUserInfo;
}
else if(Objects.equals(socialType, "apple")) {
val appleAccessTokenResponse = appleTokenManager.getAccessTokenByCode(code);
if (appleAccessTokenResponse == null) throw new AuthFailureException("apple 인증에 실패했습니다.");

val appleUserInfo = appleTokenManager.getUserInfo(appleAccessTokenResponse);
if (appleUserInfo == null) throw new WrongTokenException("Apple AccessToken Invalid");
authUserId = appleUserInfo;
}
if(authUserId == null) throw new AuthFailureException("잘못된 소셜로그인입니다.");
val member = memberRepository.save(
Member.builder()
.authUserId(authUserId)
.idpType(socialType)
.hasProfile(true)
.build()
);
return tokenManager.createAuthToken(member.getId());
}

@Transactional
public String registerByFbAndMagicRegisterToken(String registerToken, String code) {
val isMagic = tokenManager.verifyMagicRegisterToken(registerToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,6 @@ private JsonNode createTextFieldNode (String text) {
@Transactional
public Member updateMemberProfile (Long id, MemberProfileUpdateRequest request) {
val member = getMemberById(id);

if (!member.getEditActivitiesAble()) {
throw new ClientBadRequestException("이미 프로필을 수정한 적이 있는 유저입니다.");
}

val memberId = member.getId();
val memberLinks = memberLinkRepository.saveAll(
request.links().stream().map(link ->
Expand Down Expand Up @@ -331,7 +326,6 @@ public Member updateMemberProfile (Long id, MemberProfileUpdateRequest request)
request.selfIntroduction(), request.allowOfficial(),
memberActivities, memberLinks, memberCareers
);
member.editActivityChangeToFalse();
return member;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ naver-cloud-sms:
serviceId: test
oauth:
registerPage: testUrl
dev-register-magic-number: test
fb:
redirect:
auth: testUrl
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ naver-cloud-sms:
serviceId: test
oauth:
registerPage: testUrl
dev-register-magic-number: test
fb:
redirect:
auth: testUrl
Expand Down

0 comments on commit c5e23d9

Please sign in to comment.