[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taldir] branch master updated: add qr code generation
From: |
gnunet |
Subject: |
[taler-taldir] branch master updated: add qr code generation |
Date: |
Tue, 05 Jul 2022 13:34:37 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository taldir.
The following commit(s) were added to refs/heads/master by this push:
new 6fd9c18 add qr code generation
6fd9c18 is described below
commit 6fd9c1815caefdf8d66dfe03d7e5430e73db6eb3
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Tue Jul 5 13:34:35 2022 +0200
add qr code generation
---
go.mod | 1 +
taldir.go | 28 +++++++++++++++++++++++++++-
test.sh | 2 ++
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/go.mod b/go.mod
index 00078d6..7d1e166 100644
--- 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
index 302a1fb..d8b19e0 100644
--- 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
index de0e45d..411fcba 100755
--- 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
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-taldir] branch master updated: add qr code generation,
gnunet <=