commit 8a443f930527f4e55aad1ae267b342f5e992eb61
parent 4a8478b5fe6a8e525f27c7ed5afed162b50e99ea
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Sun, 3 Dec 2023 19:35:28 +0100
Add templates for landing, name and all names pages.
Diffstat:
6 files changed, 115 insertions(+), 11 deletions(-)
diff --git a/cmd/web/main.go b/cmd/gns-registrar/main.go
diff --git a/gns-registrar.conf b/gns-registrar.conf
@@ -2,6 +2,7 @@
production = false
host = "https://taldir.gnunet.org"
bind_to = "localhost:11000"
+delegations_public = no
monthly_fee = KUDOS:1
default_doc_filetype = text/html
default_doc_lang = en
@@ -10,5 +11,7 @@ default_pp_path = privacy/
supported_doc_filetypes = text/html application/pdf application/epub application/xml text/plain
merchant_baseurl_private = http://merchant.taldir/instances/myInstance
merchant_token = superSecretToken
-validation_landing = templates/validation_landing.html
-validation_expiration = 24h
+registrar_landing = web/templates/landing.html
+registrar_name = web/templates/name.html
+registration_failed = templates/registration_failed.html
+registration_duration = 1y
diff --git a/pkg/rest/gnsregistrar.go b/pkg/rest/gnsregistrar.go
@@ -44,7 +44,13 @@ type Registrar struct {
Validators map[string]bool
// landing page
- ValidationTpl *template.Template
+ LandingTpl *template.Template
+
+ // name page
+ NameTpl *template.Template
+
+ // all names page
+ AllNamesTpl *template.Template
// The address salt
Salt string
@@ -87,9 +93,41 @@ func (t *Registrar) configResponse(w http.ResponseWriter, r *http.Request) {
w.Write(response)
}
+func (t *Registrar) landingPage(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
+
+ fullData := map[string]interface{}{
+ "title": "Landing",
+ }
+ t.LandingTpl.Execute(w, fullData)
+ return
+}
+
+func (t *Registrar) namePage(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
+ fullData := map[string]interface{}{
+ "label": r.URL.Query().Get("label"),
+ }
+ t.NameTpl.Execute(w, fullData)
+ return
+}
+
+func (t *Registrar) allNamesPage(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
+ fullData := map[string]interface{}{
+ "names": []string{"example", "gnu", "gnunet"},
+ }
+ t.AllNamesTpl.Execute(w, fullData)
+ return
+}
+
func (t *Registrar) setupHandlers() {
t.Router = mux.NewRouter().StrictSlash(true)
+ t.Router.HandleFunc("/", t.landingPage).Methods("GET")
+ t.Router.HandleFunc("/name", t.namePage).Methods("GET")
+ t.Router.HandleFunc("/names", t.allNamesPage).Methods("GET")
+
/* ToS API */
// t.Router.HandleFunc("/terms", t.termsResponse).Methods("GET")
// t.Router.HandleFunc("/privacy", t.privacyResponse).Methods("GET")
@@ -99,13 +137,6 @@ func (t *Registrar) setupHandlers() {
/* Assets HTML */
t.Router.PathPrefix("/css").Handler(http.StripPrefix("/css", http.FileServer(http.Dir("./static/css"))))
-
- /* Registration API */
- /* t.Router.HandleFunc("/{h_address}", t.getSingleEntry).Methods("GET")
- t.Router.HandleFunc("/register/{method}", t.registerRequest).Methods("POST")
- t.Router.HandleFunc("/register/{h_address}/{challenge}", t.validationPage).Methods("GET")
- t.Router.HandleFunc("/{h_address}", t.validationRequest).Methods("POST")
- */
}
// Initialize the gnsregistrar instance with cfgfile
@@ -119,7 +150,22 @@ func (t *Registrar) Initialize(cfgfile string) {
if t.Cfg.Section("gns-registrar").Key("production").MustBool(false) {
fmt.Println("Production mode enabled")
}
-
+ landingTplFile := t.Cfg.Section("gns-registrar").Key("registrar_landing").MustString("web/templates/landing.html")
+ t.LandingTpl, err = template.ParseFiles(landingTplFile)
+ if err != nil {
+ fmt.Println(err)
+ }
+ nameTplFile := t.Cfg.Section("gns-registrar").Key("registrar_name").MustString("web/templates/name.html")
+ t.NameTpl, err = template.ParseFiles(nameTplFile)
+ if err != nil {
+ fmt.Println(err)
+ }
+ allNamesTplFile := t.Cfg.Section("gns-registrar").Key("registrar_all_names").MustString("web/templates/names.html")
+ t.AllNamesTpl, err = template.ParseFiles(allNamesTplFile)
+ if err != nil {
+ fmt.Println(err)
+ }
+ // gnunetURL := t.Cfg.Section("gns-registrar").Key("gnunet_baseurl_private").MustString("http://localhost:7776")
merchURL := t.Cfg.Section("gns-registrar").Key("merchant_baseurl_private").MustString("http://merchant.gnsregistrar/instances/myInstance")
merchToken := t.Cfg.Section("gns-registrar").Key("merchant_token").MustString("secretAccessToken")
t.Merchant = merchant.NewMerchant(merchURL, merchToken)
diff --git a/web/templates/landing.html b/web/templates/landing.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <!-- Required meta tags -->
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+ <link href="/css/style.css" rel="stylesheet">
+ <title>GNS Registrar</title>
+ </head>
+ <body>
+ <div class="search">
+ <h1>Lookup your domain name.</h1>
+ <form action="/name" method="get" >
+ <input name="label" type="text" placeholder="Check if your name is still available!" required autofocus>
+ <input type="submit" value="Search">
+ </form>
+ </div>
+ </body>
+</html>
diff --git a/web/templates/name.html b/web/templates/name.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <!-- Required meta tags -->
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+ <link href="/css/style.css" rel="stylesheet">
+ <title>Name Overview</title>
+ </head>
+ <body>
+ <div class="name">
+ <h1>{{.label}} exists.</h1>
+ <a class="button" href="/buy?label={{.label}}">Buy</a>
+ </div>
+ </body>
+</html>
diff --git a/web/templates/names.html b/web/templates/names.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <!-- Required meta tags -->
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+ <link href="/css/style.css" rel="stylesheet">
+ <title>All Names Overview</title>
+ </head>
+ <body>
+ <div class="names">
+ <!-- FIXME: Probably make this a table -->
+ <ul>
+ {{range $idx, $e := .names}}
+ <li>{{$e}}</li>
+ {{end}}
+ </ul>
+ </div>
+ </body>
+</html>