git-svn-id: svn://losandesgames.com/alfheim-website@53 15359d88-9307-4e75-a9c1-e5686e5897df
This commit is contained in:
parent
eb222d8677
commit
65e87129a6
12
.vscode/launch.json
vendored
12
.vscode/launch.json
vendored
@ -18,9 +18,9 @@
|
|||||||
"mode": "remote",
|
"mode": "remote",
|
||||||
"port": 4321,
|
"port": 4321,
|
||||||
"host": "losandesgames.com",
|
"host": "losandesgames.com",
|
||||||
"substitutePath": [
|
// "substitutePath": [
|
||||||
{ "from": "${workspaceFolder}", "to": "/home/alfheim/linux_amd64" },
|
// { "from": "${workspaceFolder}", "to": "/home/alfheim/linux_amd64" },
|
||||||
]
|
// ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Launch Remote",
|
"name": "Launch Remote",
|
||||||
@ -31,9 +31,9 @@
|
|||||||
"program": "/home/alfheim/linux_amd64/alfheim-website",
|
"program": "/home/alfheim/linux_amd64/alfheim-website",
|
||||||
"port": 4321,
|
"port": 4321,
|
||||||
"host": "losandesgames.com",
|
"host": "losandesgames.com",
|
||||||
"substitutePath": [
|
// "substitutePath": [
|
||||||
{ "from": "${workspaceFolder}", "to": "/home/alfheim/linux_amd64" },
|
// { "from": "${workspaceFolder}", "to": "/home/alfheim/linux_amd64" },
|
||||||
]
|
// ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
16
Makefile
16
Makefile
@ -1,21 +1,17 @@
|
|||||||
svn_revision = $(shell svn info --show-item revision)
|
svn_revision = $(shell svn info --show-item revision)
|
||||||
|
|
||||||
|
#LDFLAGS = "-X main.version=$(svn_revision)"
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@echo "Building the website..."
|
@echo "Building the website..."
|
||||||
rm -rf bin
|
rm -rf bin
|
||||||
mkdir bin
|
mkdir bin
|
||||||
mkdir bin/static
|
go build -ldflags=$(LDFLAGS) -o bin/alfheim-website ./cmd/web
|
||||||
mkdir bin/ui
|
cp -r ui bin
|
||||||
go build -ldflags="-X main.version=$(svn_revision)" -o bin/alfheim-website ./cmd/web
|
|
||||||
cp -r ui/html bin
|
|
||||||
cp -r ui/static bin
|
|
||||||
cp Caddyfile bin
|
cp Caddyfile bin
|
||||||
mkdir bin/linux_amd64
|
mkdir bin/linux_amd64
|
||||||
mkdir bin/linux_amd64/static
|
GOOS=linux GOARCH=amd64 go build -ldflags=$(LDFLAGS) -o bin/linux_amd64/alfheim-website ./cmd/web
|
||||||
mkdir bin/linux_amd64/ui
|
cp -r ui bin/linux_amd64
|
||||||
GOOS=linux GOARCH=amd64 go build -ldflags="-X main.version=$(svn_revision)" -o bin/linux_amd64/alfheim-website ./cmd/web
|
|
||||||
cp -r ui/html bin/linux_amd64
|
|
||||||
cp -r ui/static bin/linux_amd64
|
|
||||||
cp Caddyfile bin/linux_amd64
|
cp Caddyfile bin/linux_amd64
|
||||||
|
|
||||||
run:
|
run:
|
||||||
|
|||||||
@ -16,13 +16,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/stripe/stripe-go/v78"
|
"github.com/stripe/stripe-go/v83"
|
||||||
"github.com/stripe/stripe-go/v78/billingportal/session"
|
"github.com/stripe/stripe-go/v83/billingportal/session"
|
||||||
"github.com/stripe/stripe-go/v78/customer"
|
"github.com/stripe/stripe-go/v83/customer"
|
||||||
"github.com/stripe/stripe-go/v78/customersession"
|
"github.com/stripe/stripe-go/v83/customersession"
|
||||||
"github.com/stripe/stripe-go/v78/price"
|
"github.com/stripe/stripe-go/v83/price"
|
||||||
"github.com/stripe/stripe-go/v78/subscription"
|
"github.com/stripe/stripe-go/v83/subscription"
|
||||||
"github.com/stripe/stripe-go/v78/webhook"
|
"github.com/stripe/stripe-go/v83/webhook"
|
||||||
|
|
||||||
"alfheimgame.com/alfheim/pkg/models"
|
"alfheimgame.com/alfheim/pkg/models"
|
||||||
)
|
)
|
||||||
@ -84,7 +84,7 @@ func home(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
active_subscription := subscriptions.HasActiveSubscription(id)
|
active_subscription := subscriptions.HasActiveSubscription(id)
|
||||||
|
|
||||||
text, err := template.ParseFiles("ui/base.html", "ui/index.html")
|
text, err := template.ParseFiles("ui/html/base.html", "ui/html/index.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal Server Error", 500)
|
http.Error(w, "Internal Server Error", 500)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -108,7 +108,7 @@ func home(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func login(w http.ResponseWriter, r *http.Request) {
|
func login(w http.ResponseWriter, r *http.Request) {
|
||||||
text, err := template.ParseFiles("ui/base.html", "ui/login.html")
|
text, err := template.ParseFiles("ui/html/base.html", "ui/html/login.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal Server Error", 500)
|
http.Error(w, "Internal Server Error", 500)
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -174,7 +174,7 @@ func login(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func logout(w http.ResponseWriter, r *http.Request) {
|
func logout(w http.ResponseWriter, r *http.Request) {
|
||||||
text, err := template.ParseFiles("ui/base.html", "ui/logout.html")
|
text, err := template.ParseFiles("ui/html/base.html", "ui/html/logout.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal Server Error", 500)
|
http.Error(w, "Internal Server Error", 500)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -209,7 +209,7 @@ func logout(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func register(w http.ResponseWriter, r *http.Request) {
|
func register(w http.ResponseWriter, r *http.Request) {
|
||||||
text, err := template.ParseFiles("ui/base.html", "ui/register.html")
|
text, err := template.ParseFiles("ui/html/base.html", "ui/html/register.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal Server Error", 500)
|
http.Error(w, "Internal Server Error", 500)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -291,7 +291,7 @@ func account(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
//log.Println(id, account)
|
//log.Println(id, account)
|
||||||
|
|
||||||
text, err := template.ParseFiles("ui/base.html", "ui/account.html")
|
text, err := template.ParseFiles("ui/html/base.html", "ui/html/account.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal Server Error", 500)
|
http.Error(w, "Internal Server Error", 500)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -363,7 +363,7 @@ func subscribe(w http.ResponseWriter, r *http.Request) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
text, err := template.New("base.html").Funcs(fm).ParseFiles("ui/base.html", "ui/subscribe.html")
|
text, err := template.New("base.html").Funcs(fm).ParseFiles("ui/html/base.html", "ui/html/subscribe.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal Server Error", 500)
|
http.Error(w, "Internal Server Error", 500)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -399,7 +399,7 @@ func subscribeStripe(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
text, err := template.ParseFiles("ui/base.html", "ui/subscribe_stripe.html")
|
text, err := template.ParseFiles("ui/html/base.html", "ui/html/subscribe_stripe.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal Server Error", 500)
|
http.Error(w, "Internal Server Error", 500)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -421,7 +421,7 @@ func manageBilling(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
params := &stripe.BillingPortalSessionParams{
|
params := &stripe.BillingPortalSessionParams{
|
||||||
Customer: stripe.String(account.StripeID),
|
Customer: stripe.String(account.StripeID),
|
||||||
ReturnURL: stripe.String("http://localhost:8080/account"),
|
ReturnURL: stripe.String("https://alfheimgame.com/account"),
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := session.New(params)
|
result, err := session.New(params)
|
||||||
|
|||||||
@ -5,17 +5,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"database/sql"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
|
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
_ "github.com/lib/pq"
|
|
||||||
"github.com/stripe/stripe-go/v78"
|
"github.com/stripe/stripe-go/v83"
|
||||||
|
|
||||||
"alfheimgame.com/alfheim/pkg/models/postgresql"
|
"alfheimgame.com/alfheim/pkg/models/postgresql"
|
||||||
)
|
)
|
||||||
@ -53,11 +54,12 @@ func main() {
|
|||||||
|
|
||||||
store.MaxAge(0)
|
store.MaxAge(0)
|
||||||
|
|
||||||
db, err := sql.Open("postgres", "postgres://elves_database:iK2SoVbDhdCki5n3LxGyP6zKpLspt4@80.240.25.87/elves_database")
|
db, err := pgx.Connect(context.Background(), "postgres://alfheim:iK2SoVbDhdCki5n3LxGyP6zKpLspt4@losandesgames.com/alfheim")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer db.Close()
|
|
||||||
|
defer db.Close(context.Background())
|
||||||
|
|
||||||
users = &postgresql.AccountModel{DB: db}
|
users = &postgresql.AccountModel{DB: db}
|
||||||
subscriptions = &postgresql.SubscriptionModel{DB: db}
|
subscriptions = &postgresql.SubscriptionModel{DB: db}
|
||||||
@ -73,7 +75,7 @@ func main() {
|
|||||||
//accounts := make([]*Account, 0)
|
//accounts := make([]*Account, 0)
|
||||||
//for rows.Next() {
|
//for rows.Next() {
|
||||||
// acc := new(Account)
|
// acc := new(Account)
|
||||||
// err := rows.Scan(&acc.id, &acc.Username, &acc.password, &acc.Color)
|
// err := rows.Scan(&acc.id, &acc.Username, &acc.password, &acc.Colour)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// log.Fatal(err)
|
// log.Fatal(err)
|
||||||
// }
|
// }
|
||||||
@ -88,7 +90,7 @@ func main() {
|
|||||||
// log.Println(acc)
|
// log.Println(acc)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("ui/static"))))
|
||||||
|
|
||||||
mux.HandleFunc("/favicon.ico", favicon)
|
mux.HandleFunc("/favicon.ico", favicon)
|
||||||
|
|
||||||
|
|||||||
18
go.mod
18
go.mod
@ -1,16 +1,22 @@
|
|||||||
module alfheimgame.com/alfheim
|
module alfheimgame.com/alfheim
|
||||||
|
|
||||||
go 1.24
|
go 1.24.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/alexedwards/argon2id v1.0.0
|
github.com/alexedwards/argon2id v1.0.0
|
||||||
github.com/gorilla/sessions v1.2.2
|
github.com/gorilla/sessions v1.4.0
|
||||||
github.com/lib/pq v1.10.9
|
github.com/jackc/pgx/v5 v5.7.6
|
||||||
github.com/stripe/stripe-go/v78 v78.7.0
|
github.com/stripe/stripe-go/v83 v83.0.0
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||||
|
golang.org/x/text v0.29.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gorilla/securecookie v1.1.2 // indirect
|
github.com/gorilla/securecookie v1.1.2 // indirect
|
||||||
golang.org/x/crypto v0.33.0 // indirect
|
golang.org/x/crypto v0.42.0 // indirect
|
||||||
golang.org/x/sys v0.30.0 // indirect
|
golang.org/x/sys v0.36.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
47
go.sum
47
go.sum
@ -1,52 +1,63 @@
|
|||||||
github.com/alexedwards/argon2id v1.0.0 h1:wJzDx66hqWX7siL/SRUmgz3F8YMrd/nfX/xHHcQQP0w=
|
github.com/alexedwards/argon2id v1.0.0 h1:wJzDx66hqWX7siL/SRUmgz3F8YMrd/nfX/xHHcQQP0w=
|
||||||
github.com/alexedwards/argon2id v1.0.0/go.mod h1:tYKkqIjzXvZdzPvADMWOEZ+l6+BD6CtBXMj5fnJppiw=
|
github.com/alexedwards/argon2id v1.0.0/go.mod h1:tYKkqIjzXvZdzPvADMWOEZ+l6+BD6CtBXMj5fnJppiw=
|
||||||
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/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
|
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
|
||||||
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
|
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
|
||||||
github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY=
|
github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY=
|
||||||
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
|
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
|
||||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzqQ=
|
||||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik=
|
||||||
|
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||||
|
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||||
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||||
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||||
|
github.com/jackc/pgx/v5 v5.7.6 h1:rWQc5FwZSPX58r1OQmkuaNicxdmExaEz5A2DO2hUuTk=
|
||||||
|
github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
|
||||||
|
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||||
|
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||||
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.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
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/v78 v78.7.0 h1:TdTkzBn0wB0ntgOI74YHpvsNyHPBijX83n4ljsjXh6o=
|
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||||
github.com/stripe/stripe-go/v78 v78.7.0/go.mod h1:GjncxVLUc1xoIOidFqVwq+y3pYiG7JLVWiVQxTsLrvQ=
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
github.com/stripe/stripe-go/v83 v83.0.0 h1:00HYu/n80zH6ugy88bWI5sBLbJZ7WmhCXCRQ1N1tuqI=
|
||||||
|
github.com/stripe/stripe-go/v83 v83.0.0/go.mod h1:nRyDcLrJtwPPQUnKAFs9Bt1NnQvNhNiF6V19XHmPISE=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||||
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
|
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
|
||||||
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
|
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
|
||||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
|
||||||
|
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
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-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
|
||||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
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/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
@ -54,18 +65,18 @@ golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
|||||||
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
|
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
|
||||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
|
||||||
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=
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
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=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
@ -18,7 +18,7 @@ type Account struct {
|
|||||||
ID int32
|
ID int32
|
||||||
Username string
|
Username string
|
||||||
Password []byte
|
Password []byte
|
||||||
Color int32
|
Colour int32
|
||||||
Firstname string
|
Firstname string
|
||||||
Lastname string
|
Lastname string
|
||||||
Email string
|
Email string
|
||||||
|
|||||||
@ -1,23 +1,21 @@
|
|||||||
package postgresql
|
package postgresql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
//import "golang.org/x/crypto/bcrypt"
|
|
||||||
|
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
|
|
||||||
"github.com/alexedwards/argon2id"
|
"github.com/alexedwards/argon2id"
|
||||||
_ "github.com/lib/pq"
|
"github.com/stripe/stripe-go/v83"
|
||||||
"github.com/stripe/stripe-go/v78"
|
"github.com/stripe/stripe-go/v83/customer"
|
||||||
"github.com/stripe/stripe-go/v78/customer"
|
|
||||||
|
|
||||||
"alfheimgame.com/alfheim/pkg/models"
|
"alfheimgame.com/alfheim/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AccountModel struct {
|
type AccountModel struct {
|
||||||
DB *sql.DB
|
DB *pgx.Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *AccountModel) Insert(username string, password string, firstname string, lastname string, email string) (int32, error) {
|
func (m *AccountModel) Insert(username string, password string, firstname string, lastname string, email string) (int32, error) {
|
||||||
@ -31,17 +29,11 @@ func (m *AccountModel) Insert(username string, password string, firstname string
|
|||||||
}
|
}
|
||||||
|
|
||||||
//log.Println(hashedpassword)
|
//log.Println(hashedpassword)
|
||||||
stmt := `INSERT INTO accounts (username, password, firstname, lastname, email, created) VALUES ($1, $2, $3, $4, $5, NOW()) RETURNING id`
|
stmt := `INSERT INTO accounts (username, password, firstname, lastname, email) VALUES ($1, $2, $3, $4, $5) RETURNING id`
|
||||||
|
|
||||||
var insertid int32
|
var insertid int32
|
||||||
|
|
||||||
row := m.DB.QueryRow(stmt, username, string(hashedpassword), firstname, lastname, email)
|
err = m.DB.QueryRow(context.Background(), stmt, username, string(hashedpassword), firstname, lastname, email).Scan(&insertid)
|
||||||
if row.Err() != nil {
|
|
||||||
log.Println(row.Err())
|
|
||||||
return 0, row.Err()
|
|
||||||
}
|
|
||||||
|
|
||||||
err = row.Scan(&insertid)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -60,9 +52,7 @@ func (m *AccountModel) Insert(username string, password string, firstname string
|
|||||||
|
|
||||||
stmt = `UPDATE accounts SET stripe_id = $1 WHERE id = $2`
|
stmt = `UPDATE accounts SET stripe_id = $1 WHERE id = $2`
|
||||||
|
|
||||||
//log.Println(customer.ID, insertid)
|
_, err = m.DB.Exec(context.Background(), stmt, customer.ID, insertid)
|
||||||
|
|
||||||
_, err = m.DB.Exec(stmt, customer.ID, insertid)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -89,7 +79,7 @@ func (m *AccountModel) Delete(id int32) error {
|
|||||||
|
|
||||||
stmt := `DELETE FROM accounts WHERE id = $1`
|
stmt := `DELETE FROM accounts WHERE id = $1`
|
||||||
|
|
||||||
_, err = m.DB.Exec(stmt, id)
|
_, err = m.DB.Exec(context.Background(), stmt, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
@ -101,14 +91,13 @@ func (m *AccountModel) GetAccount(id int32) (models.Account, error) {
|
|||||||
if id == 0 {
|
if id == 0 {
|
||||||
return models.Account{}, models.ErrNoRecord
|
return models.Account{}, models.ErrNoRecord
|
||||||
}
|
}
|
||||||
stmt := `SELECT id, username, password, color, firstname, lastname, email, created, stripe_id FROM accounts WHERE id = $1`
|
|
||||||
row := m.DB.QueryRow(stmt, id)
|
|
||||||
|
|
||||||
var account models.Account
|
var account models.Account
|
||||||
err := row.Scan(&account.ID, &account.Username, &account.Password, &account.Color, &account.Firstname, &account.Lastname, &account.Email, &account.Created, &account.StripeID)
|
stmt := `SELECT id, username, password, colour, firstname, lastname, email, created, stripe_id FROM accounts WHERE id = $1`
|
||||||
|
err := m.DB.QueryRow(context.Background(), stmt, id).Scan(&account.ID, &account.Username, &account.Password, &account.Colour, &account.Firstname, &account.Lastname, &account.Email, &account.Created, &account.StripeID)
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == pgx.ErrNoRows {
|
||||||
return models.Account{}, sql.ErrNoRows
|
return models.Account{}, pgx.ErrNoRows
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return models.Account{}, err
|
return models.Account{}, err
|
||||||
}
|
}
|
||||||
@ -119,9 +108,9 @@ func (m *AccountModel) GetAccount(id int32) (models.Account, error) {
|
|||||||
func (m *AccountModel) Authenticate(username string, password string) (int32, error) {
|
func (m *AccountModel) Authenticate(username string, password string) (int32, error) {
|
||||||
var id int32
|
var id int32
|
||||||
var hashedpassword string
|
var hashedpassword string
|
||||||
row := m.DB.QueryRow("SELECT id, password FROM accounts WHERE username = $1", username)
|
stmt := `SELECT id, password FROM accounts WHERE username = $1`
|
||||||
err := row.Scan(&id, &hashedpassword)
|
err := m.DB.QueryRow(context.Background(), stmt, username).Scan(&id, &hashedpassword)
|
||||||
if err == sql.ErrNoRows {
|
if err == pgx.ErrNoRows {
|
||||||
return 0, models.ErrInvalidCredentials
|
return 0, models.ErrInvalidCredentials
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,11 +127,10 @@ func (m *AccountModel) Authenticate(username string, password string) (int32, er
|
|||||||
func (m *AccountModel) ExistsAccount(id int32) bool {
|
func (m *AccountModel) ExistsAccount(id int32) bool {
|
||||||
var exists bool
|
var exists bool
|
||||||
stmt := `SELECT EXISTS(SELECT 1 FROM accounts WHERE id = $1)`
|
stmt := `SELECT EXISTS(SELECT 1 FROM accounts WHERE id = $1)`
|
||||||
row := m.DB.QueryRow(stmt, id)
|
err := m.DB.QueryRow(context.Background(), stmt, id).Scan(&exists)
|
||||||
if row.Err() != nil {
|
if err != nil {
|
||||||
log.Println(row.Err())
|
log.Println(err)
|
||||||
}
|
}
|
||||||
row.Scan(&exists)
|
|
||||||
|
|
||||||
//log.Println(exists)
|
//log.Println(exists)
|
||||||
|
|
||||||
|
|||||||
@ -1,33 +1,26 @@
|
|||||||
package postgresql
|
package postgresql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"context"
|
||||||
|
|
||||||
//import "golang.org/x/crypto/bcrypt"
|
"github.com/jackc/pgx/v5"
|
||||||
|
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
_ "github.com/lib/pq"
|
"github.com/stripe/stripe-go/v83"
|
||||||
"github.com/stripe/stripe-go/v78"
|
|
||||||
|
|
||||||
"alfheimgame.com/alfheim/pkg/models"
|
"alfheimgame.com/alfheim/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SubscriptionModel struct {
|
type SubscriptionModel struct {
|
||||||
DB *sql.DB
|
DB *pgx.Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SubscriptionModel) Insert(stripeid string, stripesubscriptionid string, stripecheckoutid string, status stripe.SubscriptionStatus) (int32, error) {
|
func (m *SubscriptionModel) Insert(stripeid string, stripesubscriptionid string, stripecheckoutid string, status stripe.SubscriptionStatus) (int32, error) {
|
||||||
var id int32
|
var id int32
|
||||||
stmt := `SELECT id FROM accounts WHERE stripe_id = $1`
|
stmt := `SELECT id FROM accounts WHERE stripe_id = $1`
|
||||||
|
|
||||||
row := m.DB.QueryRow(stmt, stripeid)
|
err := m.DB.QueryRow(context.Background(), stmt, stripeid).Scan(&id)
|
||||||
if row.Err() != nil {
|
|
||||||
log.Println(row.Err())
|
|
||||||
return 0, row.Err()
|
|
||||||
}
|
|
||||||
|
|
||||||
err := row.Scan(&id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -37,13 +30,7 @@ func (m *SubscriptionModel) Insert(stripeid string, stripesubscriptionid string,
|
|||||||
|
|
||||||
var insertid int32
|
var insertid int32
|
||||||
|
|
||||||
row = m.DB.QueryRow(stmt, id, string(stripesubscriptionid), string(stripecheckoutid), string(status))
|
err = m.DB.QueryRow(context.Background(), stmt, id, string(stripesubscriptionid), string(stripecheckoutid), string(status)).Scan(&insertid)
|
||||||
if row.Err() != nil {
|
|
||||||
log.Println(row.Err())
|
|
||||||
return 0, row.Err()
|
|
||||||
}
|
|
||||||
|
|
||||||
err = row.Scan(&insertid)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -55,7 +42,7 @@ func (m *SubscriptionModel) Insert(stripeid string, stripesubscriptionid string,
|
|||||||
func (m *SubscriptionModel) Delete(id int32) error {
|
func (m *SubscriptionModel) Delete(id int32) error {
|
||||||
stmt := `DELETE FROM accounts WHERE id = $1`
|
stmt := `DELETE FROM accounts WHERE id = $1`
|
||||||
|
|
||||||
_, err := m.DB.Exec(stmt, id)
|
_, err := m.DB.Exec(context.Background(), stmt, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return err
|
return err
|
||||||
@ -69,20 +56,16 @@ func (m *SubscriptionModel) GetSubscription(id int32) (models.Subscription, erro
|
|||||||
return models.Subscription{}, models.ErrNoRecord
|
return models.Subscription{}, models.ErrNoRecord
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt := `SELECT id, account_id, stripe_subscription_id, stripe_checkout_id, status FROM subscriptions WHERE id = $1`
|
|
||||||
row := m.DB.QueryRow(stmt, id)
|
|
||||||
|
|
||||||
var subscription models.Subscription
|
var subscription models.Subscription
|
||||||
err := row.Scan(&subscription.ID, &subscription.AccountID, &subscription.StripeSubscriptionID, &subscription.StripeCheckoutID, &subscription.Status)
|
stmt := `SELECT id, account_id, stripe_subscription_id, stripe_checkout_id, status FROM subscriptions WHERE id = $1`
|
||||||
|
err := m.DB.QueryRow(context.Background(), stmt, id).Scan(&subscription.ID, &subscription.AccountID, &subscription.StripeSubscriptionID, &subscription.StripeCheckoutID, &subscription.Status)
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == pgx.ErrNoRows {
|
||||||
return models.Subscription{}, sql.ErrNoRows
|
return models.Subscription{}, pgx.ErrNoRows
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return models.Subscription{}, err
|
return models.Subscription{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//log.Println(subscription.Status)
|
|
||||||
|
|
||||||
return subscription, nil
|
return subscription, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +75,7 @@ func (m *SubscriptionModel) GetSubscriptionsFromAccount(accountid int32) ([]mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
stmt := `SELECT id, account_id, stripe_subscription_id, stripe_checkout_id, status FROM subscriptions WHERE account_id = $1`
|
stmt := `SELECT id, account_id, stripe_subscription_id, stripe_checkout_id, status FROM subscriptions WHERE account_id = $1`
|
||||||
rows, err := m.DB.Query(stmt, accountid)
|
rows, err := m.DB.Query(context.Background(), stmt, accountid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -102,8 +85,8 @@ func (m *SubscriptionModel) GetSubscriptionsFromAccount(accountid int32) ([]mode
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var subscription models.Subscription
|
var subscription models.Subscription
|
||||||
err := rows.Scan(&subscription.ID, &subscription.AccountID, &subscription.StripeSubscriptionID, &subscription.StripeCheckoutID, &subscription.Status)
|
err := rows.Scan(&subscription.ID, &subscription.AccountID, &subscription.StripeSubscriptionID, &subscription.StripeCheckoutID, &subscription.Status)
|
||||||
if err == sql.ErrNoRows {
|
if err == pgx.ErrNoRows {
|
||||||
return nil, sql.ErrNoRows
|
return nil, pgx.ErrNoRows
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<div>Username: {{.Account.Username}}</div>
|
<div>Username: {{.Account.Username}}</div>
|
||||||
<div>First name: {{.Account.Firstname}}</div>
|
<div>First name: {{.Account.Firstname}}</div>
|
||||||
<div>Last name: {{.Account.Lastname}}</div>
|
<div>Last name: {{.Account.Lastname}}</div>
|
||||||
<div>Color: {{.Account.Color}}</div>
|
<div>Colour: {{.Account.Colour}}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user