diff --git a/main.go b/main.go index f88e492..5414840 100644 --- a/main.go +++ b/main.go @@ -54,7 +54,6 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) { var datetimestring = t.Format("20060102150405") var scales = getMyDevs(userName) var last_metrics []OneMetric - var checkout_session_id string if (r.URL.Path == "/scales.html") { // wir holen noch die letzten Metriken @@ -69,13 +68,11 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) { DateTimeString string Scales []string LastMetrics []OneMetric - CheckoutSessionID string } { userName, datetimestring, scales, last_metrics, - checkout_session_id, } if err := tmpl.ExecuteTemplate(w, "layout", &data); err != nil { diff --git a/persistence.go b/persistence.go index d1a38c5..640359d 100644 --- a/persistence.go +++ b/persistence.go @@ -3,6 +3,7 @@ package main import ( "time" "strings" + "fmt" "log" "crypto/rand" "golang.org/x/crypto/bcrypt" @@ -54,6 +55,7 @@ type Dev struct { Alias string Alarmactive string Smsnumber string + ActiveUntil string // Abo bezahlt bis TT.MM.YYYY } func initDB() { @@ -203,6 +205,42 @@ func getDevSmsnumber(deveui string) string { return res } +func prolongActivation(deveui string, years int) (string, error) { + conn := globalPool.Get() + defer conn.Close() + + active_until_old, err := redis.String(conn.Do("HGET", devPrefix+deveui, "active_until")) + if err == nil { + logit("prolongActivation: active_until: " +active_until_old) + } else { + log.Print(err) + } + + layout := "02.01.2006" + t, err := time.Parse(layout, active_until_old) + + if err != nil { + fmt.Println(err) + } + fmt.Println(t.Unix()) + + var t_new time.Time + if t.Before(time.Now()) { + t_new = time.Now().AddDate(1, 0, 0) + } else { + t_new = t.AddDate(1, 0, 0) + } + active_until_new := t_new.Format(layout) + + // SET object + _, err1 := conn.Do("HMSET", devPrefix+deveui, "active_until", active_until_new) + if err1 != nil { + return "",err1 + } + + return active_until_new, nil +} + func randString(n int) string { const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" var bytes = make([]byte, n) diff --git a/snippets/payment_cancelled.html b/snippets/payment_cancelled.html index 277b677..e90ab50 100644 --- a/snippets/payment_cancelled.html +++ b/snippets/payment_cancelled.html @@ -1,4 +1,9 @@ {{define "body_content"}} +{{ if ne .UserName "" }} +
Zahlung abgebrochen!
Zahlung wurde abgebrochen
+{{ else }} +Danke schoen!
Danke fuer die Zahlung!
+{{ else }} +