gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: Create customer via Access API


From: gnunet
Subject: [libeufin] branch master updated: Create customer via Access API
Date: Tue, 19 Oct 2021 09:54:51 +0200

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

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new d13b09a  Create customer via Access API
d13b09a is described below

commit d13b09a8a905387eb2013eb42f3fa68a2664f13c
Author: ms <ms@taler.net>
AuthorDate: Tue Oct 19 09:54:44 2021 +0200

    Create customer via Access API
---
 .../src/main/kotlin/tech/libeufin/sandbox/DB.kt    |  9 ++++++
 .../main/kotlin/tech/libeufin/sandbox/Helpers.kt   | 11 ++++++++
 .../src/main/kotlin/tech/libeufin/sandbox/JSON.kt  |  5 ++++
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  | 32 +++++++++++++++++++---
 sandbox/src/main/resources/logback.xml             |  3 ++
 5 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index fff7d52..ee3cc00 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -117,6 +117,15 @@ object DemobankCustomersTable : LongIdTable() {
     val passwordHash = text("passwordHash")
 }
 
+class DemobankCustomerEntity(id: EntityID<Long>) : LongEntity(id) {
+    companion object : 
LongEntityClass<DemobankCustomerEntity>(DemobankCustomersTable)
+    var isPublic by DemobankCustomersTable.isPublic
+    var demobankConfig by DemobankCustomersTable.demobankConfig
+    var balance by DemobankCustomersTable.balance
+    var username by DemobankCustomersTable.username
+    var passwordHash by DemobankCustomersTable.passwordHash
+}
+
 
 /**
  * This table stores RSA public keys of subscribers.
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
index ca72be6..a63c363 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
@@ -23,6 +23,7 @@ import io.ktor.http.HttpStatusCode
 import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
 import org.jetbrains.exposed.sql.and
 import org.jetbrains.exposed.sql.transactions.transaction
+import tech.libeufin.util.internalServerError
 
 /**
  * Helps to communicate Camt values without having
@@ -87,6 +88,16 @@ fun getBankAccountFromSubscriber(subscriber: 
EbicsSubscriberEntity): BankAccount
     }
 }
 
+fun ensureDemobank(name: String): DemobankConfigEntity {
+    return transaction {
+        val res = DemobankConfigEntity.find {
+            DemobankConfigsTable.name eq name
+        }.firstOrNull()
+        if (res == null) throw internalServerError("Demobank '$name' never 
created")
+        res
+    }
+}
+
 fun getSandboxConfig(name: String?): DemobankConfigEntity? {
     return transaction {
         if (name == null) {
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
index 8e726cf..8569d44 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
@@ -72,6 +72,11 @@ data class BankAccountRequest(
     val currency: String
 )
 
+data class CustomerRegistration(
+    val username: String,
+    val password: String
+)
+
 data class CamtParams(
     // name/label of the bank account to query.
     val bankaccount: String,
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 4a955f4..8a976c5 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -1075,8 +1075,6 @@ val sandboxApp: Application.() -> Unit = {
                 get("/accounts/{account_name}") {
                     // Authenticated.  Accesses basic information (balance)
                     // about an account. (see docs)
-
-                    // FIXME: Since we now use IBANs everywhere, maybe the 
account should also be assigned an IBAN
                 }
 
                 get("/accounts/{account_name}/history") {
@@ -1095,8 +1093,34 @@ val sandboxApp: Application.() -> Unit = {
                     // Get transaction history of a public account
                 }
 
-                post("/register") {
-
+                // Keeping the prefix "testing" to allow integration tests 
using this endpoint.
+                post("/testing/register") {
+                    // Check demobank was created.
+                    val demobank = 
ensureDemobank(call.getUriComponent("demobankid"))
+                    val req = call.receive<CustomerRegistration>()
+                    val checkExist = transaction {
+                        DemobankCustomerEntity.find {
+                            DemobankCustomersTable.username eq req.username
+                        }
+                    }.firstOrNull()
+                    if (checkExist != null) {
+                        throw SandboxError(
+                            HttpStatusCode.Conflict,
+                            "Username ${req.username} not available."
+                        )
+                    }
+                    // Create new customer.
+                    requireValidResourceName(req.username)
+                    transaction {
+                        // FIXME: Since we now use IBANs everywhere, maybe the 
account should also be assigned an IBAN
+                        DemobankCustomerEntity.new {
+                            username = req.username
+                            passwordHash = CryptoUtil.hashpw(req.password)
+                            demobankConfig = demobank.id
+                        }
+                    }
+                    call.respondText("Registration successful")
+                    return@post
                 }
             }
 
diff --git a/sandbox/src/main/resources/logback.xml 
b/sandbox/src/main/resources/logback.xml
index d761ec6..53aa888 100644
--- a/sandbox/src/main/resources/logback.xml
+++ b/sandbox/src/main/resources/logback.xml
@@ -9,6 +9,9 @@
     <logger name="tech.libeufin.sandbox" level="DEBUG"  additivity="false">
         <appender-ref ref="STDERR" />
     </logger>
+    <logger name="tech.libeufin.util" level="DEBUG"  additivity="false">
+        <appender-ref ref="STDERR" />
+    </logger>
 
     <logger name="io.netty" level="WARN" />
     <logger name="ktor" level="WARN" />

-- 
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]