Files
hlaeja-management/src/main/kotlin/ltd/hlaeja/util/Mapping.kt
Swordsteel 794c0c49d6 added basic edit save account
- changes to AccountController
  - added postEditAccount
  - change postCreateAccount to use lambda
- added success message to edit.html
- added lambda to deal with password to toAccountRequest in Mapping.kt
- added updateAccount to AccountRegistryService
- added accountRegistryUpdate to WebClientCalls.kt
- added NoChangeException
- added NotFoundException
2025-01-28 21:54:16 +01:00

25 lines
828 B
Kotlin

package ltd.hlaeja.util
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(operation: (CharSequence?) -> CharSequence?): Account.Request = Account.Request(
username = username,
password = operation(password),
enabled = enabled,
roles = listOf("ROLE_${role.uppercase()}"),
)
fun Account.Response.toAccountForm(): AccountForm = AccountForm(
username = username,
enabled = enabled,
role = roles.first().removePrefix("ROLE_").lowercase(),
)