diff --git a/backend/src/main/kotlin/com/github/sor2171/backend/controller/v1/AuthorizeController.kt b/backend/src/main/kotlin/com/github/sor2171/backend/controller/v1/AuthorizeController.kt index 3f16a6c..c26d5b6 100644 --- a/backend/src/main/kotlin/com/github/sor2171/backend/controller/v1/AuthorizeController.kt +++ b/backend/src/main/kotlin/com/github/sor2171/backend/controller/v1/AuthorizeController.kt @@ -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 { diff --git a/backend/src/main/kotlin/com/github/sor2171/backend/service/impl/AccountServiceImpl.kt b/backend/src/main/kotlin/com/github/sor2171/backend/service/impl/AccountServiceImpl.kt index 129147a..9b1896d 100644 --- a/backend/src/main/kotlin/com/github/sor2171/backend/service/impl/AccountServiceImpl.kt +++ b/backend/src/main/kotlin/com/github/sor2171/backend/service/impl/AccountServiceImpl.kt @@ -57,9 +57,6 @@ class AccountServiceImpl : ServiceImpl(), AccountService ): Mono = Mono.fromCallable(block) .subscribeOn(Schedulers.boundedElastic()) - .flatMap { - Mono.just(it) - } private fun findAccount( fieldName: String, diff --git a/backend/src/main/kotlin/com/github/sor2171/backend/service/v1/AuthorizationService.kt b/backend/src/main/kotlin/com/github/sor2171/backend/service/v1/AuthorizationService.kt index 005f3e5..fcc9e7b 100644 --- a/backend/src/main/kotlin/com/github/sor2171/backend/service/v1/AuthorizationService.kt +++ b/backend/src/main/kotlin/com/github/sor2171/backend/service/v1/AuthorizationService.kt @@ -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 + } + } + } + } } }