Added admin bool field and middleware.
This commit is contained in:
parent
dae9ea3ae1
commit
2c9cf2a21a
13 changed files with 183 additions and 5 deletions
|
|
@ -103,3 +103,19 @@ func RequireNoAuthentication(next echo.HandlerFunc) echo.HandlerFunc {
|
|||
return next(c)
|
||||
}
|
||||
}
|
||||
|
||||
// RequireAdmin requires that the user be an admin in order to proceed.
|
||||
func RequireAdmin(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
if u := c.Get(context.AuthenticatedUserKey); u != nil {
|
||||
if user, ok := u.(*ent.User); ok {
|
||||
if user.Admin {
|
||||
// TODO tests
|
||||
return next(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return echo.NewHTTPError(http.StatusUnauthorized)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue