added basic create account

- add link in to creat in users.html
- AccountController
  - add getCreateAccount
  - add postCreateAccount
- add create.html
- add AccountForm to Account Request in Mapping.kt
- add AccountForm
- add addAccount to AccountRegistryService
- add accountRegistryCreate to WebClientCalls.kt
- add UsernameDuplicateException
- add AccountRegistryException
- add HlaejaException
This commit is contained in:
2025-01-27 11:39:04 +01:00
parent 34349653db
commit 8e65de0350
11 changed files with 240 additions and 6 deletions

View File

@@ -1,10 +1,18 @@
package ltd.hlaeja.util
import org.springframework.security.core.Authentication as SpringAuthentication
import ltd.hlaeja.form.AccountForm
import ltd.hlaeja.library.accountRegistry.Account
import ltd.hlaeja.library.accountRegistry.Authentication
import org.springframework.security.core.Authentication as SpringAuthentication
fun SpringAuthentication.toAuthenticationRequest(): Authentication.Request = Authentication.Request(
principal as String,
credentials as String,
)
fun AccountForm.toAccountRequest(): Account.Request = Account.Request(
username = username,
password = password,
enabled = enabled,
roles = listOf("ROLE_${role.uppercase()}"),
)

View File

@@ -1,8 +1,12 @@
package ltd.hlaeja.util
import ltd.hlaeja.exception.AccountRegistryException
import ltd.hlaeja.exception.UsernameDuplicateException
import ltd.hlaeja.library.accountRegistry.Account
import ltd.hlaeja.library.accountRegistry.Authentication
import ltd.hlaeja.property.AccountRegistryProperty
import org.springframework.http.HttpStatus.BAD_REQUEST
import org.springframework.http.HttpStatus.CONFLICT
import org.springframework.http.HttpStatus.LOCKED
import org.springframework.http.HttpStatus.NOT_FOUND
import org.springframework.http.HttpStatus.UNAUTHORIZED
@@ -28,8 +32,19 @@ fun WebClient.accountRegistryAuthenticate(
fun WebClient.accountRegistryAccounts(
page: Int,
size: Int,
property: AccountRegistryProperty
property: AccountRegistryProperty,
): Flux<Account.Response> = get()
.uri("${property.url}/accounts?page=$page&size=$size".also(::logCall))
.retrieve()
.bodyToFlux(Account.Response::class.java)
fun WebClient.accountRegistryCreate(
request: Account.Request,
property: AccountRegistryProperty,
): Mono<Account.Response> = post()
.uri("${property.url}/account".also(::logCall))
.bodyValue(request)
.retrieve()
.onStatus(CONFLICT::equals) { throw UsernameDuplicateException() }
.onStatus(BAD_REQUEST::equals) { throw AccountRegistryException("Remote service returned 400") }
.bodyToMono(Account.Response::class.java)