Compare commits
3 Commits
master
...
a6be73765a
Author | SHA1 | Date | |
---|---|---|---|
a6be73765a | |||
ddc9e51831 | |||
dc450e26dd |
@ -19,7 +19,7 @@ fine with getting your hands dirty, but I plan on having it ready to go for more
|
|||||||
- Config file handling
|
- Config file handling
|
||||||
- Scheduled tasks
|
- Scheduled tasks
|
||||||
- Entire website compiles into a single binary (~10mb) (excluding env.json)
|
- Entire website compiles into a single binary (~10mb) (excluding env.json)
|
||||||
- Minimal dependencies (just standard library, postgres driver, and x/crypto for bcrypt)
|
- Minimal dependencies (just standard library, postgres driver, and experimental package for bcrypt)
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ fine with getting your hands dirty, but I plan on having it ready to go for more
|
|||||||
### License and disclaimer 😤
|
### License and disclaimer 😤
|
||||||
|
|
||||||
- You are free to use this project under the terms of the MIT license. See LICENSE for more details.
|
- You are free to use this project under the terms of the MIT license. See LICENSE for more details.
|
||||||
- You are responsible for the security and everything else regarding your application.
|
- You and you alone are responsible for the security and everything else regarding your application.
|
||||||
- It is not required, but I ask that when you use this project you give me credit by linking to this repository.
|
- It is not required, but I ask that when you use this project you give me credit by linking to this repository.
|
||||||
- I also ask that when releasing self-hosted or other end-user applications that you release it under
|
- I also ask that when releasing self-hosted or other end-user applications that you release it under
|
||||||
the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) license. This too is not required, but I would appreciate it.
|
the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) license. This too is not required, but I would appreciate it.
|
@ -2,7 +2,6 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"GoWeb/app"
|
"GoWeb/app"
|
||||||
"GoWeb/models"
|
|
||||||
"GoWeb/security"
|
"GoWeb/security"
|
||||||
"GoWeb/templating"
|
"GoWeb/templating"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -15,7 +14,8 @@ type Get struct {
|
|||||||
|
|
||||||
func (g *Get) ShowHome(w http.ResponseWriter, _ *http.Request) {
|
func (g *Get) ShowHome(w http.ResponseWriter, _ *http.Request) {
|
||||||
type dataStruct struct {
|
type dataStruct struct {
|
||||||
Test string
|
CsrfToken string
|
||||||
|
Test string
|
||||||
}
|
}
|
||||||
|
|
||||||
data := dataStruct{
|
data := dataStruct{
|
||||||
@ -58,8 +58,3 @@ func (g *Get) ShowLogin(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
templating.RenderTemplate(w, "templates/pages/login.html", data)
|
templating.RenderTemplate(w, "templates/pages/login.html", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Get) Logout(w http.ResponseWriter, r *http.Request) {
|
|
||||||
models.LogoutUser(g.App, w, r)
|
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
|
||||||
}
|
|
||||||
|
@ -50,3 +50,8 @@ func (p *Post) Register(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
http.Redirect(w, r, "/login", http.StatusFound)
|
http.Redirect(w, r, "/login", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Post) Logout(w http.ResponseWriter, r *http.Request) {
|
||||||
|
models.LogoutUser(p.App, w, r)
|
||||||
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -4,5 +4,5 @@ go 1.22
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/lib/pq v1.10.9
|
github.com/lib/pq v1.10.9
|
||||||
golang.org/x/crypto v0.24.0
|
golang.org/x/crypto v0.19.0
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
go.sum
@ -1,4 +1,4 @@
|
|||||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
|
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
|
||||||
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
|
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||||
|
@ -25,7 +25,7 @@ func RunAllMigrations(app *app.App) error {
|
|||||||
Id: 1,
|
Id: 1,
|
||||||
UserId: 1,
|
UserId: 1,
|
||||||
AuthToken: "migrate",
|
AuthToken: "migrate",
|
||||||
RememberMe: false,
|
RememberMe: true, // Booleans must be true to migrate properly
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
err = database.Migrate(app, session)
|
err = database.Migrate(app, session)
|
||||||
|
@ -22,12 +22,11 @@ func Get(app *app.App) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
staticHandler := http.FileServer(http.FS(staticFS))
|
staticHandler := http.FileServer(http.FS(staticFS))
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", staticHandler))
|
http.Handle("GET /static/", http.StripPrefix("/static/", staticHandler))
|
||||||
slog.Info("serving static files from embedded file system /static")
|
slog.Info("serving static files from embedded file system /static")
|
||||||
|
|
||||||
// Pages
|
// Pages
|
||||||
http.HandleFunc("/", getController.ShowHome)
|
http.HandleFunc("GET /", getController.ShowHome)
|
||||||
http.HandleFunc("/login", getController.ShowLogin)
|
http.HandleFunc("GET /login", getController.ShowLogin)
|
||||||
http.HandleFunc("/register", getController.ShowRegister)
|
http.HandleFunc("GET /register", getController.ShowRegister)
|
||||||
http.HandleFunc("/logout", getController.Logout)
|
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ func Post(app *app.App) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// User authentication
|
// User authentication
|
||||||
http.HandleFunc("/register-handle", middleware.Csrf(postController.Register))
|
http.HandleFunc("POST /register-handle", middleware.Csrf(postController.Register))
|
||||||
http.HandleFunc("/login-handle", middleware.Csrf(postController.Login))
|
http.HandleFunc("POST /login-handle", middleware.Csrf(postController.Login))
|
||||||
|
http.HandleFunc("POST /logout", middleware.Csrf(postController.Logout))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user