mirror of
https://github.com/SOR2171/Springboot4-Vue3_Demo.git
synced 2026-10-26 21:11:10 +08:00
refactor: AuthorizationService.kt
This commit is contained in:
+1
-1
@@ -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,
|
||||||
|
|||||||
+10
-11
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user