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

[NB-241] 회원탈퇴 후 로그인 시 예외 처리 구현 #62

Merged
merged 2 commits into from
Oct 18, 2024
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 @@ -24,6 +24,9 @@ public interface UserRepository extends JpaRepository<User, Long> {

Boolean existsByNickname(String nickname);

@Query(value = "SELECT EXISTS(SELECT 1 FROM users WHERE email = :email AND is_deleted = true)", nativeQuery = true)
Boolean existsByEmailAndIsDeletedTrue(String email);

Page<User> findByNicknameStartsWith(Pageable pageable, String query);

@Modifying
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/soyeon/nubim/domain/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.soyeon.nubim.domain.user.dto.ProfileUpdateRequest;
import com.soyeon.nubim.domain.user.dto.ProfileUpdateResponse;
import com.soyeon.nubim.domain.user.dto.UserProfileResponseDto;
import com.soyeon.nubim.domain.user.exception.DeletedUserSignupAttemptException;
import com.soyeon.nubim.domain.user.exception.InvalidNicknameFormatException;
import com.soyeon.nubim.domain.user.exception.MultipleProfileUpdateException;
import com.soyeon.nubim.domain.user.exception.NicknameAlreadyExistsException;
Expand Down Expand Up @@ -151,6 +152,12 @@ public ProfileUpdateResponse updateProfile(ProfileUpdateRequest updateRequest) {
throw new MultipleProfileUpdateException();
}

public void checkIfUserIsDeleted(String email) {
if (userRepository.existsByEmailAndIsDeletedTrue(email)) {
throw new DeletedUserSignupAttemptException(email);
}
}

private void validateProfileImageContentType(String contentType) {
if (contentType == null || !contentType.equals("image/png")) {
throw new UnsupportedProfileImageTypeException(contentType);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.soyeon.nubim.domain.user.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;

public class DeletedUserSignupAttemptException extends ResponseStatusException {
public DeletedUserSignupAttemptException(String email) {
super(HttpStatus.FORBIDDEN, "deleted account : " + email);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private User upsertUserFromAppleUserInfo(User user) {
existingUser.updateNameFromOAuthProfile(user.getUsername());
return userService.saveUser(existingUser);
} catch (UserNotFoundException e) {
userService.checkIfUserIsDeleted(user.getEmail());
return userService.saveUser(user);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private User upsertUserFromGoogleUserInfo(GoogleUserInfo userInfo) {
oAuthLoginCommons.validateUserProvider(user, Provider.GOOGLE);
user = user.updateNameFromOAuthProfile(userInfo.getName());
} catch (UserNotFoundException e) {
userService.checkIfUserIsDeleted(userInfo.getEmail());
user = userInfo.toUserEntity();
}
return userService.saveUser(user);
Expand Down