refactor: AuthorizationService.kt

This commit is contained in:
SOR
2026-07-27 12:59:04 +08:00
parent 531659a891
commit 350c6dde67
3 changed files with 33 additions and 37 deletions
@@ -66,7 +66,7 @@ class AuthorizeController(
return service return service
.jwtTokenRelogin(authorization) .jwtTokenRelogin(authorization)
?.map { ApiResponse.success(it) } ?.map { ApiResponse.success(it) }
?: Mono.just(messageHandler("Please login with password.")) ?: Mono.just(ApiResponse.failure(401, null, "Please login with password."))
} }
private fun messageHandler(wrongMessage: String): ApiResponse<Any?> { private fun messageHandler(wrongMessage: String): ApiResponse<Any?> {
@@ -57,9 +57,6 @@ class AccountServiceImpl : ServiceImpl<AccountMapper, Account>(), AccountService
): Mono<T> = ): Mono<T> =
Mono.fromCallable(block) Mono.fromCallable(block)
.subscribeOn(Schedulers.boundedElastic()) .subscribeOn(Schedulers.boundedElastic())
.flatMap {
Mono.just(it)
}
private fun findAccount( private fun findAccount(
fieldName: String, fieldName: String,
@@ -54,19 +54,20 @@ class AuthorizationService(
val (email, code, username, password) = vo val (email, code, username, password) = vo
return verifyCode(email, code) return verifyCode(email, code)
.filter { it.isBlank() } .flatMap { result ->
.switchIfEmpty(Mono.just("wrong code")) if (result.isNotBlank()) {
.flatMap { return@flatMap Mono.just(result)
accountService.existAccountByEmail(email)
} }
accountService.existAccountByEmail(email)
.flatMap { emailExists -> .flatMap { emailExists ->
if (emailExists) { if (emailExists) {
Mono.just("account with the same email already exists.") return@flatMap Mono.just("account with the same email already exists.")
} else { }
accountService.existAccountByName(username).flatMap { usernameExists -> accountService.existAccountByName(username)
.flatMap { usernameExists ->
if (usernameExists) { if (usernameExists) {
Mono.just("username already exists.") return@flatMap Mono.just("username already exists.")
} else { }
val account = Account( val account = Account(
id = null, id = null,
username = username, username = username,
@@ -75,7 +76,6 @@ class AuthorizationService(
role = "user", role = "user",
registerTime = getCurrentDateTime() registerTime = getCurrentDateTime()
) )
Mono.fromCallable { accountService.save(account) } Mono.fromCallable { accountService.save(account) }
.flatMap { success -> .flatMap { success ->
if (success) { if (success) {
@@ -89,7 +89,6 @@ class AuthorizationService(
} }
} }
} }
}
fun resetEmailAccountPassword(vo: PasswordResetVO): Mono<String> { fun resetEmailAccountPassword(vo: PasswordResetVO): Mono<String> {
val (email, code, password) = vo val (email, code, password) = vo