Migrated to the new go-web-dev-kit setup.
This commit is contained in:
parent
8d70b57299
commit
71ee505717
20 changed files with 193 additions and 810 deletions
|
|
@ -9,20 +9,13 @@ import (
|
|||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/gofiber/fiber/v2/middleware/session"
|
||||
|
||||
"zedshaw.games/webapp/data"
|
||||
. "zedshaw.games/webapp/common"
|
||||
"MY/webapp/data"
|
||||
. "MY/webapp/common"
|
||||
)
|
||||
|
||||
var STORE *session.Store
|
||||
|
||||
|
||||
func GetApiLogout(c *fiber.Ctx) error {
|
||||
err := LogoutUser(c)
|
||||
if err != nil { return IfErrNil(err, c) }
|
||||
|
||||
return c.Redirect("/")
|
||||
}
|
||||
|
||||
func GetApiStream(c *fiber.Ctx) error {
|
||||
sql, args, err := sq.Select("*").From("stream").ToSql()
|
||||
err = data.SelectJson[data.Stream](c, err, sql, args...)
|
||||
|
|
@ -48,48 +41,6 @@ func GetApiStreamIdLinks(c *fiber.Ctx) error {
|
|||
return IfErrNil(err, c)
|
||||
}
|
||||
|
||||
func PostApiRegister(c *fiber.Ctx) error {
|
||||
user, err := ReceivePost[data.User](c)
|
||||
if err != nil { return IfErrNil(err, c) }
|
||||
|
||||
err = SetUserPassword(user)
|
||||
if err != nil { return IfErrNil(err, c) }
|
||||
|
||||
sql, args, err := sq.Insert("user").
|
||||
Columns("username", "email", "password").
|
||||
Values(user.Username, user.Email, user.Password).ToSql()
|
||||
|
||||
err = data.Exec(err, sql, args...)
|
||||
if err != nil { return IfErrNil(err, c) }
|
||||
|
||||
return c.Redirect("/login/")
|
||||
}
|
||||
|
||||
func PostApiLogin(c *fiber.Ctx) error {
|
||||
var user data.User
|
||||
|
||||
login, err := ReceivePost[data.Login](c)
|
||||
if(err != nil) { return IfErrNil(err, c) }
|
||||
|
||||
pass_good, err := LoginUser(&user, login)
|
||||
if err != nil { return IfErrNil(err, c) }
|
||||
|
||||
if pass_good {
|
||||
sess, err := STORE.Get(c)
|
||||
if err != nil { return IfErrNil(err, c) }
|
||||
|
||||
// BUG: THIS IS A BIG NO NO, just for getting going
|
||||
sess.Set("authenticated", true)
|
||||
sess.Set("admin", IsAdmin(&user))
|
||||
err = sess.Save()
|
||||
if err != nil { return IfErrNil(err, c) }
|
||||
|
||||
return c.Redirect("/")
|
||||
} else {
|
||||
return c.Redirect("/login/")
|
||||
}
|
||||
}
|
||||
|
||||
func PostApiLink(c *fiber.Ctx) error {
|
||||
var sql string
|
||||
var args []interface{}
|
||||
|
|
@ -104,7 +55,7 @@ func PostApiLink(c *fiber.Ctx) error {
|
|||
Columns("stream_id", "url", "description").
|
||||
Values(link.StreamId, link.Url, link.Description).ToSql()
|
||||
|
||||
err = data.Exec(err, sql, args...)
|
||||
_, err = data.Exec(err, sql, args...)
|
||||
if(err != nil) { return IfErrNil(err, c) }
|
||||
|
||||
return c.Redirect("/live/")
|
||||
|
|
@ -141,12 +92,14 @@ func Setup(app *fiber.App) {
|
|||
app.Get("/api/game/:id", GetApiGameId)
|
||||
|
||||
app.Get("/api/stream", GetApiStream)
|
||||
app.Get("/api/logout", GetApiLogout)
|
||||
app.Get("/api/stream/:id", GetApiStreamId)
|
||||
app.Get("/api/stream/:id/links", GetApiStreamIdLinks)
|
||||
app.Post("/api/login", PostApiLogin)
|
||||
app.Post("/api/link", PostApiLink)
|
||||
|
||||
// api/auth.go
|
||||
app.Get("/api/logout", GetApiLogout)
|
||||
app.Post("/api/register", PostApiRegister)
|
||||
app.Post("/api/login", PostApiLogin)
|
||||
}
|
||||
|
||||
func Shutdown() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue