From ffc9590db54771b5ddea0dd63305c365b3b49849 Mon Sep 17 00:00:00 2001 From: kih00 Date: Sat, 1 Feb 2025 21:07:26 +0900 Subject: [PATCH] =?UTF-8?q?iOS=20=EC=9A=94=EC=B2=AD=EC=82=AC=ED=95=AD=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memoWithTags/exception/UserExceptions.kt | 13 +++++++++++-- .../toyproject/memoWithTags/user/controller/User.kt | 3 +++ .../memoWithTags/user/service/UserService.kt | 7 +++++-- src/main/resources/application-dev.yml | 2 +- src/main/resources/application-prod.yml | 2 +- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/exception/UserExceptions.kt b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/exception/UserExceptions.kt index 659b11f..87dba83 100644 --- a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/exception/UserExceptions.kt +++ b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/exception/UserExceptions.kt @@ -57,12 +57,21 @@ class OAuthRequestException : UserException( msg = "소셜 로그인 요청에 실패했습니다." ) +// 비밀번호 변경 시 잘못된 비밀번호 입력 +class UpdatePasswordInvalidException : UserException( + errorCode = 0, + httpErrorCode = HttpStatus.FORBIDDEN, + msg = "잘못된 비밀번호입니다." +) + +// 회원 탈퇴 시 이메일을 잘못 입력 class EmailNotMatchException : UserException( errorCode = 0, - httpErrorCode = HttpStatus.BAD_REQUEST, - msg = "업데이트 할 유저 이메일이 기존 이메일과 일치하지 않습니다" + httpErrorCode = HttpStatus.NOT_FOUND, + msg = "입력한 이메일이 유저의 이메일과 일치하지 않습니다" ) +// Admin 권한 없음 class UserNotAdminException : UserException( errorCode = 0, httpErrorCode = HttpStatus.BAD_REQUEST, diff --git a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/user/controller/User.kt b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/user/controller/User.kt index 629cbca..847e658 100644 --- a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/user/controller/User.kt +++ b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/user/controller/User.kt @@ -1,5 +1,6 @@ package com.wafflestudio.toyproject.memoWithTags.user.controller +import com.wafflestudio.toyproject.memoWithTags.user.SocialType import com.wafflestudio.toyproject.memoWithTags.user.persistence.UserEntity import java.time.Instant import java.util.UUID @@ -9,6 +10,7 @@ class User( val userNumber: Int, val email: String, val nickname: String, + val isSocial: Boolean, val createdAt: Instant ) { companion object { @@ -18,6 +20,7 @@ class User( userNumber = entity.userNumber, email = entity.email, nickname = entity.nickname, + isSocial = (entity.socialType != null), createdAt = entity.createdAt ) } diff --git a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/user/service/UserService.kt b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/user/service/UserService.kt index ad97b4f..42b298c 100644 --- a/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/user/service/UserService.kt +++ b/src/main/kotlin/com/wafflestudio/toyproject/memoWithTags/user/service/UserService.kt @@ -2,10 +2,12 @@ package com.wafflestudio.toyproject.memoWithTags.user.service import com.wafflestudio.toyproject.memoWithTags.exception.AuthenticationFailedException import com.wafflestudio.toyproject.memoWithTags.exception.EmailAlreadyExistsException +import com.wafflestudio.toyproject.memoWithTags.exception.EmailNotMatchException import com.wafflestudio.toyproject.memoWithTags.exception.EmailSendingException import com.wafflestudio.toyproject.memoWithTags.exception.InValidTokenException import com.wafflestudio.toyproject.memoWithTags.exception.MailVerificationException import com.wafflestudio.toyproject.memoWithTags.exception.SignInInvalidException +import com.wafflestudio.toyproject.memoWithTags.exception.UpdatePasswordInvalidException import com.wafflestudio.toyproject.memoWithTags.exception.UserNotFoundException import com.wafflestudio.toyproject.memoWithTags.mail.EmailVerification import com.wafflestudio.toyproject.memoWithTags.mail.persistence.EmailVerificationEntity @@ -123,6 +125,7 @@ class UserService( password: String ): Triple { val userEntity = userRepository.findByEmail(email) ?: throw SignInInvalidException() + if (userEntity.socialType != null) throw SignInInvalidException() if (!BCrypt.checkpw(password, userEntity.hashedPassword)) throw SignInInvalidException() logger.info("User logged in: ${userEntity.id}, ${userEntity.email}") return Triple( @@ -171,7 +174,7 @@ class UserService( newPassword: String ): User { val userEntity = userRepository.findByEmail(user.email) ?: throw UserNotFoundException() - if (!BCrypt.checkpw(originalPassword, userEntity.hashedPassword)) throw SignInInvalidException() + if (!BCrypt.checkpw(originalPassword, userEntity.hashedPassword)) throw UpdatePasswordInvalidException() userEntity.hashedPassword = BCrypt.hashpw(newPassword, BCrypt.gensalt()) return User.fromEntity(userRepository.save(userEntity)) } @@ -218,7 +221,7 @@ class UserService( user: User, email: String ) { - if (user.email != email) throw AuthenticationFailedException() + if (user.email != email) throw EmailNotMatchException() userRepository.deleteById(user.id) } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index cfc8547..b48f3d9 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -6,7 +6,7 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: - ddl-auto: update + ddl-auto: create-drop show-sql: true config: diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 24e727b..46fde0d 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -9,7 +9,7 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: - ddl-auto: create # or validate, none + ddl-auto: update # or validate, none properties: hibernate: format_sql: true