Skip to content

Commit

Permalink
iOS 요청사항 처리 (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
kih00 authored Feb 1, 2025
1 parent 7ad809a commit 7a0afba
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +10,7 @@ class User(
val userNumber: Int,
val email: String,
val nickname: String,
val isSocial: Boolean,
val createdAt: Instant
) {
companion object {
Expand All @@ -18,6 +20,7 @@ class User(
userNumber = entity.userNumber,
email = entity.email,
nickname = entity.nickname,
isSocial = (entity.socialType != null),
createdAt = entity.createdAt
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -123,6 +125,7 @@ class UserService(
password: String
): Triple<User, String, String> {
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(
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7a0afba

Please sign in to comment.