-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#53): converted user service classes java to kotlin
- Loading branch information
1 parent
7ad0d73
commit 0e3c52a
Showing
10 changed files
with
258 additions
and
268 deletions.
There are no files selected for viewing
83 changes: 0 additions & 83 deletions
83
archive-application/src/main/java/site/archive/service/user/UserAuthService.java
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
archive-application/src/main/java/site/archive/service/user/UserProfileImageService.java
This file was deleted.
Oops, something went wrong.
58 changes: 0 additions & 58 deletions
58
archive-application/src/main/java/site/archive/service/user/UserRegisterServiceV1.java
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
archive-application/src/main/java/site/archive/service/user/UserRegisterServiceV2.java
This file was deleted.
Oops, something went wrong.
60 changes: 0 additions & 60 deletions
60
archive-application/src/main/java/site/archive/service/user/UserService.java
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
archive-application/src/main/kotlin/site/archive/service/user/UserAuthService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package site.archive.service.user | ||
|
||
import org.springframework.security.crypto.password.PasswordEncoder | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import site.archive.common.exception.common.ResourceNotFoundException | ||
import site.archive.common.exception.common.UnauthorizedResourceException | ||
import site.archive.common.exception.user.LoginFailException | ||
import site.archive.common.exception.user.OAuthUserHasNotPasswordException | ||
import site.archive.domain.user.BaseUser | ||
import site.archive.domain.user.PasswordUser | ||
import site.archive.domain.user.PasswordUserRepository | ||
import site.archive.domain.user.UserInfo | ||
import site.archive.domain.user.UserRepository | ||
import site.archive.dto.v1.auth.LoginCommandV1 | ||
import site.archive.dto.v1.user.UserPasswordResetRequestDtoV1 | ||
import site.archive.infra.mail.MailService | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
class UserAuthService( | ||
val userRepository: UserRepository, | ||
val passwordUserRepository: PasswordUserRepository, | ||
val encoder: PasswordEncoder, | ||
val mailService: MailService | ||
) { | ||
|
||
fun tryLoginAndReturnInfo(command: LoginCommandV1): UserInfo { | ||
val user = verifyPasswordReturnUser(command.email, command.password) | ||
return user.convertToUserInfo() | ||
} | ||
|
||
@Transactional | ||
fun updateTemporaryPassword(email: String, temporaryPassword: String) { | ||
val passwordUser = userRepository.findByMailAddress(email) | ||
.map { convertPasswordUser(it) } | ||
.orElseThrow { ResourceNotFoundException("Email") } | ||
passwordUser.updatePassword(encoder.encode(temporaryPassword), true) | ||
mailService.sendTemporaryPassword(email, temporaryPassword) | ||
} | ||
|
||
@Transactional | ||
fun resetPassword(userInfo: UserInfo, userPasswordResetRequestDtoV1: UserPasswordResetRequestDtoV1) { | ||
if (userInfo.mailAddress != userPasswordResetRequestDtoV1.email) { | ||
throw UnauthorizedResourceException("ํด๋น ์ด๋ฉ์ผ์ ๋ํ ๋น๋ฐ๋ฒํธ ์ด๊ธฐํ ๊ถํ์ด ์์ต๋๋ค.") | ||
} | ||
this.resetPassword(userPasswordResetRequestDtoV1) | ||
} | ||
|
||
@Transactional | ||
fun resetPassword(userPasswordResetRequestDtoV1: UserPasswordResetRequestDtoV1) { | ||
val passwordUser = verifyPasswordReturnUser(userPasswordResetRequestDtoV1.email, userPasswordResetRequestDtoV1.currentPassword) | ||
passwordUser.updatePassword(encoder.encode(userPasswordResetRequestDtoV1.newPassword), false) | ||
} | ||
|
||
fun isTemporaryPasswordLogin(userId: Long): Boolean { | ||
return passwordUserRepository.findById(userId) | ||
.map(PasswordUser::isCurrentTemporaryPassword) | ||
.orElse(false) | ||
} | ||
|
||
private fun verifyPasswordReturnUser(email: String, password: String): PasswordUser { | ||
val user = passwordUserRepository.findByMailAddress(email) | ||
.orElseThrow { ResourceNotFoundException("Email") } | ||
if (!encoder.matches(password, user.password)) { | ||
throw LoginFailException("๋น๋ฐ๋ฒํธ๊ฐ ๋ค๋ฆ ๋๋ค") | ||
} | ||
return user | ||
} | ||
|
||
private fun convertPasswordUser(user: BaseUser): PasswordUser { | ||
if (user !is PasswordUser) { | ||
throw OAuthUserHasNotPasswordException() | ||
} | ||
return user | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
archive-application/src/main/kotlin/site/archive/service/user/UserProfileImageService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package site.archive.service.user | ||
|
||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import site.archive.domain.user.UserRepository | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
class UserProfileImageService(val userRepository: UserRepository) { | ||
|
||
@Transactional | ||
fun updateUserProfileImage(userId: Long, profileImageUri: String) { | ||
userRepository.updateUserProfileImage(userId, profileImageUri) | ||
} | ||
|
||
} |
Oops, something went wrong.