From f186d1cf5f85190bd06827acc74a2a090ac57a98 Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Sat, 3 Apr 2021 11:43:35 +0200 Subject: [PATCH] work on order form --- mail.go | 34 +++++++++++++ main.go | 1 + order.go | 33 +++++++++++++ snippets/order.html | 21 +++++++-- static/files/wo-bisch-AGBs.pdf | Bin 0 -> 8239 bytes static/js/order.js | 84 ++++++++++++++++++++++----------- 6 files changed, 142 insertions(+), 31 deletions(-) create mode 100644 order.go create mode 100644 static/files/wo-bisch-AGBs.pdf diff --git a/mail.go b/mail.go index 271bba7..dd6f64d 100644 --- a/mail.go +++ b/mail.go @@ -76,3 +76,37 @@ wo-bisch.ch` log.Fatal(err) } } + +func sendOrderEmail(username, body string) { + 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@wo-bisch.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: Bestelleingang auf https://wo-bisch.ch + +Lieber Administrator + +Soeben ist eine Bestellung eingegangen, bitte pruefen: + +` + body + ` + +Mit freundlichen GrĂ¼ssen +-- +wo-bisch.ch` + + buf := bytes.NewBufferString(mail_message) + if _, err = buf.WriteTo(wc); err != nil { + log.Fatal(err) + } +} diff --git a/main.go b/main.go index 38fb494..84d9217 100644 --- a/main.go +++ b/main.go @@ -94,6 +94,7 @@ func main() { http.HandleFunc("/logout", logoutHandler) http.HandleFunc("/confirm", confirmHandler) http.HandleFunc("/metrics", metricsHandler) + http.HandleFunc("/order", orderHandler) http.HandleFunc("/save_tracker_settings", save_tracker_settingsHandler) http.HandleFunc("/getstripepaymentintent", getstripepaymentintentHandler) http.HandleFunc("/stripewebhook", stripeWebhookHandler) diff --git a/order.go b/order.go new file mode 100644 index 0000000..8b623a0 --- /dev/null +++ b/order.go @@ -0,0 +1,33 @@ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "log" + "net/http" +) + +type order_struct struct { + Quantity string + Email string + DeliveryAdress string + BillingAdress string +} + +// order handler +func orderHandler(response http.ResponseWriter, request *http.Request) { + body, err := ioutil.ReadAll(request.Body) + if err != nil { + panic(err) + } + log.Println(string(body)) + sendOrderEmail("joerg.lehmann@nbit.ch", string(body)) + var t order_struct + err = json.Unmarshal(body, &t) + if err != nil { + log.Println("Error, invalid json: %v", err) + } + response.Header().Set("Content-Type", "text/json; charset=utf-8") + fmt.Fprintln(response, string(body)) +} diff --git a/snippets/order.html b/snippets/order.html index 86e55d3..e7df796 100644 --- a/snippets/order.html +++ b/snippets/order.html @@ -2,6 +2,12 @@ +
@@ -74,17 +81,25 @@
+

-
+

+
+