Compare commits

13 Commits
Author SHA1 Message Date
jlehmann 7f639bca49 new address 2025-05-14 06:30:42 +02:00
jlehmann 483d10799d disable ordering possibility 2024-05-24 14:37:31 +02:00
jlehmann 8e3721da89 set mail content type to utf-8 2024-05-04 13:19:12 +02:00
jlehmann a297b127e1 update go version 2023-03-04 19:25:44 +01:00
jlehmann 8838103f2d make it the same as mini-beieli-web 2023-02-03 19:08:45 +01:00
jlehmann 0931ecb0f4 no receipt email 2023-02-03 18:49:24 +01:00
jlehmann 40134ceba9 go mod tidy 2023-02-03 17:26:28 +01:00
jlehmann 6364bedb29 new version with new stripe functionality 2023-02-03 17:25:51 +01:00
jlehmann 97d2bb2593 timezone in docker image 2022-12-28 17:14:09 +01:00
jlehmann 570de60338 add influx command to readme 2022-12-27 19:12:58 +01:00
jlehmann c6f98415e3 add some influx commands 2022-12-21 18:16:54 +01:00
jlehmann 0520b1eb02 use html mail for abocost because of table 2022-09-16 11:04:13 +02:00
jlehmann 1f1e34e213 add payment years to expiration date, not now 2022-09-15 18:17:15 +02:00
11 changed files with 86 additions and 55 deletions
+2
View File
@@ -4,6 +4,8 @@ ADD go.mod .
COPY . .
RUN go build
FROM alpine
RUN apk add --no-cache tzdata
ENV TZ=Europe/Zurich
WORKDIR /build
RUN apk add --no-cache tzdata
COPY --from=builder /build/wo-bisch-web /build/wo-bisch-web
+20
View File
@@ -45,3 +45,23 @@ show range of last values:
Autor: Joerg Lehmann, nbit Informatik GmbH
### Influxdb Commands
```
Show tokens
# influx auth ls
Clone Admin Token in Webgui if not known anymore and use this to get all tokens:
Create Default Config:
# influx config create --config-name default --token XXXXXXXXXXX --host-url http://127.0.0.1:8086 -a
Update Token in Default Config:
# influx config update --config-name default --token XXXXXXXXXXX
Backup Influxdb:
# influx backup /root/joergs-backup -t XXXXXadmintokenXXXXX
Restore Influxdb:
# influx restore /var/lib/influxdb2/joergs-backup/ --full
```
+3 -1
View File
@@ -12,6 +12,7 @@ func sendEmailAccu(username string, alias string, deveui string, accu_percent st
mail_message := "To: " + username + `
From: info@wo-bisch.ch
Subject: ` + level + ` - wo-bisch.ch: Akku Ladezustand (` + alias + `)
Content-Type: text/plain; charset="UTF-8"
Lieber Benutzer von wo-bisch.ch
@@ -38,12 +39,13 @@ func sendEmailAbo(username string, alias string, deveui string, days_left int, l
mail_message := "To: " + username + `
From: info@wo-bisch.ch
Subject: ` + level + ` - wo-bisch.ch: Abo verlaengern (` + alias + `)
Content-Type: text/plain; charset="UTF-8"
Lieber Benutzer von wo-bisch.ch
` + ablauftext + `
Bitte Abo verlaengern auf https://wo-bisch.ch
Bitte Abo verlängern auf https://wo-bisch.ch
Mit freundlichen Grüssen
--
+2 -3
View File
@@ -1,11 +1,10 @@
module nbit.ch/wo-bisch-web/v2
go 1.14
go 1.17
require (
github.com/gomodule/redigo v1.8.4
github.com/gorilla/securecookie v1.1.1
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
github.com/stripe/stripe-go/v72 v72.41.0
github.com/stripe/stripe-go/v74 v74.7.0
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
)
+10 -7
View File
@@ -1,29 +1,32 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gomodule/redigo v1.8.4 h1:Z5JUg94HMTR1XpwBaSH4vq3+PNSIykBLxMdglbw10gg=
github.com/gomodule/redigo v1.8.4/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
github.com/gomodule/redigo/redis v0.0.0-do-not-use h1:J7XIp6Kau0WoyT4JtXHT3Ei0gA1KkSc6bc87j9v9WIo=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible h1:jdpOPRN1zP63Td1hDQbZW73xKmzDvZHzVdNYxhnTMDA=
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stripe/stripe-go v1.0.3 h1:RHgK2FUKawVNBPJ15pNM4IWkEVVCg5Ju3xK5QZNhTwY=
github.com/stripe/stripe-go v70.15.0+incompatible h1:hNML7M1zx8RgtepEMlxyu/FpVPrP7KZm1gPFQquJQvM=
github.com/stripe/stripe-go/v72 v72.41.0 h1:HkyJew+GkD/ClBT306+5vKLjBE4PRCJDiZ1enQyxeGQ=
github.com/stripe/stripe-go/v72 v72.41.0/go.mod h1:QwqJQtduHubZht9mek5sds9CtQcKFdsykV9ZepRWwo0=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stripe/stripe-go/v74 v74.7.0 h1:KHlyslQj9YOv62b1sycQ31LFj7KlqR+seHsSowAWrjc=
github.com/stripe/stripe-go/v74 v74.7.0/go.mod h1:5PoXNp30AJ3tGq57ZcFuaMylzNi8KpwlrYAFmO1fHZw=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+8 -4
View File
@@ -35,10 +35,11 @@ func sendEmailConfirm(username, confirm_id string) {
mail_message := "To: " + username + `
From: register@wo-bisch.ch
Subject: Passwortaenderung auf https://wo-bisch.ch, bitte bestaetigen
Content-Type: text/plain; charset="UTF-8"
Lieber Benutzer von wo-bisch.ch
Sie haben soeben eine Passwortaenderung veranlasst. Bitte klicken Sie folgenden Link,
Sie haben soeben eine Passwortänderung veranlasst. Bitte klicken Sie folgenden Link,
um das neue Passwort zu aktivieren:
https://wo-bisch.ch/confirm?id=` + confirm_id + `
@@ -56,7 +57,9 @@ func sendPaymentConfirmationEmail(username, charge_data string, amount int64) {
mail_message := "To: " + username + `
From: info@wo-bisch.ch
Subject: Zahlungsbestaetigung wo-bisch.ch
MIME-version: 1.0;
Content-Type: text/html; charset="UTF-8";
<pre>
Lieber Benutzer von wo-bisch.ch
Sie haben soeben erfolgreich folgende Abo-Verlaengerungen bezahlt:
@@ -65,7 +68,7 @@ Sie haben soeben erfolgreich folgende Abo-Verlaengerungen bezahlt:
Mit freundlichen Grüssen
--
wo-bisch.ch`
wo-bisch.ch</pre>`
sendEmail(username, "mail@wo-bisch.ch", mail_message)
}
@@ -74,10 +77,11 @@ func sendOrderEmail(username, body string) {
mail_message := "To: " + username + `
From: info@wo-bisch.ch
Subject: Bestelleingang auf https://wo-bisch.ch
Content-Type: text/plain; charset="UTF-8"
Lieber Administrator
Soeben ist eine Bestellung eingegangen, bitte pruefen:
Soeben ist eine Bestellung eingegangen, bitte prüfen:
` + body + `
+1 -5
View File
@@ -383,11 +383,7 @@ func prolongActivation(deveui string, years int) (string, error) {
fmt.Println(t.Unix())
var t_new time.Time
if t.Before(time.Now()) {
t_new = time.Now().AddDate(years, 0, 0)
} else {
t_new = t.AddDate(years, 0, 0)
}
t_new = t.AddDate(years, 0, 0)
active_until_new := t_new.Format(layout)
// SET object
+2 -2
View File
@@ -1,8 +1,8 @@
{{define "body_content"}}
<p class="title is-4">Kontakt</p>
<p>nbit Informatik GmbH<br />
Kirchweg 2<br />
3510 Konolfingen<br />
Untere Stockteile 16<br />
3806 B&ouml;nigen b. Interlaken<br />
<br />
+41 31 792 00 40<br />
<a href='&#109;ai&#108;&#116;o&#58;i&#37;6Ef&#111;&#64;%6Ebi&#116;&#46;%63h'>&#105;nfo&#64;nbit&#46;ch</a>
-21
View File
@@ -16,25 +16,4 @@ Hier sind Sie am richtigen Ort, wenn Sie einen kleinen, sparsamen <a href="/prod
<p class="pb-4">
Hier geht's zur <a href="/product.html">Produktbeschreibung</a>
</p>
{{ if ne .UserName "" }}
<p>
<strong>Ich will weitere bestellen!</strong>
<span class="icon"><i class="fa fa-arrow-right"></i></span>
Hier geht's zur <a href="/order.html">Bestellung</a>
</p>
{{ else }}
<div>
<p>
<strong>Ich will auch einen!</strong>
<span class="icon"><i class="fa fa-arrow-right"></i></span>
Hier geht's zur <a href="/order.html">Bestellung</a>
</p>
<p>&nbsp;</p>
<p class="pb-4">
<strong>Ich habe bereits einen (oder mehrere)</strong>
<span class="icon"><i class="fa fa-arrow-right"></i></span>
Hier geht's zum <a href="/login.html">Login</a>
</p>
</div>
{{end}}
{{end}}
+38 -6
View File
@@ -3,8 +3,9 @@ package main
import (
"encoding/json"
"fmt"
"github.com/stripe/stripe-go/v72"
"github.com/stripe/stripe-go/v72/paymentintent"
"github.com/stripe/stripe-go/v74"
"github.com/stripe/stripe-go/v74/customer"
"github.com/stripe/stripe-go/v74/paymentintent"
"io/ioutil"
"log"
"net/http"
@@ -21,6 +22,33 @@ func getStripePK() string {
return os.Getenv("STRIPE_PK")
}
func getCustomerid(name string) string {
// if customer does not already exist, create it...
var cid = ""
params := &stripe.CustomerSearchParams{}
params.Query = *stripe.String("name:'" + name + "'")
customers := customer.Search(params)
for customers.Next() {
fmt.Printf("%s\n", customers.Current().(*stripe.Customer).ID)
cid = customers.Current().(*stripe.Customer).ID
}
if cid == "" {
// create new customer
paramsc := &stripe.CustomerParams{
Name: stripe.String(name),
}
customer, err := customer.New(paramsc)
if err != nil {
log.Println("Error Creating Customer: " + name)
}
cid = customer.ID
}
return cid
}
func getstripepaymentintentHandler(response http.ResponseWriter, request *http.Request) {
name := getUserName(request)
if name != "" {
@@ -51,10 +79,14 @@ func getstripepaymentintentHandler(response http.ResponseWriter, request *http.R
stripe.Key = getStripeKey()
// if customer does not already exist, create it...
customerid := getCustomerid(name)
// define payment
params := &stripe.PaymentIntentParams{
Amount: stripe.Int64(abo_amount),
Currency: stripe.String(string(stripe.CurrencyCHF)),
ReceiptEmail: stripe.String(name),
Customer: stripe.String(customerid),
Amount: stripe.Int64(abo_amount),
Currency: stripe.String(string(stripe.CurrencyCHF)),
}
params.AddMetadata("charge_data", charge_data[0])
params.AddMetadata("login_user", name)
@@ -121,7 +153,7 @@ func stripeWebhookHandler(w http.ResponseWriter, req *http.Request) {
return
}
fmt.Printf("PaymentIntent was successful (charge_data: %s, amount: %d)!\n", paymentIntent.Metadata["charge_data"], paymentIntent.Amount)
HandlePayment(paymentIntent.ReceiptEmail, paymentIntent.Metadata["charge_data"], paymentIntent.Amount)
HandlePayment(paymentIntent.Metadata["login_user"], paymentIntent.Metadata["charge_data"], paymentIntent.Amount)
// ... handle other event types
default:
fmt.Fprintf(os.Stderr, "Unexpected event type: %s\n", event.Type)
-6
View File
@@ -46,12 +46,6 @@
<span>Kontakt</span>
</div>
</a>
<a class="navbar-item" href="/order.html">
<div style="position:relative">
<span class="icon"><i class="fa fa-shopping-cart"></i></span>
<span>Bestellen</span>
</div>
</a>
{{ if ne .UserName "" }}
<a class="navbar-item" href="/tracker.html">
<div style="position:relative">