Compare commits
No commits in common. "01c9e06d42b10f253a89061a28c29378d3bfa520" and "eff25a79f6b6927b478370df0a5d2d6fcb8725b5" have entirely different histories.
01c9e06d42
...
eff25a79f6
16
Dockerfile
16
Dockerfile
|
|
@ -1,16 +0,0 @@
|
||||||
FROM golang:alpine AS builder
|
|
||||||
WORKDIR /build
|
|
||||||
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/mini-beieli-web /build/mini-beieli-web
|
|
||||||
COPY snippets snippets
|
|
||||||
COPY templates templates
|
|
||||||
COPY static static
|
|
||||||
CMD ["./mini-beieli-web"]
|
|
||||||
EXPOSE 4000
|
|
||||||
|
|
@ -30,7 +30,7 @@ func sendEmailAbo(username string, alias string, deveui string, days_left int, l
|
||||||
var ablauftext string
|
var ablauftext string
|
||||||
if days_left == 0 {
|
if days_left == 0 {
|
||||||
fmt.Printf("SEND EMAIL ABO (%s) - %s:%s\n", level, username, deveui)
|
fmt.Printf("SEND EMAIL ABO (%s) - %s:%s\n", level, username, deveui)
|
||||||
ablauftext = "Das Abo von \"" + alias + "\" (DevEUI: " + deveui + ") laeuft heute ab."
|
ablauftext = "Das Abo von \"" + alias + "\" (DevEUI: " + deveui + ") ist abgelaufen."
|
||||||
} else if days_left > 0 {
|
} else if days_left > 0 {
|
||||||
fmt.Printf("SEND EMAIL ABO (%s) - %s:%s\n", level, username, deveui)
|
fmt.Printf("SEND EMAIL ABO (%s) - %s:%s\n", level, username, deveui)
|
||||||
ablauftext = "Das Abo von \"" + alias + "\" (DevEUI: " + deveui + ") laeuft in " + strconv.Itoa(days_left) + " Tagen ab."
|
ablauftext = "Das Abo von \"" + alias + "\" (DevEUI: " + deveui + ") laeuft in " + strconv.Itoa(days_left) + " Tagen ab."
|
||||||
|
|
|
||||||
3
go.mod
3
go.mod
|
|
@ -5,6 +5,7 @@ go 1.17
|
||||||
require (
|
require (
|
||||||
github.com/gomodule/redigo v1.8.9
|
github.com/gomodule/redigo v1.8.9
|
||||||
github.com/gorilla/securecookie v1.1.1
|
github.com/gorilla/securecookie v1.1.1
|
||||||
github.com/stripe/stripe-go/v74 v74.7.0
|
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
|
||||||
|
github.com/stripe/stripe-go v70.15.0+incompatible
|
||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
|
||||||
)
|
)
|
||||||
|
|
|
||||||
11
go.sum
11
go.sum
|
|
@ -4,26 +4,23 @@ github.com/gomodule/redigo v1.8.9 h1:Sl3u+2BI/kk+VEatbj0scLdrFhjPmbxOc1myhDP41ws
|
||||||
github.com/gomodule/redigo v1.8.9/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE=
|
github.com/gomodule/redigo v1.8.9/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE=
|
||||||
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
|
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/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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
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/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
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 v70.15.0+incompatible h1:hNML7M1zx8RgtepEMlxyu/FpVPrP7KZm1gPFQquJQvM=
|
||||||
github.com/stripe/stripe-go/v74 v74.7.0/go.mod h1:5PoXNp30AJ3tGq57ZcFuaMylzNi8KpwlrYAFmO1fHZw=
|
github.com/stripe/stripe-go v70.15.0+incompatible/go.mod h1:A1dQZmO/QypXmsL0T8axYZkSN/uA/T/A64pfKdBAMiY=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
|
||||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
|
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
|
||||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
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/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
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.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
|
|
||||||
6
mail.go
6
mail.go
|
|
@ -56,9 +56,7 @@ func sendPaymentConfirmationEmail(username, charge_data string, amount int64) {
|
||||||
mail_message := "To: " + username + `
|
mail_message := "To: " + username + `
|
||||||
From: info@mini-beieli.ch
|
From: info@mini-beieli.ch
|
||||||
Subject: Zahlungsbestaetigung mini-beieli.ch
|
Subject: Zahlungsbestaetigung mini-beieli.ch
|
||||||
MIME-version: 1.0;
|
|
||||||
Content-Type: text/html; charset="UTF-8";
|
|
||||||
<pre>
|
|
||||||
Lieber Benutzer von mini-beieli.ch
|
Lieber Benutzer von mini-beieli.ch
|
||||||
|
|
||||||
Sie haben soeben erfolgreich folgende Abo-Verlaengerungen bezahlt:
|
Sie haben soeben erfolgreich folgende Abo-Verlaengerungen bezahlt:
|
||||||
|
|
@ -67,7 +65,7 @@ Sie haben soeben erfolgreich folgende Abo-Verlaengerungen bezahlt:
|
||||||
|
|
||||||
Mit freundlichen Grüssen
|
Mit freundlichen Grüssen
|
||||||
--
|
--
|
||||||
mini-beieli.ch</pre>`
|
mini-beieli.ch`
|
||||||
|
|
||||||
sendEmail(username, "mail@mini-beieli.ch", mail_message)
|
sendEmail(username, "mail@mini-beieli.ch", mail_message)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -102,6 +102,6 @@ func main() {
|
||||||
http.HandleFunc("/checknodes", checkNodesHandler)
|
http.HandleFunc("/checknodes", checkNodesHandler)
|
||||||
|
|
||||||
logit("Starting Web Application...")
|
logit("Starting Web Application...")
|
||||||
http.ListenAndServe(":4000", nil)
|
http.ListenAndServe("127.0.0.1:4000", nil)
|
||||||
logit("Terminating Web Application...")
|
logit("Terminating Web Application...")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ func newPool() *redis.Pool {
|
||||||
// Dial is an application supplied function for creating and
|
// Dial is an application supplied function for creating and
|
||||||
// configuring a connection.
|
// configuring a connection.
|
||||||
Dial: func() (redis.Conn, error) {
|
Dial: func() (redis.Conn, error) {
|
||||||
c, err := redis.Dial("tcp", getenv("REDIS_CONNECTION_STRING", ":6379"))
|
c, err := redis.Dial("tcp", ":6379")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -119,14 +119,15 @@ func checkUserAvailable(username string) bool {
|
||||||
conn := globalPool.Get()
|
conn := globalPool.Get()
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
exists, _ := redis.Bool(conn.Do("EXISTS", userPrefix+username))
|
_, err := conn.Do("HGETALL", userPrefix+username)
|
||||||
if !exists {
|
if err == redis.ErrNil {
|
||||||
logit("checkUserAvailable: User does not exist, so it is available: " + username)
|
logit("User does not exist and is therefore available:" + username)
|
||||||
return true
|
return true
|
||||||
} else {
|
} else if err != nil {
|
||||||
logit("checkUserAvailable: User exist, so it is not available: " + username)
|
logit("checkUserAvailable: Error to query Key Value Store")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMyDevs(username string) []string {
|
func getMyDevs(username string) []string {
|
||||||
|
|
@ -315,7 +316,11 @@ func prolongActivation(deveui string, years int) (string, error) {
|
||||||
fmt.Println(t.Unix())
|
fmt.Println(t.Unix())
|
||||||
|
|
||||||
var t_new time.Time
|
var t_new time.Time
|
||||||
t_new = t.AddDate(years, 0, 0)
|
if t.Before(time.Now()) {
|
||||||
|
t_new = time.Now().AddDate(years, 0, 0)
|
||||||
|
} else {
|
||||||
|
t_new = t.AddDate(years, 0, 0)
|
||||||
|
}
|
||||||
active_until_new := t_new.Format(layout)
|
active_until_new := t_new.Format(layout)
|
||||||
|
|
||||||
// SET object
|
// SET object
|
||||||
|
|
@ -361,14 +366,6 @@ func updateUser(username, password string) {
|
||||||
conn := globalPool.Get()
|
conn := globalPool.Get()
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
logit("updateUser: " + username)
|
logit("updateUser: " + username)
|
||||||
|
|
||||||
// we exit if user does not exit
|
|
||||||
exists, _ := redis.Bool(conn.Do("EXISTS", userPrefix+username))
|
|
||||||
if !exists {
|
|
||||||
logit("updateUser: User does not exist: " + username)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
pwd := []byte(password)
|
pwd := []byte(password)
|
||||||
hashedPassword, err := bcrypt.GenerateFromPassword(pwd, bcrypt.DefaultCost)
|
hashedPassword, err := bcrypt.GenerateFromPassword(pwd, bcrypt.DefaultCost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
37
stripe.go
37
stripe.go
|
|
@ -3,9 +3,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/stripe/stripe-go/v74"
|
"github.com/stripe/stripe-go"
|
||||||
"github.com/stripe/stripe-go/v74/customer"
|
"github.com/stripe/stripe-go/paymentintent"
|
||||||
"github.com/stripe/stripe-go/v74/paymentintent"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -22,33 +21,6 @@ func getStripePK() string {
|
||||||
return os.Getenv("STRIPE_PK")
|
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) {
|
func getstripepaymentintentHandler(response http.ResponseWriter, request *http.Request) {
|
||||||
name := getUserName(request)
|
name := getUserName(request)
|
||||||
if name != "" {
|
if name != "" {
|
||||||
|
|
@ -79,12 +51,7 @@ func getstripepaymentintentHandler(response http.ResponseWriter, request *http.R
|
||||||
|
|
||||||
stripe.Key = getStripeKey()
|
stripe.Key = getStripeKey()
|
||||||
|
|
||||||
// if customer does not already exist, create it...
|
|
||||||
customerid := getCustomerid(name)
|
|
||||||
|
|
||||||
// define payment
|
|
||||||
params := &stripe.PaymentIntentParams{
|
params := &stripe.PaymentIntentParams{
|
||||||
Customer: stripe.String(customerid),
|
|
||||||
Amount: stripe.Int64(abo_amount),
|
Amount: stripe.Int64(abo_amount),
|
||||||
Currency: stripe.String(string(stripe.CurrencyCHF)),
|
Currency: stripe.String(string(stripe.CurrencyCHF)),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue