gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: invoking the SMS/e-mail command


From: gnunet
Subject: [libeufin] branch master updated: invoking the SMS/e-mail command
Date: Mon, 16 Jan 2023 20:37:04 +0100

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 536bb0c7 invoking the SMS/e-mail command
536bb0c7 is described below

commit 536bb0c78f6a3d41eceac35faa95d8daa9403e18
Author: MS <ms@taler.net>
AuthorDate: Mon Jan 16 20:36:40 2023 +0100

    invoking the SMS/e-mail command
---
 .../kotlin/tech/libeufin/sandbox/CircuitApi.kt     | 61 +++++++++++++++++-----
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  |  9 ++++
 2 files changed, 58 insertions(+), 12 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
index bb39c954..9da9aca0 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
@@ -5,14 +5,11 @@ import io.ktor.http.*
 import io.ktor.server.request.*
 import io.ktor.server.response.*
 import io.ktor.server.routing.*
-import io.ktor.utils.io.core.*
 import org.jetbrains.exposed.sql.transactions.transaction
 import tech.libeufin.sandbox.CashoutOperationsTable.uuid
 import tech.libeufin.util.*
-import java.io.BufferedWriter
 import java.io.File
 import java.io.InputStreamReader
-import java.io.OutputStreamWriter
 import java.math.BigDecimal
 import java.math.MathContext
 import java.util.*
@@ -138,6 +135,9 @@ fun isTanChannelSupported(tanChannel: String): Boolean {
     return false
 }
 
+var EMAIL_TAN_CMD: String? = null
+var SMS_TAN_CMD: String? = null
+
 /**
  * Runs the command and returns True/False if that succeeded/failed.
  * A failed command causes "500 Internal Server Error" to be responded
@@ -345,10 +345,44 @@ fun circuitApi(circuitRoute: Route) {
         // Send the TAN.
         when (tanChannel) {
             SupportedTanChannels.EMAIL.name -> {
-                // TBD
+                val isSuccessful = try {
+                    runTanCommand(
+                        command = EMAIL_TAN_CMD ?: throw internalServerError(
+                            "E-mail TAN supported but the command" +
+                                    " was not found.  See the --email-tan 
option from 'serve'"
+                        ),
+                        address = customer.email ?: throw internalServerError(
+                            "Customer has no e-mail address, but previous 
check should" +
+                                    " have detected it!"
+                        ),
+                        message = op.tan
+                    )
+                } catch (e: Exception) {
+                    throw internalServerError("E-mail TAN command threw 
exception: ${e.message}")
+                }
+                if (!isSuccessful)
+                    throw internalServerError("E-mail TAN command failed.")
             }
             SupportedTanChannels.SMS.name -> {
-                // TBD
+                val isSuccessful = try {
+                    runTanCommand(
+                        command = SMS_TAN_CMD ?: throw internalServerError(
+                            "SMS TAN supported but the command" +
+                                    " was not found.  See the --sms-tan option 
from 'serve'"
+                        ),
+                        address = customer.email ?: throw internalServerError(
+                        "Customer has no phone number, but previous check 
should" +
+                                " have detected it!"
+
+                        ),
+                        message = op.tan
+                    )
+
+                } catch (e: Exception) {
+                    throw internalServerError("SMS TAN command threw 
exception: ${e.message}")
+                }
+                if (!isSuccessful)
+                    throw internalServerError("SMS TAN command failed.")
             }
             SupportedTanChannels.FILE.name -> {
                 try {
@@ -461,9 +495,11 @@ fun circuitApi(circuitRoute: Route) {
         if (req.contact_data.email != null) {
             if (!checkEmailAddress(req.contact_data.email))
                 throw badRequest("Invalid e-mail address: 
${req.contact_data.email}.  Won't register")
-            val maybeEmailConflict = DemobankCustomerEntity.find {
-                DemobankCustomersTable.email eq req.contact_data.email
-            }.firstOrNull()
+            val maybeEmailConflict = transaction {
+                DemobankCustomerEntity.find {
+                    DemobankCustomersTable.email eq req.contact_data.email
+                }.firstOrNull()
+            }
             // Warning since two individuals claimed one same e-mail address.
             if (maybeEmailConflict != null)
                 throw conflict("Won't register user ${req.username}: e-mail 
conflict on ${req.contact_data.email}")
@@ -472,10 +508,11 @@ fun circuitApi(circuitRoute: Route) {
             if (!checkPhoneNumber(req.contact_data.phone))
                 throw badRequest("Invalid phone number: 
${req.contact_data.phone}.  Won't register")
 
-            val maybePhoneConflict = DemobankCustomerEntity.find {
-                DemobankCustomersTable.phone eq req.contact_data.phone
-            }.firstOrNull()
-
+            val maybePhoneConflict = transaction {
+                DemobankCustomerEntity.find {
+                    DemobankCustomersTable.phone eq req.contact_data.phone
+                }.firstOrNull()
+            }
             // Warning since two individuals claimed one same phone number.
             if (maybePhoneConflict != null)
                 throw conflict("Won't register user ${req.username}: phone 
conflict on ${req.contact_data.phone}")
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 115f2e4a..906ea637 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -344,6 +344,13 @@ class Serve : CliktCommand("Run sandbox HTTP server") {
         help = "Bind the Sandbox to the Unix domain socket at PATH.  
Overrides" +
                 " --port, when both are given", metavar = "PATH"
     )
+    private val smsTan by option(help = "Command to send the TAN via SMS." +
+            "  The command gets the TAN via STDIN and the phone number" +
+            " as its first parameter"
+    )
+    private val emailTan by option(help = "Command to send the TAN via 
e-mail." +
+            "  The command gets the TAN via STDIN and the e-mail address as 
its" +
+            " first parameter.")
     override fun run() {
         WITH_AUTH = auth
         setLogLevel(logLevel)
@@ -367,6 +374,8 @@ class Serve : CliktCommand("Run sandbox HTTP server") {
             )
             exitProcess(0)
         }
+        SMS_TAN_CMD = smsTan
+        EMAIL_TAN_CMD = emailTan
         serverMain(port, localhostOnly, ipv4Only)
     }
 }

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