first commit
This commit is contained in:
commit
7cec3bb263
27 changed files with 597 additions and 0 deletions
34
middlewares/authentication.go
Normal file
34
middlewares/authentication.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package middlewares
|
||||
|
||||
import (
|
||||
"git.readonly.ch/bouzoure/popvaud-people/helpers"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func AuthMiddleware(c *fiber.Ctx) error {
|
||||
if c.Path() == "/login" {
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
sess, err := helpers.GetSessionStore(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
userid := sess.Get("userid")
|
||||
|
||||
if userid == nil {
|
||||
return c.Redirect("/login")
|
||||
}
|
||||
|
||||
active, err := helpers.UserExistsAndIsActive(userid.(int))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !active {
|
||||
return c.Redirect("/login")
|
||||
}
|
||||
|
||||
return c.Next()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue