added Require User
Dieser Commit ist enthalten in:
Ursprung
8084ee4538
Commit
a69e026b70
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/phuslu/log"
|
"github.com/phuslu/log"
|
||||||
|
"go.sebtobie.de/httpserver/auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LogMiddleware is an middleware to log requests to phuslu/log and catches panics
|
// LogMiddleware is an middleware to log requests to phuslu/log and catches panics
|
||||||
|
@ -38,3 +39,12 @@ func LogMiddleware(c *gin.Context) {
|
||||||
}()
|
}()
|
||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RequireUser is an middleware that looks if the user is an Anonymous user and redircts it to the login if so.
|
||||||
|
func RequireUser(c *gin.Context) {
|
||||||
|
var acc = c.MustGet("account").(auth.Account)
|
||||||
|
if acc.Anonymous() {
|
||||||
|
acc.Redirect(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Laden…
In neuem Issue referenzieren