Can now set an auth cookie to check for auth, but I should see what it takes to make a middleware.
This commit is contained in:
parent
05788e5fbb
commit
b0c4144987
3 changed files with 29 additions and 4 deletions
|
|
@ -13,9 +13,25 @@ import (
|
||||||
|
|
||||||
var STORE *session.Store
|
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 {
|
func GetApiStream(c *fiber.Ctx) error {
|
||||||
sess, err := STORE.Get(c)
|
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()
|
sql, args, err := sq.Select("*").From("stream").ToSql()
|
||||||
err = data.SelectJson[data.Stream](c, err, sql, args...)
|
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 err != nil { return IfErrNil(err, c) }
|
||||||
|
|
||||||
if login.Username == result.Username && login.Password == result.Password {
|
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("/")
|
return c.Redirect("/")
|
||||||
} else {
|
} else {
|
||||||
return c.Redirect("/login/")
|
return c.Redirect("/login/")
|
||||||
|
|
@ -69,7 +92,9 @@ func PostApiLink(c *fiber.Ctx) error {
|
||||||
link, err := ReceivePost[data.Link](c)
|
link, err := ReceivePost[data.Link](c)
|
||||||
if err != nil { goto fail }
|
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...)
|
err = data.Insert(err, sql, args...)
|
||||||
return c.Redirect("/live/")
|
return c.Redirect("/live/")
|
||||||
|
|
@ -83,6 +108,7 @@ func Setup(app *fiber.App) {
|
||||||
STORE = session.New()
|
STORE = session.New()
|
||||||
|
|
||||||
app.Get("/api/stream/", GetApiStream)
|
app.Get("/api/stream/", GetApiStream)
|
||||||
|
app.Get("/api/logout/", Logout)
|
||||||
app.Get("/api/stream/:id", GetApiStreamId)
|
app.Get("/api/stream/:id", GetApiStreamId)
|
||||||
app.Get("/api/stream/:id/links", GetApiStreamIdLinks)
|
app.Get("/api/stream/:id/links", GetApiStreamIdLinks)
|
||||||
app.Post("/api/login", PostApiLogin)
|
app.Post("/api/login", PostApiLogin)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
<label for="username">Username</label>
|
<label for="username">Username</label>
|
||||||
<input id="username" name="username" placeholder="Username" type="text">
|
<input id="username" name="username" placeholder="Username" type="text">
|
||||||
<label for="password">Password</label>
|
<label for="password">Password</label>
|
||||||
<input id="password" name="password" placeholder="Password" type="text">
|
<input id="password" name="password" placeholder="Password" type="password">
|
||||||
</middle>
|
</middle>
|
||||||
<bottom>
|
<bottom>
|
||||||
<button-group>
|
<button-group>
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@
|
||||||
</ul>
|
</ul>
|
||||||
</block>
|
</block>
|
||||||
|
|
||||||
|
|
||||||
<block style="--value: 7; --border: 1px;" class="horizontal">
|
<block style="--value: 7; --border: 1px;" class="horizontal">
|
||||||
<grid style="--cols: 2">
|
<grid style="--cols: 2">
|
||||||
<shape>Left Image</shape>
|
<shape>Left Image</shape>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue