Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
534ff18a59 | ||
|
|
89e6d009ef | ||
|
|
e6d8e6321a | ||
|
|
547da06a6f | ||
|
|
cc7d1eafee | ||
|
|
a3f961a7c4 | ||
|
|
117ff4c6aa | ||
|
|
459e656f44 | ||
|
|
14e5536d5d | ||
|
|
4ea5374695 | ||
|
|
75507e26ea | ||
|
|
717fac9efd | ||
|
|
a8f17eed19 | ||
|
|
92c1606f47 | ||
|
|
de40dc68ff | ||
|
|
d2a12cc3bb | ||
|
|
e8fc18bc87 | ||
|
|
a87f5085e7 | ||
|
|
b36ab9e572 | ||
|
|
2168404670 | ||
|
|
025441ef7d | ||
|
|
26957ff42b | ||
|
|
9d947c08ba | ||
|
|
49560c8cec | ||
|
|
5727e667fb | ||
|
|
66fa08d48b | ||
|
|
01c9e06d42 | ||
|
|
8b945eeaba | ||
|
|
fb55a302f9 | ||
|
|
8bf76a4a6c | ||
|
|
15a2827afe | ||
|
|
a827a6e91b | ||
|
|
d8eece9046 | ||
|
|
972f38fe6a | ||
|
|
44e6536c4f | ||
|
|
fb3e1dbe52 |
@@ -1,2 +1,4 @@
|
||||
mini-beieli-web
|
||||
nohup.out
|
||||
mini-beieli-sass/node_modules
|
||||
mini-beieli-sass/package-lock.json
|
||||
|
||||
@@ -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
|
||||
@@ -51,6 +51,13 @@ $ TOKEN="XXXXXX influxdb access token with rw access rights XXXXXX"
|
||||
$ influx delete --token "${TOKEN}" --org minibeieliorg --bucket minibeielibucket --start 2021-06-01T10:53:00Z --stop 2021-06-01T10:53:00Z --predicate '_measurement="measurement" AND deveui="0000D3A659832805"'
|
||||
```
|
||||
|
||||
### Create and Push Docker Image
|
||||
```
|
||||
Example:
|
||||
$ podman login --username drpuur git.nbit.ch
|
||||
$ podman build --tag git.nbit.ch/drpuur/mini-beieli-web:2025080701 -f ./Dockerfile
|
||||
$ podman push git.nbit.ch/drpuur/wo-bisch-web:2025080701
|
||||
```
|
||||
|
||||
Autor: Joerg Lehmann, nbit Informatik GmbH
|
||||
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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=
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,31 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func getConfigFromEnv(item string) string {
|
||||
value := os.Getenv("CONFIG_ENVVAR")
|
||||
if value == "" {
|
||||
value = "ADDRESS,INITIALCOST,YEARLYCOST"
|
||||
}
|
||||
configArr := strings.Split(value, ",")
|
||||
|
||||
// Check for expected length to prevent out-of-range panic
|
||||
if len(configArr) < 3 {
|
||||
logit("CONFIG_ENVVAR has less than 3 elements")
|
||||
return "NOTFOUND"
|
||||
}
|
||||
|
||||
switch strings.ToLower(item) {
|
||||
case "address":
|
||||
return configArr[0]
|
||||
case "initialcost":
|
||||
return configArr[1]
|
||||
case "yearlycost":
|
||||
return configArr[2]
|
||||
default:
|
||||
return "NOTFOUND"
|
||||
}
|
||||
}
|
||||
|
||||
func serveTemplate(w http.ResponseWriter, r *http.Request) {
|
||||
logit("Called URL: " + r.URL.Path)
|
||||
// wennn kein File angegeben ist: index.html
|
||||
@@ -40,6 +65,9 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
t := time.Now()
|
||||
var datetimestring = t.Format("20060102150405")
|
||||
var address = template.HTML(getConfigFromEnv("address"))
|
||||
var initialcost = getConfigFromEnv("initialcost")
|
||||
var yearlycost = getConfigFromEnv("yearlycost")
|
||||
var scales = getMyDevs(userName)
|
||||
var last_metrics []OneMetric
|
||||
|
||||
@@ -63,12 +91,18 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {
|
||||
data := struct {
|
||||
UserName string
|
||||
DateTimeString string
|
||||
Address template.HTML
|
||||
InitialCost string
|
||||
YearlyCost string
|
||||
Scales []string
|
||||
LastMetrics []OneMetric
|
||||
QueryValues map[string][]string
|
||||
}{
|
||||
userName,
|
||||
datetimestring,
|
||||
address,
|
||||
initialcost,
|
||||
yearlycost,
|
||||
scales,
|
||||
last_metrics,
|
||||
query_values,
|
||||
@@ -102,6 +136,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...")
|
||||
}
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
{
|
||||
"name": "mini-beieli-sass",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"description": "SASS for mini-beieli-web",
|
||||
"main": "enter sass/mini-beieli-web.scss",
|
||||
"main": "css/mini-beieli-web.css",
|
||||
"scripts": {
|
||||
"css-build": "node-sass --omit-source-map-url sass/mini-beieli-web.scss css/mini-beieli-web.css",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"css-build": "sass --no-source-map --load-path=node_modules sass/mini-beieli-web.scss css/mini-beieli-web.css",
|
||||
"css-build:min": "sass --no-source-map --load-path=node_modules --style=compressed sass/mini-beieli-web.scss css/mini-beieli-web.min.css",
|
||||
"watch": "sass --watch sass/mini-beieli-web.scss css/mini-beieli-web.css",
|
||||
"clean": "rm -rf css/*",
|
||||
"test": "echo \"No tests yet\""
|
||||
},
|
||||
"author": "Joerg Lehmann",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"bulma": "^0.9.0",
|
||||
"bulma-helpers": "^0.3.12",
|
||||
"node-sass": "^4.14.1"
|
||||
}
|
||||
"bulma": "^1.0.4",
|
||||
"sass": "^1.77.0"
|
||||
},
|
||||
"browserslist": [
|
||||
"> 0.5%",
|
||||
"last 2 versions",
|
||||
"not dead"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
@charset "utf-8";
|
||||
|
||||
// Import a Google Font
|
||||
@import url('https://fonts.googleapis.com/css?family=Rubik:400,700');
|
||||
@use "bulma/sass/utilities/initial-variables" with (
|
||||
$family-sans-serif: ("Rubik", sans-serif)
|
||||
);
|
||||
|
||||
// Set nbit Style...
|
||||
$family-sans-serif: "Rubik", sans-serif;
|
||||
@use "bulma/bulma" as *;
|
||||
|
||||
@import "../node_modules/bulma/bulma.sass";
|
||||
@import "../node_modules/bulma-helpers/bulma-helpers.sass";
|
||||
@import url("https://fonts.googleapis.com/css?family=Rubik:400,700");
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
{{define "body_content"}}
|
||||
<p class="title is-4">Kontakt</p>
|
||||
<p>nbit Informatik GmbH<br />
|
||||
Kirchweg 2<br />
|
||||
3510 Konolfingen<br />
|
||||
<br />
|
||||
+41 31 792 00 40<br />
|
||||
<a href='mailto:i%6Efo@%6Ebit.%63h'>info@nbit.ch</a>
|
||||
<p>{{ .Address }}
|
||||
{{end}}
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<!-- Content ... -->
|
||||
</section>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/apexcharts@3.27.3"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/apexcharts@5.3.2"></script>
|
||||
|
||||
<script src="static/js/chart.js"></script>
|
||||
|
||||
|
||||
@@ -1,9 +1,34 @@
|
||||
{{define "body_content"}}
|
||||
<div class="columns is-multiline">
|
||||
<div class="column is-half">
|
||||
<div class="box">
|
||||
<div class="image">
|
||||
<img src="/static/images/mini-beieli-eine-waage.jpeg" alt="Detail eine Waage">
|
||||
</div>
|
||||
<div class="mt-2">Ansicht auf eine Waage</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-half">
|
||||
<div class="box">
|
||||
<div class="image">
|
||||
<img src="/static/images/mini-beieli-eine-waage-nur-boexli.jpeg" alt="Waage (Boexli)">
|
||||
</div>
|
||||
<hr />
|
||||
<div class="mt-2">Ansicht auf die Box mit der Elektronik/Uebertragungseinheit</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box">
|
||||
<div class="image">
|
||||
<img src="/static/images/mini-beieli-eine-waage.jpeg" alt="Detail eine Waage">
|
||||
<img src="/static/images/mini-beieli-web-screenshot.jpeg" alt="Messwerteübersicht einer Waage">
|
||||
</div>
|
||||
<div class="mt-2">Ansicht auf eine Waage</div>
|
||||
<div class="mt-2">Messwerteübersicht einer Waage</div>
|
||||
</div>
|
||||
<div class="box">
|
||||
<div class="image">
|
||||
<img src="/static/images/mini-beieli-gewichtsentwicklung-screenshot.jpeg" alt="Gewichtsentwicklung">
|
||||
</div>
|
||||
<div class="mt-2">Grafik der Gewichtsentwicklung (Zeitdauer kann gewählt werden)</div>
|
||||
</div>
|
||||
<div class="box">
|
||||
<div class="image">
|
||||
@@ -17,11 +42,4 @@
|
||||
</div>
|
||||
<div class="mt-2">CAD Zeichnung Aluminium-Auflage (CNC gefräst, eloxiert)</div>
|
||||
</div>
|
||||
<div class="box">
|
||||
<div class="image">
|
||||
<img src="/static/images/mini-beieli-kabelkonfektionierung.jpeg" alt="Kabelkonfektionierung">
|
||||
</div>
|
||||
<hr />
|
||||
<div class="mt-2">Kabelkonfektionierung in Werkstatt für Menschen mit Behinderung</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
@@ -5,15 +5,12 @@
|
||||
<div>
|
||||
<div class="message is-danger">
|
||||
<div class="message-body">
|
||||
Aktuell finden Feldversuche statt... Wer trotzdem schon eine möchte, bitte melden!
|
||||
Kann ab sofort gemietet werden. Abokosten pro Kalenderjahr: {{ .YearlyCost }}
|
||||
<br /><br />
|
||||
Hier gibt es einen <a href="static/files/mini-beieli-kurzbeschrieb.pdf" target="_blank">Kurzbeschrieb</a>
|
||||
Hier gibt es einen <a href="static/files/mini-beieli-kurzbeschrieb.pdf" target="_blank">Kurzbeschrieb</a>, hier ein paar <a href="/images.html">Bilder</a>.
|
||||
<br /><br />
|
||||
Sonderpreis: CHF 500.-- (exkl. MwSt., so lange Vorrat, inkl. ein Jahr Abogebühr geschenkt, anschliessend CHF 5.-- pro Monat).
|
||||
Einmalige Kosten pro Waage: {{ .InitialCost }} (so lange Vorrat, beinhaltet das Abo für das erste Kalenderjahr)
|
||||
</div>
|
||||
</div>
|
||||
<div class="image">
|
||||
<a href="/images.html"><img src="/static/images/mini-beieli-ready-to-sell.jpeg" alt="Waagen zum Verkauf"></a>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
{{define "body_content"}}
|
||||
<p class="title is-4">Bestellformular</p>
|
||||
<div class="message is-danger">
|
||||
<div class="message-body">
|
||||
Aktuell noch in Entwicklung, kommen Sie später noch einmal vorbei...
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
After Width: | Height: | Size: 267 KiB |
|
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 350 KiB |
|
After Width: | Height: | Size: 257 KiB |
|
Before Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 331 KiB |
|
After Width: | Height: | Size: 162 KiB |
@@ -17,7 +17,7 @@ function drawGraph(deveui, alias, property, start, stop, minmax, create_graph) {
|
||||
minfunc = function(min) { if (min > 0) { return 0 } else { return min } }
|
||||
maxfunc = function(max) { return max + 5 }
|
||||
labels = {
|
||||
offsetX: 35,
|
||||
offsetX: 12,
|
||||
offsetY: -5,
|
||||
align: 'right'
|
||||
};
|
||||
@@ -28,7 +28,7 @@ function drawGraph(deveui, alias, property, start, stop, minmax, create_graph) {
|
||||
minfunc = function(min) { return 0 }
|
||||
maxfunc = function(max) { return 100 }
|
||||
labels = {
|
||||
offsetX: 30,
|
||||
offsetX: 12,
|
||||
offsetY: -5,
|
||||
align: 'right'
|
||||
};
|
||||
@@ -49,7 +49,7 @@ function drawGraph(deveui, alias, property, start, stop, minmax, create_graph) {
|
||||
]
|
||||
};
|
||||
labels = {
|
||||
offsetX: 45,
|
||||
offsetX: 12,
|
||||
offsetY: -5,
|
||||
align: 'right',
|
||||
formatter: function(val, index) {
|
||||
@@ -63,7 +63,7 @@ function drawGraph(deveui, alias, property, start, stop, minmax, create_graph) {
|
||||
minfunc = function(min) { return 0 }
|
||||
maxfunc = function(max) { return 100 }
|
||||
labels = {
|
||||
offsetX: 30,
|
||||
offsetX: 12,
|
||||
offsetY: -5,
|
||||
align: 'right'
|
||||
};
|
||||
@@ -75,7 +75,7 @@ function drawGraph(deveui, alias, property, start, stop, minmax, create_graph) {
|
||||
minfunc = function(min) { return 900 }
|
||||
maxfunc = function(max) { return 1060 }
|
||||
labels = {
|
||||
offsetX: 35,
|
||||
offsetX: 12,
|
||||
offsetY: -5,
|
||||
align: 'right'
|
||||
};
|
||||
|
||||
@@ -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)),
|
||||
}
|
||||
|
||||