- 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
25 lines
828 B
Kotlin
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(),
|
|
)
|