libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 1117d23adcbb41661968859e0efe52d34e05ac33
parent cf835854e5cd07fd7d1b630d5c13da31abe08f49
Author: ms <ms@taler.net>
Date:   Tue, 29 Jun 2021 11:39:02 +0200

Jinja and form-auth experiments

Diffstat:
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 44+++++++++++++++++++++++++++++++++++++++-----
1 file changed, 39 insertions(+), 5 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -227,8 +227,16 @@ fun serverMain(dbName: String, port: Int) { } install(Authentication) { // Web-based authentication for Bank customers. - form { - + form("auth-form") { + userParamName = "username" + passwordParamName = "password" + validate { credentials -> + if (credentials.name == "test") { + UserIdPrincipal(credentials.name) + } else { + null + } + } } } install(ContentNegotiation) { @@ -302,6 +310,24 @@ fun serverMain(dbName: String, port: Int) { } } routing { + /* + + FIXME: commenting out until a solution for i18n is found. + + get("/bank") { + val ret = renderTemplate( + "login.html", + mapOf("csrf_token" to "todo", ) + ) + call.respondText(ret) + return@get + } */ + + post("/register") { + // how to read form-POSTed values? + + } + get("/jinja-test") { val template = Resources.toString( Resources.getResource("templates/hello.html"), @@ -313,6 +339,15 @@ fun serverMain(dbName: String, port: Int) { return@get } + authenticate("auth-form") { + get("/profile") { + val userSession = call.principal<UserIdPrincipal>() + println("Welcoming ${userSession?.name}") + call.respond(object {}) + return@get + } + } + static("/static") { /** * Here Sandbox will serve the CSS files. @@ -400,13 +435,12 @@ fun serverMain(dbName: String, port: Int) { post("/admin/ebics/bank-accounts") { val body = call.receiveJson<BankAccountRequest>() transaction { - val subscriber = getEbicsSubscriberFromDetails( + var subscriber = getEbicsSubscriberFromDetails( body.subscriber.userID, body.subscriber.partnerID, body.subscriber.hostID ) - BankAccountEntity.new { - this.subscriber = subscriber + subscriber.bankAccount = BankAccountEntity.new { iban = body.iban bic = body.bic name = body.name