added basic edit account
- add link in to edit a user in users.html - change to AccountController - update getCreateAccount for change to AccountForm - add getEditAccount - add edit.html - change to Mapping.kt - update AccountForm toAccountRequest to throw exception if password null - add Account Response toAccountForm - change password and passwordConfirm to be null in AccountForm - add PasswordException - add getAccount to AccountRegistryService - add accountRegistryAccount to WebClientCalls.kt
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package ltd.hlaeja.util
|
||||
|
||||
import ltd.hlaeja.exception.PasswordException
|
||||
import ltd.hlaeja.form.AccountForm
|
||||
import ltd.hlaeja.library.accountRegistry.Account
|
||||
import ltd.hlaeja.library.accountRegistry.Authentication
|
||||
@@ -12,7 +13,13 @@ fun SpringAuthentication.toAuthenticationRequest(): Authentication.Request = Aut
|
||||
|
||||
fun AccountForm.toAccountRequest(): Account.Request = Account.Request(
|
||||
username = username,
|
||||
password = password,
|
||||
password = password ?: throw PasswordException("Password requirements failed"),
|
||||
enabled = enabled,
|
||||
roles = listOf("ROLE_${role.uppercase()}"),
|
||||
)
|
||||
|
||||
fun Account.Response.toAccountForm(): AccountForm = AccountForm(
|
||||
username = username,
|
||||
enabled = enabled,
|
||||
role = roles.first().removePrefix("ROLE_").lowercase()
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ltd.hlaeja.util
|
||||
|
||||
import java.util.UUID
|
||||
import ltd.hlaeja.exception.AccountRegistryException
|
||||
import ltd.hlaeja.exception.UsernameDuplicateException
|
||||
import ltd.hlaeja.library.accountRegistry.Account
|
||||
@@ -14,6 +15,7 @@ import org.springframework.security.authentication.BadCredentialsException
|
||||
import org.springframework.security.authentication.LockedException
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException
|
||||
import org.springframework.web.reactive.function.client.WebClient
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@@ -48,3 +50,12 @@ fun WebClient.accountRegistryCreate(
|
||||
.onStatus(CONFLICT::equals) { throw UsernameDuplicateException() }
|
||||
.onStatus(BAD_REQUEST::equals) { throw AccountRegistryException("Remote service returned 400") }
|
||||
.bodyToMono(Account.Response::class.java)
|
||||
|
||||
fun WebClient.accountRegistryAccount(
|
||||
account: UUID,
|
||||
property: AccountRegistryProperty,
|
||||
): Mono<Account.Response> = get()
|
||||
.uri("${property.url}/account-$account".also(::logCall))
|
||||
.retrieve()
|
||||
.onStatus(NOT_FOUND::equals) { throw ResponseStatusException(NOT_FOUND) }
|
||||
.bodyToMono(Account.Response::class.java)
|
||||
|
||||
Reference in New Issue
Block a user