mirror of
https://github.com/SOR2171/Springboot4-Vue3_Demo.git
synced 2026-10-23 11:31:10 +08:00
refactor: AuthorizationService.kt
This commit is contained in:
+1
-1
@@ -66,7 +66,7 @@ class AuthorizeController(
|
||||
return service
|
||||
.jwtTokenRelogin(authorization)
|
||||
?.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?> {
|
||||
|
||||
@@ -57,9 +57,6 @@ class AccountServiceImpl : ServiceImpl<AccountMapper, Account>(), AccountService
|
||||
): Mono<T> =
|
||||
Mono.fromCallable(block)
|
||||
.subscribeOn(Schedulers.boundedElastic())
|
||||
.flatMap {
|
||||
Mono.just(it)
|
||||
}
|
||||
|
||||
private fun findAccount(
|
||||
fieldName: String,
|
||||
|
||||
+32
-33
@@ -54,40 +54,39 @@ class AuthorizationService(
|
||||
val (email, code, username, password) = vo
|
||||
|
||||
return verifyCode(email, code)
|
||||
.filter { it.isBlank() }
|
||||
.switchIfEmpty(Mono.just("wrong code"))
|
||||
.flatMap {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.flatMap { result ->
|
||||
if (result.isNotBlank()) {
|
||||
return@flatMap Mono.just(result)
|
||||
}
|
||||
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