Compare commits
5 Commits
f23a45b9c0
...
ffb27bfd93
| Author | SHA1 | Date |
|---|---|---|
|
|
ffb27bfd93 | |
|
|
4b60cdbcc2 | |
|
|
4cfa05d9fd | |
|
|
9bf854db1a | |
|
|
ed1db2f525 |
46
Dockerfile
46
Dockerfile
|
|
@ -1,46 +0,0 @@
|
||||||
FROM ubuntu:18.04
|
|
||||||
|
|
||||||
ENV DEBIAN_FRONTEND=noninteractive
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y --no-install-recommends \
|
|
||||||
wget \
|
|
||||||
ca-certificates \
|
|
||||||
gcc
|
|
||||||
# linux-libc-dev
|
|
||||||
RUN apt-get clean
|
|
||||||
RUN rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
WORKDIR /usr/local
|
|
||||||
|
|
||||||
# RUN wget https://launchpad.net/ubuntu/+source/glibc/2.27-3ubuntu1.4/+build/20381725/+files/libc6_2.27-3ubuntu1.4_amd64.deb
|
|
||||||
# RUN wget https://launchpad.net/ubuntu/+source/glibc/2.27-3ubuntu1.4/+build/20381725/+files/libc-dev-bin_2.27-3ubuntu1.4_amd64.deb
|
|
||||||
# RUN wget https://launchpad.net/ubuntu/+source/glibc/2.27-3ubuntu1.4/+build/20381725/+files/libc6-dev_2.27-3ubuntu1.4_amd64.deb
|
|
||||||
# RUN dpkg -i libc6_2.27-3ubuntu1.4_amd64.deb
|
|
||||||
# RUN dpkg -i libc-dev-bin_2.27-3ubuntu1.4_amd64.deb
|
|
||||||
# RUN dpkg -i libc6-dev_2.27-3ubuntu1.4_amd64.deb
|
|
||||||
|
|
||||||
# RUN wget https://go.dev/dl/go1.22.3.linux-amd64.tar.gz
|
|
||||||
# RUN tar -xzf go1.22.3.linux-amd64.tar.gz
|
|
||||||
# ENV PATH=$PATH:/usr/local/go/bin
|
|
||||||
|
|
||||||
# WORKDIR /
|
|
||||||
# RUN mkdir /glibc_install
|
|
||||||
# WORKDIR /glibc_install
|
|
||||||
# RUN wget https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/glibc/2.27-3ubuntu1.4/glibc_2.27.orig.tar.xz
|
|
||||||
# RUN tar -xf glibc_2.27.orig.tar.xz
|
|
||||||
# WORKDIR /glibc_install/glibc-2.27
|
|
||||||
# RUN mkdir build
|
|
||||||
# WORKDIR /glibc_install/glibc-2.27/build
|
|
||||||
# RUN ../configure --prefix=/opt/glibc-2.27-3ubuntu1.4
|
|
||||||
# RUN make -j4
|
|
||||||
# RUN make install
|
|
||||||
|
|
||||||
# ENV LD_PRELOAD=/opt/glibc-2.27-3ubuntu1.4/lib/libc.so.6
|
|
||||||
|
|
||||||
# WORKDIR /
|
|
||||||
# RUN rm -rf /glibc_install
|
|
||||||
# RUN rm go1.22.3.linux-amd64.tar.gz
|
|
||||||
# RUN rm libc6-dev_2.27-3ubuntu1.4_amd64.deb
|
|
||||||
|
|
||||||
CMD ["tail", "-f", "/dev/null"]
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"lishwist/templates"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LoginGetProps struct {
|
||||||
|
SuccessfulRegistration bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (auth *AuthMiddleware) Login(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, _ := auth.Store.Get(r, "lishwist_user")
|
||||||
|
successfulReg, ok := session.Values["successful_registration"].(bool)
|
||||||
|
if ok {
|
||||||
|
delete(session.Values, "successful_registration")
|
||||||
|
if err := session.Save(r, w); err != nil {
|
||||||
|
log.Println("Couldn't save session:", err)
|
||||||
|
http.Error(w, "Something went wrong. Error code: Zuko", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
templates.Execute(w, "login.gotmpl", LoginGetProps{
|
||||||
|
SuccessfulRegistration: successfulReg,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"lishwist/db"
|
"lishwist/db"
|
||||||
|
|
@ -41,5 +42,13 @@ func (auth *AuthMiddleware) RegisterPost(w http.ResponseWriter, r *http.Request)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session, _ := auth.Store.Get(r, "lishwist_user")
|
||||||
|
session.Values["successful_registration"] = true
|
||||||
|
if err := session.Save(r, w); err != nil {
|
||||||
|
log.Println("Couldn't save session:", err)
|
||||||
|
http.Error(w, "Something went wrong. Error code: Zuko", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
build.sh
1
build.sh
|
|
@ -1 +0,0 @@
|
||||||
docker run --rm -v "$PWD":/usr/src/lishwist -w /usr/src/lishwist ubuntu-18.04-golang-1.22.3 env GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build .
|
|
||||||
4
db/db.go
4
db/db.go
|
|
@ -5,13 +5,13 @@ package db
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/glebarez/go-sqlite"
|
||||||
)
|
)
|
||||||
|
|
||||||
var database *sql.DB
|
var database *sql.DB
|
||||||
|
|
||||||
func Open() error {
|
func Open() error {
|
||||||
db, err := sql.Open("sqlite3", "./lishwist.db")
|
db, err := sql.Open("sqlite", "./lishwist.db")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,11 @@ func GuaranteeEnv(key string) (variable string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var JwtSecret = GuaranteeEnv("LISHWIST_JWT_SECRET")
|
var JwtSecret = GuaranteeEnv("LISHWIST_JWT_SECRET")
|
||||||
var HostDomain = GuaranteeEnv("LISHWIST_HOST_DOMAIN")
|
var HostRootUrl = GuaranteeEnv("LISHWIST_HOST_ROOT_URL")
|
||||||
var HostPort = os.Getenv("LISHWIST_HOST_PORT")
|
var HostPort = os.Getenv("LISHWIST_HOST_PORT")
|
||||||
var ServePort = GuaranteeEnv("LISHWIST_SERVE_PORT")
|
var ServePort = GuaranteeEnv("LISHWIST_SERVE_PORT")
|
||||||
var HostUrl = func() *url.URL {
|
var HostUrl = func() *url.URL {
|
||||||
rawUrl := "http://" + HostDomain
|
rawUrl := HostRootUrl
|
||||||
if HostPort != "" {
|
if HostPort != "" {
|
||||||
rawUrl += ":" + HostPort
|
rawUrl += ":" + HostPort
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
go.mod
14
go.mod
|
|
@ -3,10 +3,20 @@ module lishwist
|
||||||
go 1.22.0
|
go 1.22.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/glebarez/go-sqlite v1.22.0
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/gorilla/sessions v1.2.2
|
github.com/gorilla/sessions v1.2.2
|
||||||
github.com/mattn/go-sqlite3 v1.14.22
|
|
||||||
golang.org/x/crypto v0.22.0
|
golang.org/x/crypto v0.22.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require github.com/gorilla/securecookie v1.1.2 // indirect
|
require (
|
||||||
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
|
github.com/gorilla/securecookie v1.1.2 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||||
|
golang.org/x/sys v0.19.0 // indirect
|
||||||
|
modernc.org/libc v1.37.6 // indirect
|
||||||
|
modernc.org/mathutil v1.6.0 // indirect
|
||||||
|
modernc.org/memory v1.7.2 // indirect
|
||||||
|
modernc.org/sqlite v1.28.0 // indirect
|
||||||
|
)
|
||||||
|
|
|
||||||
23
go.sum
23
go.sum
|
|
@ -1,12 +1,31 @@
|
||||||
|
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||||
|
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||||
|
github.com/glebarez/go-sqlite v1.22.0 h1:uAcMJhaA6r3LHMTFgP0SifzgXg46yJkgxqyuyec+ruQ=
|
||||||
|
github.com/glebarez/go-sqlite v1.22.0/go.mod h1:PlBIdHe0+aUEFn+r2/uthrWq4FxbzugL0L8Li6yQJbc=
|
||||||
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/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
|
||||||
|
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
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/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
|
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
|
||||||
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
|
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||||
|
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
modernc.org/libc v1.37.6 h1:orZH3c5wmhIQFTXF+Nt+eeauyd+ZIt2BX6ARe+kD+aw=
|
||||||
|
modernc.org/libc v1.37.6/go.mod h1:YAXkAZ8ktnkCKaN9sw/UDeUVkGYJ/YquGO4FTi5nmHE=
|
||||||
|
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
|
||||||
|
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
|
||||||
|
modernc.org/memory v1.7.2 h1:Klh90S215mmH8c9gO98QxQFsY+W451E8AnzjoE2ee1E=
|
||||||
|
modernc.org/memory v1.7.2/go.mod h1:NO4NVCQy0N7ln+T9ngWqOQfi7ley4vpwvARR+Hjw95E=
|
||||||
|
modernc.org/sqlite v1.28.0 h1:Zx+LyDDmXczNnEQdvPuEfcFVA2ZPyaD7UCZDjef3BHQ=
|
||||||
|
modernc.org/sqlite v1.28.0/go.mod h1:Qxpazz0zH8Z1xCFyi5GSL3FzbtZ3fvbjmywNogldEW0=
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -32,7 +32,7 @@ func main() {
|
||||||
|
|
||||||
publicMux.HandleFunc("GET /register", templates.Register)
|
publicMux.HandleFunc("GET /register", templates.Register)
|
||||||
publicMux.HandleFunc("POST /register", authMiddleware.RegisterPost)
|
publicMux.HandleFunc("POST /register", authMiddleware.RegisterPost)
|
||||||
publicMux.HandleFunc("GET /", templates.Login)
|
publicMux.HandleFunc("GET /", authMiddleware.Login)
|
||||||
publicMux.HandleFunc("POST /", authMiddleware.LoginPost)
|
publicMux.HandleFunc("POST /", authMiddleware.LoginPost)
|
||||||
|
|
||||||
protectedMux.HandleFunc("GET /", ctx.Home)
|
protectedMux.HandleFunc("GET /", ctx.Home)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<div class="flex-grow-1"></div>
|
<div class="flex-grow-1"></div>
|
||||||
<ul class="navbar-nav">
|
<ul class="navbar-nav">
|
||||||
<li class="nav-item"><button class="btn btn-success"
|
<li class="nav-item"><button class="btn btn-success"
|
||||||
onclick="navigator.clipboard.writeText('{{.HostUrl}}/{{.Reference}}'); alert('The share link to your wishlist has been copied to your clipboard. Share it with someone!');">Copy
|
onclick="navigator.clipboard.writeText('{{.HostUrl}}/{{.Reference}}'); alert('The share link to your wishlist has been copied to your clipboard. Anyone with the link will be able to claim gifts for you. Share it with someone!');">Copy
|
||||||
share link</button></li>
|
share link</button></li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
|
|
@ -92,4 +92,4 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
package templates
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Login(w http.ResponseWriter, r *http.Request) {
|
|
||||||
Execute(w, "login.gotmpl", nil)
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,12 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "body"}}
|
{{define "body"}}
|
||||||
<div class="flex-grow-1 d-flex justify-content-center align-items-center">
|
<div class="container d-flex flex-grow-1 justify-content-center align-items-center flex-column">
|
||||||
|
{{if .SuccessfulRegistration}}
|
||||||
|
<div class="alert alert-success" role="alert">
|
||||||
|
<p class="mb-0">Registration successful. Now you can login.</p>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="d-flex flex-column gap-3">
|
<div class="d-flex flex-column gap-3">
|
||||||
<label>
|
<label>
|
||||||
|
|
@ -20,4 +25,4 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "body"}}
|
{{define "body"}}
|
||||||
<div class="flex-grow-1 d-flex justify-content-center align-items-center">
|
<div class="container d-flex flex-grow-1 justify-content-center align-items-center flex-column">
|
||||||
|
<div class="alert alert-warning" role="alert">
|
||||||
|
<p>Your password will be stored in a safe, responsible manner; but don't trust my programming skills!</p>
|
||||||
|
<p class="mb-0">Maybe use a password here that you don't use for important things...</p>
|
||||||
|
</div>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="d-flex flex-column gap-3">
|
<div class="d-flex flex-column gap-3">
|
||||||
<label>
|
<label>
|
||||||
|
|
@ -11,11 +15,11 @@
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
Password
|
Password
|
||||||
<input class="form-control" name="newPassword" type="password" required>
|
<input class="form-control" name="newPassword" type="password" required minlength="5">
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
Confirm password
|
Confirm password
|
||||||
<input class="form-control" name="confirmPassword" type="password" required>
|
<input class="form-control" name="confirmPassword" type="password" required minlength="5">
|
||||||
</label>
|
</label>
|
||||||
<input class="btn btn-primary" type="submit" value="Register">
|
<input class="btn btn-primary" type="submit" value="Register">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue