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

iOS 요청사항 처리 #90

Merged
merged 1 commit into from
Feb 1, 2025
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 @@ -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
2 changes: 1 addition & 1 deletion src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading