Compare commits
10 Commits
dc450e26dd
...
enhanced_r
Author | SHA1 | Date | |
---|---|---|---|
783ddaf553 | |||
b8b64968bb | |||
aad9cdfaf5 | |||
3738ba689e | |||
65be302aa4 | |||
8ab50cb37c | |||
a833823ad6 | |||
6d6aff50b3 | |||
a6be73765a | |||
ddc9e51831 |
@ -19,7 +19,7 @@ fine with getting your hands dirty, but I plan on having it ready to go for more
|
||||
- Config file handling
|
||||
- Scheduled tasks
|
||||
- Entire website compiles into a single binary (~10mb) (excluding env.json)
|
||||
- Minimal dependencies (just standard library, postgres driver, and experimental package for bcrypt)
|
||||
- Minimal dependencies (just standard library, postgres driver, and x/crypto for bcrypt)
|
||||
|
||||
<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 😤
|
||||
|
||||
- You are free to use this project under the terms of the MIT license. See LICENSE for more details.
|
||||
- You and you alone are responsible for the security and everything else regarding your application.
|
||||
- You 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.
|
||||
- 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.
|
@ -2,6 +2,7 @@ package controllers
|
||||
|
||||
import (
|
||||
"GoWeb/app"
|
||||
"GoWeb/models"
|
||||
"GoWeb/security"
|
||||
"GoWeb/templating"
|
||||
"net/http"
|
||||
@ -12,22 +13,11 @@ type Get struct {
|
||||
App *app.App
|
||||
}
|
||||
|
||||
func (g *Get) ShowHome(w http.ResponseWriter, _ *http.Request) {
|
||||
func (g *Get) ShowHome(w http.ResponseWriter, r *http.Request) {
|
||||
type dataStruct struct {
|
||||
CsrfToken string
|
||||
Test string
|
||||
}
|
||||
|
||||
data := dataStruct{
|
||||
Test: "Hello World!",
|
||||
}
|
||||
|
||||
templating.RenderTemplate(w, "templates/pages/home.html", data)
|
||||
}
|
||||
|
||||
func (g *Get) ShowRegister(w http.ResponseWriter, r *http.Request) {
|
||||
type dataStruct struct {
|
||||
CsrfToken string
|
||||
CsrfToken string
|
||||
IsAuthenticated bool
|
||||
Test string
|
||||
}
|
||||
|
||||
CsrfToken, err := security.GenerateCsrfToken(w, r)
|
||||
@ -35,8 +25,41 @@ func (g *Get) ShowRegister(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
isAuthenticated := true
|
||||
user, err := models.CurrentUser(g.App, r)
|
||||
if err != nil || user.Id == 0 {
|
||||
isAuthenticated = false
|
||||
}
|
||||
|
||||
data := dataStruct{
|
||||
CsrfToken: CsrfToken,
|
||||
CsrfToken: CsrfToken,
|
||||
Test: "Hello World!",
|
||||
IsAuthenticated: isAuthenticated,
|
||||
}
|
||||
|
||||
templating.RenderTemplate(w, "templates/pages/home.html", data)
|
||||
}
|
||||
|
||||
func (g *Get) ShowRegister(w http.ResponseWriter, r *http.Request) {
|
||||
type dataStruct struct {
|
||||
CsrfToken string
|
||||
IsAuthenticated bool
|
||||
}
|
||||
|
||||
CsrfToken, err := security.GenerateCsrfToken(w, r)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
isAuthenticated := true
|
||||
user, err := models.CurrentUser(g.App, r)
|
||||
if err != nil || user.Id == 0 {
|
||||
isAuthenticated = false
|
||||
}
|
||||
|
||||
data := dataStruct{
|
||||
CsrfToken: CsrfToken,
|
||||
IsAuthenticated: isAuthenticated,
|
||||
}
|
||||
|
||||
templating.RenderTemplate(w, "templates/pages/register.html", data)
|
||||
@ -44,7 +67,8 @@ func (g *Get) ShowRegister(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (g *Get) ShowLogin(w http.ResponseWriter, r *http.Request) {
|
||||
type dataStruct struct {
|
||||
CsrfToken string
|
||||
CsrfToken string
|
||||
IsAuthenticated bool
|
||||
}
|
||||
|
||||
CsrfToken, err := security.GenerateCsrfToken(w, r)
|
||||
|
2
go.mod
2
go.mod
@ -4,5 +4,5 @@ go 1.22
|
||||
|
||||
require (
|
||||
github.com/lib/pq v1.10.9
|
||||
golang.org/x/crypto v0.19.0
|
||||
golang.org/x/crypto v0.20.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/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg=
|
||||
golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ=
|
||||
|
@ -25,7 +25,7 @@ func RunAllMigrations(app *app.App) error {
|
||||
Id: 1,
|
||||
UserId: 1,
|
||||
AuthToken: "migrate",
|
||||
RememberMe: false,
|
||||
RememberMe: true, // Booleans must be true to migrate properly
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
err = database.Migrate(app, session)
|
||||
|
@ -22,7 +22,7 @@ func Get(app *app.App) {
|
||||
return
|
||||
}
|
||||
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")
|
||||
|
||||
// Pages
|
||||
|
@ -6,6 +6,21 @@
|
||||
<link href="/static/css/style.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar">
|
||||
{{ if .IsAuthenticated }}
|
||||
<form action="/logout" method="post">
|
||||
<input name="csrf_token" type="hidden" value="{{ .CsrfToken }}">
|
||||
<input type="submit" value="Logout">
|
||||
</form>
|
||||
{{ else }}
|
||||
<form action="/login" method="get">
|
||||
<input type="submit" value="Login">
|
||||
</form>
|
||||
<form action="/register" method="get">
|
||||
<input type="submit" value="Register">
|
||||
</form>
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ template "content" . }}
|
||||
<div class="footer-container">
|
||||
<footer>
|
||||
|
Reference in New Issue
Block a user