Skip to content

Commit c541293

Browse files
fix: mounting assets
1 parent 73fbe77 commit c541293

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
lines changed

internal/procs/auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/ItsNotGoodName/smtpbridge/internal/core"
88
)
99

10-
var ErrorLogin = fmt.Errorf("login error")
10+
var ErrorLogin = fmt.Errorf("login invalid")
1111

1212
func AuthHTTPAnonymous(cc core.Context) bool {
1313
return cc.Config.AuthHTTP.Username == "" && cc.Config.AuthHTTP.Password == ""

web/controllers/auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func Logout(c *fiber.Ctx, cc core.Context, store *session.Store) error {
6262

6363
func UserRequire(c *fiber.Ctx, cc core.Context, store *session.Store) error {
6464
if procs.AuthHTTPAnonymous(cc) {
65-
return h.NotFound(c)
65+
return NotFound(c)
6666
}
6767

6868
return authRequire(c, cc, store)

web/controllers/controllers.go

+4
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,7 @@ func Trim(c *fiber.Ctx, cc core.Context) error {
117117
func SomethingWentWrong(c *fiber.Ctx) error {
118118
return h.Render(c, "something-went-wrong", fiber.Map{"Error": ""})
119119
}
120+
121+
func NotFound(c *fiber.Ctx) error {
122+
return h.Render(c.Status(404), "404", fiber.Map{})
123+
}

web/helpers/http.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,21 @@ func Error(c *fiber.Ctx, err error, codes ...int) error {
2929
return Render(c, "something-went-wrong", fiber.Map{"Error": err})
3030
}
3131

32-
func NotFound(c *fiber.Ctx) error {
33-
return Render(c.Status(404), "404", nil)
34-
}
35-
3632
type Meta struct {
3733
Anonymous bool
3834
CSRF string
3935
}
4036

4137
func Render(c *fiber.Ctx, name string, data fiber.Map, layouts ...string) error {
42-
data["Meta"] = Meta{
43-
Anonymous: c.Locals(AnonymousContextKey) != nil,
44-
CSRF: c.Locals(CSRFContextKey).(string),
38+
meta := Meta{}
39+
if c.Locals(AnonymousContextKey) != nil {
40+
meta.Anonymous = true
4541
}
42+
if csrfRaw := c.Locals(CSRFContextKey); csrfRaw != "" {
43+
meta.CSRF = csrfRaw.(string)
44+
}
45+
46+
data["Meta"] = meta
4647

4748
return c.Render(name, data, layouts...)
4849
}

web/http/http.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/ItsNotGoodName/smtpbridge/internal/core"
88
"github.com/ItsNotGoodName/smtpbridge/web"
9+
"github.com/ItsNotGoodName/smtpbridge/web/controllers"
910
h "github.com/ItsNotGoodName/smtpbridge/web/helpers"
1011
"github.com/gofiber/fiber/v2"
1112
"github.com/gofiber/fiber/v2/middleware/csrf"
@@ -48,14 +49,14 @@ func New(app core.App, shutdown context.CancelFunc, address string, bodyLimit in
4849
ContextKey: h.CSRFContextKey,
4950
Extractor: csrfExtractor(),
5051
}))
51-
web.UseAssets(http)
5252

5353
route(app,
5454
store,
5555
http,
5656
)
5757

58-
http.Use(h.NotFound)
58+
web.UseAssets(http)
59+
http.Use(controllers.NotFound)
5960

6061
return HTTP{
6162
http: http,

web/views/login.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ <h2>Login</h2>
2424
Log in
2525
</button>
2626
{{with .Flash}}
27-
<h3>
27+
<p class="text-red">
2828
{{.}}
29-
</h3>
30-
{{end}}
29+
</pn>
30+
{{end}}
3131
</form>
3232
{{end}}
3333
</article>

0 commit comments

Comments
 (0)