Compare commits
10 Commits
eff25a79f6
...
01c9e06d42
| Author | SHA1 | Date |
|---|---|---|
|
|
01c9e06d42 | |
|
|
8b945eeaba | |
|
|
fb55a302f9 | |
|
|
8bf76a4a6c | |
|
|
15a2827afe | |
|
|
a827a6e91b | |
|
|
d8eece9046 | |
|
|
972f38fe6a | |
|
|
44e6536c4f | |
|
|
fb3e1dbe52 |
|
|
@ -0,0 +1,16 @@
|
|||
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
|
||||
if days_left == 0 {
|
||||
fmt.Printf("SEND EMAIL ABO (%s) - %s:%s\n", level, username, deveui)
|
||||
ablauftext = "Das Abo von \"" + alias + "\" (DevEUI: " + deveui + ") ist abgelaufen."
|
||||
ablauftext = "Das Abo von \"" + alias + "\" (DevEUI: " + deveui + ") laeuft heute ab."
|
||||
} else if days_left > 0 {
|
||||
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."
|
||||
|
|
|
|||
3
go.mod
3
go.mod
|
|
@ -5,7 +5,6 @@ go 1.17
|
|||
require (
|
||||
github.com/gomodule/redigo v1.8.9
|
||||
github.com/gorilla/securecookie v1.1.1
|
||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
|
||||
github.com/stripe/stripe-go v70.15.0+incompatible
|
||||
github.com/stripe/stripe-go/v74 v74.7.0
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
|
||||
)
|
||||
|
|
|
|||
11
go.sum
11
go.sum
|
|
@ -4,23 +4,26 @@ 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/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.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stripe/stripe-go v70.15.0+incompatible h1:hNML7M1zx8RgtepEMlxyu/FpVPrP7KZm1gPFQquJQvM=
|
||||
github.com/stripe/stripe-go v70.15.0+incompatible/go.mod h1:A1dQZmO/QypXmsL0T8axYZkSN/uA/T/A64pfKdBAMiY=
|
||||
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-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
||||
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/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-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
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/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/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
|
|
|
|||
6
mail.go
6
mail.go
|
|
@ -56,7 +56,9 @@ func sendPaymentConfirmationEmail(username, charge_data string, amount int64) {
|
|||
mail_message := "To: " + username + `
|
||||
From: info@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
|
||||
|
||||
Sie haben soeben erfolgreich folgende Abo-Verlaengerungen bezahlt:
|
||||
|
|
@ -65,7 +67,7 @@ Sie haben soeben erfolgreich folgende Abo-Verlaengerungen bezahlt:
|
|||
|
||||
Mit freundlichen Grüssen
|
||||
--
|
||||
mini-beieli.ch`
|
||||
mini-beieli.ch</pre>`
|
||||
|
||||
sendEmail(username, "mail@mini-beieli.ch", mail_message)
|
||||
}
|
||||
|
|
|
|||
2
main.go
2
main.go
|
|
@ -102,6 +102,6 @@ func main() {
|
|||
http.HandleFunc("/checknodes", checkNodesHandler)
|
||||
|
||||
logit("Starting Web Application...")
|
||||
http.ListenAndServe("127.0.0.1:4000", nil)
|
||||
http.ListenAndServe(":4000", nil)
|
||||
logit("Terminating Web Application...")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ func newPool() *redis.Pool {
|
|||
// Dial is an application supplied function for creating and
|
||||
// configuring a connection.
|
||||
Dial: func() (redis.Conn, error) {
|
||||
c, err := redis.Dial("tcp", ":6379")
|
||||
c, err := redis.Dial("tcp", getenv("REDIS_CONNECTION_STRING", ":6379"))
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
|
@ -119,15 +119,14 @@ func checkUserAvailable(username string) bool {
|
|||
conn := globalPool.Get()
|
||||
defer conn.Close()
|
||||
|
||||
_, err := conn.Do("HGETALL", userPrefix+username)
|
||||
if err == redis.ErrNil {
|
||||
logit("User does not exist and is therefore available:" + username)
|
||||
exists, _ := redis.Bool(conn.Do("EXISTS", userPrefix+username))
|
||||
if !exists {
|
||||
logit("checkUserAvailable: User does not exist, so it is available: " + username)
|
||||
return true
|
||||
} else if err != nil {
|
||||
logit("checkUserAvailable: Error to query Key Value Store")
|
||||
} else {
|
||||
logit("checkUserAvailable: User exist, so it is not available: " + username)
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func getMyDevs(username string) []string {
|
||||
|
|
@ -316,11 +315,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
|
||||
|
|
@ -366,6 +361,14 @@ func updateUser(username, password string) {
|
|||
conn := globalPool.Get()
|
||||
defer conn.Close()
|
||||
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)
|
||||
hashedPassword, err := bcrypt.GenerateFromPassword(pwd, bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
|
|
|
|||
37
stripe.go
37
stripe.go
|
|
@ -3,8 +3,9 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/stripe/stripe-go"
|
||||
"github.com/stripe/stripe-go/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,7 +79,12 @@ 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{
|
||||
Customer: stripe.String(customerid),
|
||||
Amount: stripe.Int64(abo_amount),
|
||||
Currency: stripe.String(string(stripe.CurrencyCHF)),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue