-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from JNU-econovation/member
Member 관련 작업
- Loading branch information
Showing
94 changed files
with
802 additions
and
318 deletions.
There are no files selected for viewing
This file contains 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
7 changes: 0 additions & 7 deletions
7
modules/domain/src/main/java/com/whoz_in/domain/member/Member.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
modules/domain/src/main/java/com/whoz_in/domain/member/MemberRepository.java
This file contains 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 |
---|---|---|
@@ -1,5 +1,13 @@ | ||
package com.whoz_in.domain.member; | ||
|
||
import com.whoz_in.domain.member.exception.NoMemberException; | ||
import com.whoz_in.domain.member.model.Member; | ||
import java.util.Optional; | ||
|
||
public interface MemberRepository { | ||
void save(Member member); | ||
Optional<Member> findByLoginId(String loginId); | ||
default Member getByLoginId(String loginId){ | ||
return findByLoginId(loginId).orElseThrow(NoMemberException::new); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
modules/domain/src/main/java/com/whoz_in/domain/member/event/MemberCreated.java
This file contains 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.whoz_in.domain.member.event; | ||
|
||
import com.whoz_in.domain.member.model.Member; | ||
import com.whoz_in.domain.shared.event.DomainEvent; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public final class MemberCreated extends DomainEvent { | ||
private final Member member; | ||
} |
13 changes: 13 additions & 0 deletions
13
modules/domain/src/main/java/com/whoz_in/domain/member/event/MemberPasswordChanged.java
This file contains 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,13 @@ | ||
package com.whoz_in.domain.member.event; | ||
|
||
import com.whoz_in.domain.member.model.MemberId; | ||
import com.whoz_in.domain.shared.event.DomainEvent; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public final class MemberPasswordChanged extends DomainEvent { | ||
private final MemberId memberId; | ||
private final String newPassword; | ||
} |
13 changes: 13 additions & 0 deletions
13
modules/domain/src/main/java/com/whoz_in/domain/member/event/MemberStatusMessageChanged.java
This file contains 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,13 @@ | ||
package com.whoz_in.domain.member.event; | ||
|
||
import com.whoz_in.domain.member.model.MemberId; | ||
import com.whoz_in.domain.shared.event.DomainEvent; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public final class MemberStatusMessageChanged extends DomainEvent { | ||
private final MemberId memberId; | ||
private final String statusMessage; | ||
} |
10 changes: 10 additions & 0 deletions
10
...in/src/main/java/com/whoz_in/domain/member/exception/InvalidAuthCredentialsException.java
This file contains 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,10 @@ | ||
package com.whoz_in.domain.member.exception; | ||
|
||
import com.whoz_in.domain.shared.BusinessException; | ||
|
||
public class InvalidAuthCredentialsException extends BusinessException { | ||
|
||
public InvalidAuthCredentialsException() { | ||
super("2003", "아이디 혹은 비밀번호가 틀렸습니다."); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...in/src/main/java/com/whoz_in/domain/member/exception/LoginIdPolicyViolationException.java
This file contains 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,10 @@ | ||
package com.whoz_in.domain.member.exception; | ||
|
||
import com.whoz_in.domain.shared.BusinessException; | ||
|
||
public class LoginIdPolicyViolationException extends BusinessException { | ||
|
||
public LoginIdPolicyViolationException() { | ||
super("2001", "아이디는 알파벳 소문자, 숫자로 6자리 이상 16자리 이하여야 합니다."); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
modules/domain/src/main/java/com/whoz_in/domain/member/exception/NoMemberException.java
This file contains 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,10 @@ | ||
package com.whoz_in.domain.member.exception; | ||
|
||
import com.whoz_in.domain.shared.BusinessException; | ||
|
||
public class NoMemberException extends BusinessException { | ||
|
||
public NoMemberException() { | ||
super("2008", "존재하지 않는 멤버입니다."); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
modules/domain/src/main/java/com/whoz_in/domain/member/exception/NotAuthMemberException.java
This file contains 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,9 @@ | ||
package com.whoz_in.domain.member.exception; | ||
|
||
import com.whoz_in.domain.shared.BusinessException; | ||
|
||
public class NotAuthMemberException extends BusinessException { | ||
public NotAuthMemberException() { | ||
super("2006", "일반 로그인 정보가 없는 회원입니다."); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...les/domain/src/main/java/com/whoz_in/domain/member/exception/NotOAuthMemberException.java
This file contains 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,10 @@ | ||
package com.whoz_in.domain.member.exception; | ||
|
||
import com.whoz_in.domain.shared.BusinessException; | ||
|
||
public class NotOAuthMemberException extends BusinessException { | ||
|
||
public NotOAuthMemberException() { | ||
super("2007", "소셜 로그인 정보가 없는 회원입니다."); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...n/src/main/java/com/whoz_in/domain/member/exception/PasswordPolicyViolationException.java
This file contains 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,10 @@ | ||
package com.whoz_in.domain.member.exception; | ||
|
||
import com.whoz_in.domain.shared.BusinessException; | ||
|
||
public class PasswordPolicyViolationException extends BusinessException { | ||
|
||
public PasswordPolicyViolationException() { | ||
super("2002", "비밀번호는 알파벳 소문자, 숫자로 6자리 이상 16자리 이하여야 합니다."); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
modules/domain/src/main/java/com/whoz_in/domain/member/exception/WrongPasswordException.java
This file contains 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,10 @@ | ||
package com.whoz_in.domain.member.exception; | ||
|
||
import com.whoz_in.domain.shared.BusinessException; | ||
|
||
public class WrongPasswordException extends BusinessException { | ||
|
||
public WrongPasswordException() { | ||
super("2005", "틀린 비밀번호입니다."); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
modules/domain/src/main/java/com/whoz_in/domain/member/model/AuthCredentials.java
This file contains 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,50 @@ | ||
package com.whoz_in.domain.member.model; | ||
|
||
import com.whoz_in.domain.member.exception.InvalidAuthCredentialsException; | ||
import com.whoz_in.domain.member.exception.LoginIdPolicyViolationException; | ||
import com.whoz_in.domain.member.exception.PasswordPolicyViolationException; | ||
import com.whoz_in.domain.member.exception.WrongPasswordException; | ||
import com.whoz_in.domain.member.service.PasswordEncoder; | ||
import java.util.regex.Pattern; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
//일반 로그인 정보 | ||
@Getter | ||
@EqualsAndHashCode | ||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class AuthCredentials { | ||
private static final String LOGIN_ID_REGEX = "^(?=.*[a-z])(?=.*\\d)[a-zA-Z\\d]{6,16}$"; | ||
private static final String PASSWORD_REGEX = "^(?=.*[a-z])(?=.*\\d)[a-zA-Z\\d]{6,16}$"; | ||
private final String loginId; | ||
private final String encodedPassword; | ||
|
||
public static AuthCredentials create(String loginId, String rawPassword, PasswordEncoder passwordEncoder){ | ||
//아이디가 정책에 맞는지 확인 | ||
if (!Pattern.matches(LOGIN_ID_REGEX, loginId)) | ||
throw new LoginIdPolicyViolationException(); | ||
//비밀번호가 정책에 맞는지 확인 | ||
if (!Pattern.matches(PASSWORD_REGEX, rawPassword)) | ||
throw new PasswordPolicyViolationException(); | ||
return new AuthCredentials(loginId, passwordEncoder.encode(rawPassword)); | ||
} | ||
|
||
public static AuthCredentials load(String loginId, String encodedPassword){ | ||
if (loginId == null || encodedPassword == null) | ||
throw new IllegalStateException("no login id or encoded password"); | ||
return new AuthCredentials(loginId, encodedPassword); | ||
} | ||
|
||
AuthCredentials changePassword(String rawOldPassword, String rawNewPassword, PasswordEncoder passwordEncoder){ | ||
String encodedOldPassword = passwordEncoder.encode(rawOldPassword); | ||
//기존 비밀번호가 같은지 확인 | ||
if (!encodedPassword.equals(encodedOldPassword)) | ||
throw new WrongPasswordException(); | ||
//새로운 비밀번호가 정책에 맞는지 확인 | ||
if (!Pattern.matches(PASSWORD_REGEX, rawNewPassword)) | ||
throw new PasswordPolicyViolationException(); | ||
return new AuthCredentials(this.loginId, passwordEncoder.encode(rawNewPassword)); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
modules/domain/src/main/java/com/whoz_in/domain/member/model/Member.java
This file contains 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,85 @@ | ||
package com.whoz_in.domain.member.model; | ||
|
||
import com.whoz_in.domain.member.event.MemberCreated; | ||
import com.whoz_in.domain.member.event.MemberPasswordChanged; | ||
import com.whoz_in.domain.member.event.MemberStatusMessageChanged; | ||
import com.whoz_in.domain.member.exception.NotAuthMemberException; | ||
import com.whoz_in.domain.member.service.PasswordEncoder; | ||
import com.whoz_in.domain.shared.AggregateRoot; | ||
import com.whoz_in.domain.shared.Nullable; | ||
import java.util.Optional; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class Member extends AggregateRoot { | ||
@Getter private final MemberId id; | ||
@Getter private final String name; //실명 | ||
@Getter private final Position mainPosition; | ||
@Getter private final int generation; //기수 | ||
@Getter private String statusMessage; //상태 메세지 | ||
@Nullable private AuthCredentials authCredentials; | ||
@Nullable private OAuthCredentials oAuthCredentials; | ||
|
||
//일반 로그인이 아닐수도 있으므로 Optional | ||
public Optional<AuthCredentials> getAuthCredentials(){ | ||
return Optional.ofNullable(authCredentials); | ||
} | ||
//소셜 로그인이 아닐수도 있으므로 Optional | ||
public Optional<OAuthCredentials> getOAuthCredentials(){ | ||
return Optional.ofNullable(oAuthCredentials); | ||
} | ||
|
||
//일반 회원가입 | ||
public static Member create(String name, Position mainPosition, int generation, AuthCredentials authCredentials){ | ||
return create(name, mainPosition, generation, authCredentials, null); | ||
} | ||
//소셜 회원가입 | ||
public static Member create(String name, Position mainPosition, int generation, OAuthCredentials oAuthCredentials){ | ||
return create(name, mainPosition, generation, null, oAuthCredentials); | ||
} | ||
private static Member create(String name, Position mainPosition, int generation, | ||
AuthCredentials authCredentials, OAuthCredentials oAuthCredentials){ | ||
if (authCredentials == null && oAuthCredentials == null) | ||
throw new IllegalStateException("no auth and oauth"); | ||
Member member = builder() | ||
.id(new MemberId()) | ||
.name(name) | ||
.mainPosition(mainPosition) | ||
.generation(generation) | ||
.statusMessage("") | ||
.authCredentials(authCredentials) | ||
.oAuthCredentials(oAuthCredentials) | ||
.build(); | ||
member.register(new MemberCreated(member)); | ||
return member; | ||
} | ||
|
||
public static Member load(MemberId id, String name, Position mainPosition, int generation, String statusMessage, | ||
AuthCredentials authCredentials, OAuthCredentials oAuthCredentials){ | ||
return builder() | ||
.id(id) | ||
.name(name) | ||
.mainPosition(mainPosition) | ||
.generation(generation) | ||
.statusMessage(statusMessage) | ||
.authCredentials(authCredentials) | ||
.oAuthCredentials(oAuthCredentials) | ||
.build(); | ||
} | ||
|
||
public void changePassword(String rawOldPassword, String rawNewPassword, PasswordEncoder passwordEncoder){ | ||
if (authCredentials == null) | ||
throw new NotAuthMemberException(); | ||
this.authCredentials = this.authCredentials.changePassword(rawOldPassword, rawNewPassword, passwordEncoder); | ||
this.register(new MemberPasswordChanged(this.getId(), this.authCredentials.getEncodedPassword())); | ||
} | ||
|
||
public void changeStatusMessage(String newStatusMessage){ | ||
this.statusMessage = newStatusMessage; | ||
this.register(new MemberStatusMessageChanged(this.getId(), this.statusMessage)); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
modules/domain/src/main/java/com/whoz_in/domain/member/model/MemberId.java
This file contains 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,14 @@ | ||
package com.whoz_in.domain.member.model; | ||
|
||
import java.util.UUID; | ||
|
||
public record MemberId(UUID id) { | ||
public MemberId() { | ||
this(UUID.randomUUID()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return id.toString(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
modules/domain/src/main/java/com/whoz_in/domain/member/model/OAuthCredentials.java
This file contains 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,21 @@ | ||
package com.whoz_in.domain.member.model; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
//소셜 로그인 정보 | ||
@Getter | ||
@EqualsAndHashCode | ||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class OAuthCredentials { | ||
private final SocialProvider socialProvider; | ||
private final String socialId; | ||
|
||
public static OAuthCredentials load(SocialProvider socialProvider, String socialId){ | ||
if (socialProvider == null || socialId == null) | ||
throw new IllegalStateException("no social provider or social id"); | ||
return new OAuthCredentials(socialProvider, socialId); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
modules/domain/src/main/java/com/whoz_in/domain/member/model/Position.java
This file contains 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,10 @@ | ||
package com.whoz_in.domain.member.model; | ||
|
||
public enum Position { | ||
AI, | ||
BE, | ||
DE, | ||
FE, | ||
PM, | ||
GAME | ||
} |
5 changes: 5 additions & 0 deletions
5
modules/domain/src/main/java/com/whoz_in/domain/member/model/SocialProvider.java
This file contains 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,5 @@ | ||
package com.whoz_in.domain.member.model; | ||
|
||
public enum SocialProvider { | ||
KAKAO | ||
} |
9 changes: 9 additions & 0 deletions
9
modules/domain/src/main/java/com/whoz_in/domain/member/service/MemberIdGenerator.java
This file contains 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,9 @@ | ||
//package com.whoz_in.domain.member.service; | ||
// | ||
//import com.whoz_in.domain.member.model.MemberId; | ||
|
||
|
||
//TODO: db의 힘을 빌려야 할거 같을 때 | ||
//public interface MemberIdGenerator{ | ||
// MemberId next(); | ||
//} |
5 changes: 5 additions & 0 deletions
5
modules/domain/src/main/java/com/whoz_in/domain/member/service/PasswordEncoder.java
This file contains 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,5 @@ | ||
package com.whoz_in.domain.member.service; | ||
|
||
public interface PasswordEncoder { | ||
String encode(String plainText); | ||
} |
Oops, something went wrong.