Can now set an auth cookie to check for auth, but I should see what it takes to make a middleware.

main
Zed A. Shaw 16 hours ago
parent 05788e5fbb
commit b0c4144987
  1. 30
      api/controllers.go
  2. 2
      public/login/index.html
  3. 1
      public/stream/1/index.html

@ -13,9 +13,25 @@ import (
var STORE *session.Store
func Logout(c *fiber.Ctx) error {
sess, err := STORE.Get(c)
if err != nil { return IfErrNil(err, c) }
sess.Set("authenticated", false)
err = sess.Save()
if err != nil { return IfErrNil(err, c) }
return c.Redirect("/")
}
func GetApiStream(c *fiber.Ctx) error {
sess, err := STORE.Get(c)
sess.Set("fuck", "off")
if err != nil { return IfErrNil(err, c) }
if sess.Get("authenticated") != true {
// NOTE: need my own error thing
return IfErrNil(err, c)
}
sql, args, err := sq.Select("*").From("stream").ToSql()
err = data.SelectJson[data.Stream](c, err, sql, args...)
@ -56,6 +72,13 @@ func PostApiLogin(c *fiber.Ctx) error {
if err != nil { return IfErrNil(err, c) }
if login.Username == result.Username && login.Password == result.Password {
sess, err := STORE.Get(c)
if err != nil { return IfErrNil(err, c) }
sess.Set("authenticated", true)
err = sess.Save()
if err != nil { return IfErrNil(err, c) }
return c.Redirect("/")
} else {
return c.Redirect("/login/")
@ -69,7 +92,9 @@ func PostApiLink(c *fiber.Ctx) error {
link, err := ReceivePost[data.Link](c)
if err != nil { goto fail }
sql, args, err = sq.Insert("stream_blah").Columns("stream_id", "url", "description").Values(link.StreamId, link.Url, link.Description).ToSql()
sql, args, err = sq.Insert("stream_blah").
Columns("stream_id", "url", "description").
Values(link.StreamId, link.Url, link.Description).ToSql()
err = data.Insert(err, sql, args...)
return c.Redirect("/live/")
@ -83,6 +108,7 @@ func Setup(app *fiber.App) {
STORE = session.New()
app.Get("/api/stream/", GetApiStream)
app.Get("/api/logout/", Logout)
app.Get("/api/stream/:id", GetApiStreamId)
app.Get("/api/stream/:id/links", GetApiStreamIdLinks)
app.Post("/api/login", PostApiLogin)

@ -24,7 +24,7 @@
<label for="username">Username</label>
<input id="username" name="username" placeholder="Username" type="text">
<label for="password">Password</label>
<input id="password" name="password" placeholder="Password" type="text">
<input id="password" name="password" placeholder="Password" type="password">
</middle>
<bottom>
<button-group>

@ -43,7 +43,6 @@
</ul>
</block>
<block style="--value: 7; --border: 1px;" class="horizontal">
<grid style="--cols: 2">
<shape>Left Image</shape>

Loading…
Cancel
Save