diff options
author | MS <ms@taler.net> | 2023-01-16 20:36:40 +0100 |
---|---|---|
committer | MS <ms@taler.net> | 2023-01-16 20:36:40 +0100 |
commit | 536bb0c78f6a3d41eceac35faa95d8daa9403e18 (patch) | |
tree | 9699b3533af1b0b4e18e142599a260b8498feebb /sandbox/src/main/kotlin/tech/libeufin | |
parent | 06a854f9de2cee723a3d29baec667929a99f7a45 (diff) | |
download | libeufin-536bb0c78f6a3d41eceac35faa95d8daa9403e18.tar.gz libeufin-536bb0c78f6a3d41eceac35faa95d8daa9403e18.tar.bz2 libeufin-536bb0c78f6a3d41eceac35faa95d8daa9403e18.zip |
invoking the SMS/e-mail command
Diffstat (limited to 'sandbox/src/main/kotlin/tech/libeufin')
-rw-r--r-- | sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt | 61 | ||||
-rw-r--r-- | sandbox/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) } } |