77import com .back .web7_9_codecrete_be .domain .users .entity .User ;
88import com .back .web7_9_codecrete_be .domain .users .repository .UserRepository ;
99import com .back .web7_9_codecrete_be .global .error .code .AuthErrorCode ;
10+ import com .back .web7_9_codecrete_be .global .error .code .UserErrorCode ;
1011import com .back .web7_9_codecrete_be .global .error .exception .BusinessException ;
1112import lombok .RequiredArgsConstructor ;
1213import org .springframework .security .crypto .password .PasswordEncoder ;
1314import org .springframework .stereotype .Service ;
15+ import org .springframework .transaction .annotation .Transactional ;
1416
1517import java .security .SecureRandom ;
1618import java .time .LocalDate ;
1719
1820@ Service
1921@ RequiredArgsConstructor
22+ @ Transactional
2023public class AuthService {
2124 private final UserRepository userRepository ;
2225 private final PasswordEncoder passwordEncoder ;
@@ -38,7 +41,7 @@ public void signUp(SignupRequest req) {
3841
3942 // 닉네임 중복 체크
4043 if (userRepository .existsByNickname (req .getNickname ())) {
41- throw new BusinessException (AuthErrorCode .NICKNAME_DUPLICATED );
44+ throw new BusinessException (UserErrorCode .NICKNAME_DUPLICATED );
4245 }
4346
4447 User user = User .builder ()
@@ -59,6 +62,10 @@ public LoginResponse login(LoginRequest req) {
5962 User user = userRepository .findByEmail (req .getEmail ())
6063 .orElseThrow (() -> new BusinessException (AuthErrorCode .USER_NOT_FOUND ));
6164
65+ if (user .getIsDeleted ()) {
66+ throw new BusinessException (UserErrorCode .USER_DELETED );
67+ }
68+
6269 if (!passwordEncoder .matches (req .getPassword (), user .getPassword ())) {
6370 throw new BusinessException (AuthErrorCode .INVALID_PASSWORD );
6471 }
@@ -87,6 +94,10 @@ public void resetPassword(String email) {
8794 User user = userRepository .findByEmail (email )
8895 .orElseThrow (() -> new BusinessException (AuthErrorCode .USER_NOT_FOUND ));
8996
97+ if (user .getIsDeleted ()) {
98+ throw new BusinessException (UserErrorCode .USER_DELETED );
99+ }
100+
90101 String tempPassword = generateTempPassword ();
91102
92103 // 비밀번호 변경
0 commit comments