mirror of
https://github.com/SOR2171/Springboot4-Vue3_Demo.git
synced 2026-10-23 19:41:12 +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,
|
||||||
|
|||||||
+32
-33
@@ -54,40 +54,39 @@ 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)
|
|
||||||
}
|
|
||||||
.flatMap { emailExists ->
|
|
||||||
if (emailExists) {
|
|
||||||
Mono.just("account with the same email already exists.")
|
|
||||||
} else {
|
|
||||||
accountService.existAccountByName(username).flatMap { usernameExists ->
|
|
||||||
if (usernameExists) {
|
|
||||||
Mono.just("username already exists.")
|
|
||||||
} else {
|
|
||||||
val account = Account(
|
|
||||||
id = null,
|
|
||||||
username = username,
|
|
||||||
password = encoder.encode(password)!!,
|
|
||||||
email = email,
|
|
||||||
role = "user",
|
|
||||||
registerTime = getCurrentDateTime()
|
|
||||||
)
|
|
||||||
|
|
||||||
Mono.fromCallable { accountService.save(account) }
|
|
||||||
.flatMap { success ->
|
|
||||||
if (success) {
|
|
||||||
stringRedisTemplate.delete(Const.VERIFY_EMAIL_DATA + email)
|
|
||||||
.thenReturn("")
|
|
||||||
} else {
|
|
||||||
Const.INTERNAL_ERROR_MONO
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
accountService.existAccountByEmail(email)
|
||||||
|
.flatMap { emailExists ->
|
||||||
|
if (emailExists) {
|
||||||
|
return@flatMap Mono.just("account with the same email already exists.")
|
||||||
|
}
|
||||||
|
accountService.existAccountByName(username)
|
||||||
|
.flatMap { usernameExists ->
|
||||||
|
if (usernameExists) {
|
||||||
|
return@flatMap Mono.just("username already exists.")
|
||||||
|
}
|
||||||
|
val account = Account(
|
||||||
|
id = null,
|
||||||
|
username = username,
|
||||||
|
password = encoder.encode(password)!!,
|
||||||
|
email = email,
|
||||||
|
role = "user",
|
||||||
|
registerTime = getCurrentDateTime()
|
||||||
|
)
|
||||||
|
Mono.fromCallable { accountService.save(account) }
|
||||||
|
.flatMap { success ->
|
||||||
|
if (success) {
|
||||||
|
stringRedisTemplate.delete(Const.VERIFY_EMAIL_DATA + email)
|
||||||
|
.thenReturn("")
|
||||||
|
} else {
|
||||||
|
Const.INTERNAL_ERROR_MONO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user