diff --git a/mail.go b/mail.go index e93d9db..20d081e 100644 --- a/mail.go +++ b/mail.go @@ -41,4 +41,38 @@ mini-beieli.ch` if _, err = buf.WriteTo(wc); err != nil { log.Fatal(err) } -} +} + +func sendPaymentConfirmationEmail(username,charge_data string, amount int64) { + c, err := smtp.Dial("127.0.0.1:25") + if err != nil { + log.Fatal(err) + } + defer c.Close() + // Set the sender and recipient. + c.Mail("info@mini-beieli.ch") + c.Rcpt(username) + // Send the email body. + wc, err := c.Data() + if err != nil { + log.Fatal(err) + } + defer wc.Close() + mail_message := "To: " + username + ` +Subject: Zahlungsbestaetigung mini-beieli.ch + +Lieber Benutzer von mini-beieli.ch + +Sie haben soeben erfolgreich folgende Abo-Verlaengerungen bezahlt: + +` + charge_data + ` + +Mit freundlichen GrĂ¼ssen +-- +mini-beieli.ch` + + buf := bytes.NewBufferString(mail_message) + if _, err = buf.WriteTo(wc); err != nil { + log.Fatal(err) + } +} diff --git a/metrics.go b/metrics.go index 3288677..f8069cd 100644 --- a/metrics.go +++ b/metrics.go @@ -59,6 +59,12 @@ func metricsHandler(response http.ResponseWriter, request *http.Request) { return } + if AboExpired(mydeveui) { + log.Println("specified 'deveui' has an expired abo") + fmt.Fprintf(response, "{ \"msg\": \"specified deveui has an expired abo\" }") + return + } + log.Println("Url Param 'deveui' is: " + string(mydeveui)) // Format of start and stop: YYYY-MM-DDTHH:MI:SSZ @@ -258,7 +264,7 @@ func lastmetricsHandler(response http.ResponseWriter, request *http.Request) { func CalcDaysUntil(mydate string) int { var days int - layout := "01.01.2006" + layout := "02.01.2006" t, err := time.Parse(layout, mydate) if err != nil { diff --git a/persistence.go b/persistence.go index d0aa5e8..5245f5a 100644 --- a/persistence.go +++ b/persistence.go @@ -228,6 +228,15 @@ func getActiveUntil(deveui string) string { return res } +func AboExpired(deveui string) bool { + active_until := getActiveUntil(deveui); + + layout := "02.01.2006" + t, _ := time.Parse(layout, active_until) + + return t.Before(time.Now()) +} + func prolongActivation(deveui string, years int) (string, error) { conn := globalPool.Get() defer conn.Close() diff --git a/snippets/graph.html b/snippets/graph.html index bd2c2c2..a041a6b 100644 --- a/snippets/graph.html +++ b/snippets/graph.html @@ -206,6 +206,14 @@ function drawGraph(deveui, alias, property, start, stop, create_graph) { } $.getJSON('https://mini-beieli.ch/metrics?deveui=' + deveui + '&alias=' + alias + '&property=' + property + range, function(mydata) { + if ("msg" in mydata) { + $('#chart').html(``); + return; + } var options = { chart: { type: 'line', diff --git a/snippets/scales.html b/snippets/scales.html index 899eff5..3ecb834 100644 --- a/snippets/scales.html +++ b/snippets/scales.html @@ -3,7 +3,6 @@ {{end}} {{define "body_content"}} {{ if ne .UserName "" }} -
Info: Bezahlung durchgeführt
++
Abo ist abgelaufen
+