gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] 04/07: drafting user creation


From: gnunet
Subject: [libeufin] 04/07: drafting user creation
Date: Tue, 29 Jun 2021 15:59:15 +0200

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

commit 1ec8f2ccd12e69be71dd94a28427a61bda19c628
Author: ms <ms@taler.net>
AuthorDate: Tue Jun 29 12:00:37 2021 +0200

    drafting user creation
---
 .../src/main/kotlin/tech/libeufin/sandbox/DB.kt    | 14 ++++++++++
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  | 30 ++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index b6f42c0..a83300a 100644
--- 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
index db04d57..20e75a1 100644
--- 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") {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]