taldir

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

commit 6fd9c1815caefdf8d66dfe03d7e5430e73db6eb3
parent 493615f700e38ef7db25b3a0a8a034dc2cc7454d
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Tue,  5 Jul 2022 13:34:35 +0200

add qr code generation

Diffstat:
Mgo.mod | 1+
Mtaldir.go | 28+++++++++++++++++++++++++++-
Mtest.sh | 2++
3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/go.mod b/go.mod @@ -7,6 +7,7 @@ require ( github.com/gorilla/mux v1.8.0 github.com/jcmturner/gokrb5/v8 v8.2.0 // indirect github.com/jinzhu/now v1.1.5 // indirect + github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect gopkg.in/ini.v1 v1.66.4 gopkg.in/jcmturner/aescts.v1 v1.0.1 // indirect diff --git a/taldir.go b/taldir.go @@ -7,15 +7,18 @@ import ( "fmt" "log" "net/http" + "html/template" "encoding/json" "github.com/gorilla/mux" "gorm.io/gorm" "encoding/base32" + "encoding/base64" "math/rand" "crypto/sha512" "gorm.io/driver/postgres" "gopkg.in/ini.v1" "strings" + "github.com/skip2/go-qrcode" ) type VersionResponse struct { @@ -153,6 +156,9 @@ var cfg *ini.File // Map of supported validators as defined in the configuration var validators map[string]bool +// landing page +var validationTpl *template.Template + // Primary lookup function. // Allows the caller to query a wallet key using the hash(!) of the // identity, e.g. sha256(<email address>) @@ -377,7 +383,23 @@ func configResponse(w http.ResponseWriter, r *http.Request) { } func validationPage(w http.ResponseWriter, r *http.Request) { - // FIXME provided HTML page here + vars := mux.Vars(r) + w.Header().Set("Content-Type", "text/html; charset=utf-8") + var walletLink string + walletLink = "taler://taldir/" + vars["h_address"] + "/" + vars["validation_code"] + "-wallet" + var png []byte + png, err := qrcode.Encode(walletLink, qrcode.Medium, 256) + if err != nil { + w.WriteHeader(500) + return + } + encodedPng := base64.StdEncoding.EncodeToString(png) + + fullData := map[string]interface{}{ + "QRCode": template.URL("data:image/png;base64," + encodedPng), + "WalletLink": template.URL(walletLink), + } + validationTpl.Execute(w, fullData) return } @@ -434,5 +456,9 @@ func main() { if err := db.AutoMigrate(&Validation{}); err != nil { panic(err) } + validationTpl, err = template.ParseFiles("templates/validation_landing.html") + if err != nil { + fmt.Println(err) + } handleRequests() } diff --git a/test.sh b/test.sh @@ -6,6 +6,8 @@ CODE=`cat validation_code` H_ADDRESS=`echo -n abc@test | openssl dgst -binary -sha512 | base32 -w0` echo "Code: $CODE; Address: $H_ADDRESS" # Validate +echo localhost:11000/register/$H_ADDRESS/$CODE +exit curl -v localhost:11000/$H_ADDRESS --data "{\"solution\": \"${CODE}\"}" # Get mapping curl -v localhost:11000/$H_ADDRESS