Skip to content
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

Re Sign-up a user who previously left #135

Merged
merged 4 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class User extends BaseTimeEntity implements UserDetails {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(length = 60, nullable = false, unique = true)
@Column(length = 60, nullable = false)
private String username;

@Column(length = 60)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public interface UserRepository extends JpaRepository<User, Long> {
User findByUsername(String username);

User findByNickname(String nickname);

User findByUsernameAndDeletedAtIsNull(String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class AuthService {
public JwtTokenDto signUp(SignUpDto signUpDto) {
User user = User.builder()
.username(signUpDto.getUsername())
.password(passwordEncoder.encode(signUpDto.getPassword()))
.password(signUpDto.getPassword())
.nickname(signUpDto.getNickname())
.role(Role.USER)
.build();
Expand Down Expand Up @@ -132,7 +132,7 @@ private JwtTokenDto generateJwtTokenDto(User user) {
*/
@Transactional
public void signOut(String username, SignOutDto signOutDto) {
User user = userRepository.findByUsername(username);
User user = userRepository.findByUsernameAndDeletedAtIsNull(username);
if (user == null || user.getDeletedAt() != null) {
throw new BusinessException("존재하지 않는 사용자입니다.", StatusEnum.UNAUTHORIZED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public User create(User user) {
}

public boolean isDuplicateUsername(String username) {
return userRepository.findByUsername(username) != null;
return userRepository.findByUsernameAndDeletedAtIsNull(username) != null;
}

public boolean isValidatePassword(String password) {
Expand All @@ -74,7 +74,7 @@ public boolean isValidatePassword(String password) {
}

public User read(String username) {
User user = userRepository.findByUsername(username);
User user = userRepository.findByUsernameAndDeletedAtIsNull(username);
if (user == null) {
throw new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND);
}
Expand Down Expand Up @@ -104,7 +104,7 @@ public List<User> list() {
}

public UserUpdateResponseDto update(String username, Long userId, UserUpdateRequestDto userUpdateRequestDto) {
User user = userRepository.findByUsername(username);
User user = userRepository.findByUsernameAndDeletedAtIsNull(username);
if (user == null) {
throw new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND);
}
Expand Down Expand Up @@ -166,7 +166,11 @@ public OAuth deleteOAuthInfo(User user, OAuthPlatform oAuthPlatform) {

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
return userRepository.findByUsername(username).getDeletedAt() == null ? userRepository.findByUsername(username) : null;
User user = userRepository.findByUsernameAndDeletedAtIsNull(username);
if (user == null) {
throw new UsernameNotFoundException("존재하지 않는 회원입니다.");
}
return user;
}

public List<OAuth> deleteOAuthInfo(User user) {
Expand Down