feat(sessions): use session

This commit is contained in:
rick 2021-09-11 00:57:17 +02:00
parent 7dbd82c450
commit c1e0c6defa
Signed by: Rick
GPG key ID: 2B593F087240EE99

View file

@ -166,9 +166,27 @@ func getNew(c *fiber.Ctx) error {
func mytoken(c *fiber.Ctx) error { func mytoken(c *fiber.Ctx) error {
err := c.BodyParser(&SpotifyAPI) err := c.BodyParser(&SpotifyAPI)
if err != nil {
Errors = err.Error()
} else {
sess, err := Session.Get(c)
if err != nil { if err != nil {
Errors = err.Error() Errors = err.Error()
} }
sess.Set("token", SpotifyAPI.Token)
sess.Set("expire", SpotifyAPI.ExpiresIn)
sess.Set("tokentype", SpotifyAPI.TokenType)
sess.Set("creation", time.Now().GoString())
err = sess.Save()
if err != nil {
fmt.Printf("%v+", err)
}
}
//sess.Set("creation", time.Now())
return c.SendStatus(201) return c.SendStatus(201)
} }
@ -181,14 +199,30 @@ func spotifyCallback(c *fiber.Ctx) error {
} }
func index(c *fiber.Ctx) error { func index(c *fiber.Ctx) error {
sess, err := Session.Get(c)
if err != nil {
Errors = err.Error()
}
if Errors == "" { if Errors == "" {
return c.Render("index", fiber.Map{"connected": !SpotifyAPI.CheckEmpty(), tmp := false
if sess.Get("token") != nil {
tmp = true
}
//return c.Render("index", fiber.Map{"connected": !SpotifyAPI.CheckEmpty(),
return c.Render("index", fiber.Map{"connected": tmp,
"url": SpotifyURL}) "url": SpotifyURL})
} else { } else {
tmp := Errors tmp := false
if sess.Get("token") != nil {
tmp = true
}
e := Errors
Errors = "" Errors = ""
return c.Render("index", fiber.Map{"connected": !SpotifyAPI.CheckEmpty(), return c.Render("index", fiber.Map{"connected": tmp,
"error": tmp, "error": e,
"url": SpotifyURL}) "url": SpotifyURL})
} }
} }
@ -203,7 +237,6 @@ func main() {
app.Post("/feudecamp", getNew) app.Post("/feudecamp", getNew)
app.Post("/back", formHandler) app.Post("/back", formHandler)
app.Get("/callback", spotifyCallback) app.Get("/callback", spotifyCallback)
//app.Post("/mytoken", mytoken)
app.Listen(":8080") app.Listen(":8080")
} }