Skip to content

Commit

Permalink
Re Sign-up a user who previously left (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
inh2613 authored Oct 22, 2023
2 parents 69128bf + 337fb89 commit 82ecbe8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
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

0 comments on commit 82ecbe8

Please sign in to comment.