taldir

Directory service to resolve wallet mailboxes by messenger addresses
Log | Files | Refs | Submodules | README | LICENSE

commit 435c9151aa597afa40661f044ec452a0902344ed
parent 9becafda5f91fdda6cdd40e3111fa897e62b6bff
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Fri, 10 Jan 2025 08:18:36 +0100

more UI improvements and other bug fixes

Diffstat:
Mpkg/rest/taldir.go | 31++++++++++---------------------
Mweb/templates/landing.html | 8++++++--
Mweb/templates/landing_email.html | 6++++++
Mweb/templates/landing_phone.html | 7++++++-
Mweb/templates/lookup_result.html | 6+++---
Mweb/templates/validation_landing.html | 74+++++++++++++++++++++++++++++++++++++++++---------------------------------
6 files changed, 72 insertions(+), 60 deletions(-)

diff --git a/pkg/rest/taldir.go b/pkg/rest/taldir.go @@ -400,7 +400,7 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r *http.Request) { var validation validation var entry entry // Check if this validation method is supported or not. - _, ok := t.Validators[vars["method"]] + validator, ok := t.Validators[vars["method"]] if !ok { errDetail.Code = gana.TALDIR_METHOD_NOT_SUPPORTED errDetail.Hint = "Unsupported method" @@ -477,10 +477,9 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r *http.Request) { validation.Duration = reqDuration.Microseconds() } - fixedCost := t.Cfg.Section("taldir-" + vars["method"]).Key("challenge_fee").MustString("KUDOS:0") sliceDuration := time.Duration(validation.Duration * 1000) cost, err := util.CalculateCost(t.MonthlyFee, - fixedCost, + validator.ChallengeFee, sliceDuration, monthDuration) if err != nil { @@ -526,28 +525,16 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) return } - // Some validation methods are costly - // Require explicit whitelisting for a resend. - if validation.ChallengeSent && - !t.Cfg.Section("taldir-"+vars["method"]).Key("allow_resend").MustBool(false) { - w.WriteHeader(202) - return - } - if !t.Cfg.Section("taldir-" + vars["method"]).HasKey("command") { - log.Fatal(err) - t.Db.Delete(&validation) - w.WriteHeader(500) - return - } - command := t.Cfg.Section("taldir-" + vars["method"]).Key("command").String() - path, err := exec.LookPath(command) + path, err := exec.LookPath(validator.Command) if err != nil { log.Println(err) t.Db.Delete(&validation) w.WriteHeader(500) return } + log.Printf("Found `%s` in path as `%s`", validator.Command, path) out, err := exec.Command(path, req.Address, validation.Challenge).Output() + log.Printf("Executing `%s %s %s`", path, req.Address, validation.Challenge) if err != nil { fmt.Printf("%s, %v", out, err) t.Db.Delete(&validation) @@ -564,7 +551,7 @@ func (t *Taldir) configResponse(w http.ResponseWriter, r *http.Request) { for key := range t.Validators { var meth Method meth.Name = key - meth.ChallengeFee = t.Cfg.Section("taldir-" + key).Key("challenge_fee").MustString("KUDOS:1") + meth.ChallengeFee = t.Validators[key].ChallengeFee i++ meths = append(meths, meth) } @@ -586,6 +573,7 @@ func (t *Taldir) validationPage(w http.ResponseWriter, r *http.Request) { var png []byte var validation validation + log.Println("Validation Page") err := t.Db.First(&validation, "h_address = ?", vars["h_address"]).Error w.Header().Set("Content-Type", "text/html; charset=utf-8") if err != nil { @@ -605,13 +593,14 @@ func (t *Taldir) validationPage(w http.ResponseWriter, r *http.Request) { expectedHAddress := gnunetutil.EncodeBinaryToString(h.Sum(nil)) if expectedHAddress != validation.HAddress { - log.Fatal("Address does not match challenge!") + log.Println("Address does not match challenge!") w.WriteHeader(500) return } // This is kind of broken and probablzy requires wallet support if validation.RequiresPayment { + log.Println("Validation requires payment") walletLink = "taler://taldir/" + vars["h_address"] + "/" + vars["challenge"] + "-wallet" png, err = qrcode.Encode(walletLink, qrcode.Medium, 256) if err != nil { @@ -781,7 +770,7 @@ func (t *Taldir) Initialize(cfgfile string) { LandingPageTpl: vlandingPageTpl, ChallengeFee: sec.Key("challenge_fee").MustString("KUDOS:0"), PaymentRequired: sec.Key("enabled").MustBool(false), - Command: sec.Key("enabled").MustString(""), + Command: sec.Key("command").MustString(""), } } t.ChallengeBytes = t.Cfg.Section("taldir").Key("challenge_bytes").MustInt(16) diff --git a/web/templates/landing.html b/web/templates/landing.html @@ -19,11 +19,15 @@ </div> </div> {{end}} - <h2>Select what type of address you want to look up or register:</h2> + <div id="ebanner" class="alert alert-info" role="alert"> + <h4 class="alert-heading">Look up or register</h4> + <hr> + <p class="mb-0">Select a type of address that you want to look up or register.</p> + </div> <hr> {{range .validators}} <div class="row"> - <div class="col-lg-6 mb-2 offset-lg-3 text-center"> + <div class="col-lg-4 mb-2 offset-lg-3 text-center"> <a href="/landing/{{.Name}}" class="btn btn-primary btn-block">{{.Name}}</a> </div> </div> diff --git a/web/templates/landing_email.html b/web/templates/landing_email.html @@ -19,6 +19,12 @@ </div> </div> {{end}} + <div id="ebanner" class="alert alert-info" role="alert"> + <h4 class="alert-heading">Look up email address</h4> + <hr> + <p class="mb-0">Enter an email address (e.g. <i>jdoe@example.com</i>) to look up the associated target URI or register a target URI if it is still availialbe.</p> + </div> + <hr> <form method="get" action="/lookup/email"> <div class="row"> <div class="col-lg-6 offset-lg-3 text-center"> diff --git a/web/templates/landing_phone.html b/web/templates/landing_phone.html @@ -19,7 +19,12 @@ </div> </div> {{end}} - <form method="get" action="/lookup/email"> + <div id="ebanner" class="alert alert-info" role="alert"> + <h4 class="alert-heading">Look up phone number</h4> + <hr> + <p class="mb-0">Enter a phone number (e.g. <i>+49 123 456 789</i>) to look up the associated target URI or register a target URI if it is still availialbe.</p> + </div> + <form method="get" action="/lookup/phone"> <div class="row"> <div class="col-lg-6 offset-lg-3 text-center"> <div class="input-group mb-3"> diff --git a/web/templates/lookup_result.html b/web/templates/lookup_result.html @@ -19,8 +19,8 @@ </div> </div> {{end}} - <div class="container pt-5"> - <div id="sbanner" class="alert alert-success" role="alert" hidden> + <div id="sbanner" class="container pt-5" hidden> + <div class="alert alert-success" role="alert"> <h4 class="alert-heading">Registration initiated!</h4> <hr> Please complete your registration according to the instructions sent to you. @@ -44,7 +44,7 @@ <div class="input-group-prepend"> <span class="input-group-text" id="inputGroup-sizing-default">Target URI</span> </div> - <input id="uriInput" type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"> + <input id="uriInput" name="target_uri" type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"> </div> </div> </div> diff --git a/web/templates/validation_landing.html b/web/templates/validation_landing.html @@ -9,41 +9,47 @@ <title>Validation Landing Page</title> </head> <body> - {{if .error}} - <div class="container pt-5"> - <div id="ebanner" class="alert alert-danger" role="alert"> - <h4 class="alert-heading">An error occured!</h4> - <hr> - <p class="mb-0">{{.error}}.</p> - </div> - </div> - {{end}} - <div class="container pt-5"> - <div id="sbanner" class="alert alert-success" role="alert" hidden> - <h4 class="alert-heading">Registration successful!</h4> - </div> + {{if .error}} + <div class="container pt-5"> + <div id="ebanner" class="alert alert-danger" role="alert"> + <h4 class="alert-heading">An error occured!</h4> + <hr> + <p class="mb-0">{{.error}}.</p> </div> - {{if .WalletLink}} - <div class="qr"> - <h1>Scan this QR code with your Taler Wallet to complete your registration.</h1> - <a href="{{.WalletLink}}"> - <img class="taldir-qr" src="{{.QRCode}}"/> - </a> + </div> + {{end}} + <div class="container pt-5"> + <div id="sbanner" class="alert alert-success" role="alert" hidden> + <h4 class="alert-heading">Registration successful!</h4> + <hr> + You may now <a href="/">go back to the front page</a>. </div> - {{else}} - <div class="container pt-5"> - <h1>Click to confirm that you want to associate "<i>{{.address}}</i>" with "<i>{{.target_uri}}</i>"</h1> + </div> + {{if .WalletLink}} + <div class="qr"> + <h1>Scan this QR code with your Taler Wallet to complete your registration.</h1> + <a href="{{.WalletLink}}"> + <img class="taldir-qr" src="{{.QRCode}}"/> + </a> + </div> + {{else}} + <div id="regcontainer" class="container pt-5"> + <div class="alert alert-info" role="alert"> + <h4 class="alert-heading">Confirm registration</h4> + <hr> + Click to confirm that you want to associate "<i>{{.address}}</i>" with "<i>{{.target_uri}}</i>". <div class="row"> <div class="col-lg-6 offset-lg-3 text-center"> <form id="regform"> <input id="haddrInput" name="haddr" type="hidden" value="{{.haddress}}"> <input id="solutionInput" name="solution" type="hidden" value="{{.solution}}"> - <input class="btn btn-primary" type="submit" value="Register!""> + <input class="btn btn-primary" type="submit" value="Register!"> </form> </div> </div> </div> - {{end}} + </div> + {{end}} </body> <script> var form = document.getElementById('regform'); @@ -58,18 +64,20 @@ xhr.send(json); xhr.onreadystatechange = function() { - if (xhr.readyState == XMLHttpRequest.DONE) { - if (xhr.status == 204) { - var sbanner = document.getElementById('sbanner'); - sbanner.hidden = false; - } else { - window.location.href = "?error=Registration failed"; - } -} + if (xhr.readyState == XMLHttpRequest.DONE) { + if (xhr.status == 204) { + var sbanner = document.getElementById('sbanner'); + var regcontainer = document.getElementById('regcontainer'); + sbanner.hidden = false; + regcontainer.hidden = true; + } else { + window.location.href = "?error=Registration failed"; + } + } } //Dont submit the form. return false; - } + } </script> </html>