commit 1ec8f2ccd12e69be71dd94a28427a61bda19c628 parent 1117d23adcbb41661968859e0efe52d34e05ac33 Author: ms <ms@taler.net> Date: Tue, 29 Jun 2021 12:00:37 +0200 drafting user creation Diffstat:
| M | sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt | | | 14 | ++++++++++++++ |
| M | sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | | | 30 | ++++++++++++++++++++++++++++++ |
2 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt @@ -84,6 +84,20 @@ enum class KeyState { RELEASED } +object SandboxUsersTable : LongIdTable() { + val username = text("username") + val passwordHash = text("password") + val superuser = bool("superuser") // admin +} + +class SandboxUserEntity(id: EntityID<Long>) : LongEntity(id) { + companion object : LongEntityClass<SandboxUserEntity>(SandboxUsersTable) + var username by SandboxUsersTable.username + var passwordHash by SandboxUsersTable.passwordHash + var superuser by SandboxUsersTable.superuser +} + + /** * This table stores RSA public keys of subscribers. */ diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -325,7 +325,37 @@ fun serverMain(dbName: String, port: Int) { post("/register") { // how to read form-POSTed values? + val username = "fixme" + val password = "fixme" + val superuser = false + transaction { + // check if username is taken. + val maybeUser = SandboxUserEntity.find( + SandboxUserTable.username eq username + ).firstOrNull() + // Will be converted to a HTML response. + if (maybeUser != null) throw SandboxError( + HttpStatusCode.Conflict, "Username not available" + ) + + // username is valid. Register the user + new bank account. + SandboxUserEntity.new { + username = username + passwordHash = CryptoUtil.hashpw(password) + superuser = false + bankAccount = BankAccountEntity.new { + iban = "fixme" + bic = "fixme" + name = "fixme" + label = "fixme" + currency = "fixme" + } + } + } + + call.respondText("User $username created") + return@post } get("/jinja-test") {