diff --git a/db.go b/db.go index 7b39a7a..064c1a1 100644 --- a/db.go +++ b/db.go @@ -21,7 +21,11 @@ type Params struct { Waki string } -func SaveName(name string, params *Params, providedPin string) (pin string, err error) { +func SaveName( + name string, + params *Params, + providedPin string, +) (pin string, inv string, err error) { name = strings.ToLower(name) key := []byte(name) @@ -32,22 +36,22 @@ func SaveName(name string, params *Params, providedPin string) (pin string, err if _, closer, err := db.Get(key); err == nil { defer closer.Close() if pin != providedPin { - return "", errors.New("name already exists! must provide pin.") + return "", "", errors.New("name already exists! must provide pin.") } } // check if the given data works - if _, err := makeInvoice(params, 1000); err != nil { - return "", fmt.Errorf("couldn't make an invoice with the given data: %w", err) + if inv, err = makeInvoice(params, 1000); err != nil { + return "", "", fmt.Errorf("couldn't make an invoice with the given data: %w", err) } // save it data, _ := json.Marshal(params) if err := db.Set(key, data, pebble.Sync); err != nil { - return "", err + return "", "", err } - return pin, nil + return pin, inv, nil } func GetName(name string) (*Params, error) { diff --git a/grab.html b/grab.html new file mode 100644 index 0000000..4a9def2 --- /dev/null +++ b/grab.html @@ -0,0 +1,32 @@ + + + + Satdress - Name Saved + + + + + + +
+ name saved! this is your secret pin key for this name: {{ pin }} + this is the test invoice we've generated: {{ invoice }} +
+ + + + diff --git a/html.go b/html.go new file mode 100644 index 0000000..ca92443 --- /dev/null +++ b/html.go @@ -0,0 +1,37 @@ +package main + +import ( + "encoding/json" + "fmt" + "net/http" + "strings" +) + +type BaseData struct { + Domain string `json:"domain"` + SiteOwnerName string `json:"siteOwnerName"` + SiteOwnerURL string `json:"siteOwnerURL"` + SiteName string `json:"siteName"` +} + +func renderHTML(w http.ResponseWriter, html string, extraData interface{}) { + base, _ := json.Marshal(BaseData{ + Domain: s.Domain, + SiteOwnerName: s.SiteOwnerName, + SiteOwnerURL: s.SiteOwnerURL, + SiteName: s.SiteName, + }) + extra, _ := json.Marshal(extraData) + + w.Header().Set("content-type", "text/html") + fmt.Fprint(w, + strings.ReplaceAll( + strings.ReplaceAll( + html, + "{} // REPLACED WITH SERVER DATA", + fmt.Sprintf("{...%s, ...%s}", string(base), string(extra)), + ), + "Satdress", s.SiteName, + ), + ) +} diff --git a/index.html b/index.html index 7fc258f..c210b21 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,7 @@ + -
Satdress
@@ -334,7 +145,7 @@ src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.2.2/vue.global.prod.min.js" >