Documentation ¶
Index ¶
Constants ¶
const ( // ErrInsuffPerm is returned when a user tries to access a route for which they have insufficient permissions. // Typically a 403 status code should be returned with it. ErrInsuffPerm mwError = "middleware: you do not have sufficient permissions to view this page, if it exists" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RequireAdmin ¶
type RequireAdmin struct {
models.UserService
}
RequireAdmin is used to limit access to certain parts of the app to admins. It is a full replacement for the RequireUser middleware; use one, not both. Likewise, it assumes the User middleware has already ran.
func (*RequireAdmin) Apply ¶
func (mw *RequireAdmin) Apply(next http.Handler) http.HandlerFunc
Apply will return an http.HandlerFunc that will check to see if a user is signed-in and is an admin and then call next(w, r) if they are. If the user is not signed-in, then they will be redirected to the log in page (like the RequireUser middleware does). If the user is not an admin, an error will be shown. Uses ApplyFn under the hood.
func (*RequireAdmin) ApplyFn ¶
func (mw *RequireAdmin) ApplyFn(next http.HandlerFunc) http.HandlerFunc
ApplyFn will return an http.HandlerFunc that will check to see if a user is signed-in and is an admin and then call next(w, r) if they are. If the user is not signed-in, then they will be redirected to the log in page (like the RequireUser middleware does). If the user is not an admin, an error will be shown.
type RequireSuperAdmin ¶
type RequireSuperAdmin struct {
models.UserService
}
RequireSuperAdmin is used to limit access to certain parts of the app to superadmins. It is a full replacement for the other role middlewares.
func (*RequireSuperAdmin) Apply ¶
func (mw *RequireSuperAdmin) Apply(next http.Handler) http.HandlerFunc
Apply will return an http.HandlerFunc that will check to see if a user is signed-in and is a superadmin- see RequireAdmin.Apply
func (*RequireSuperAdmin) ApplyFn ¶
func (mw *RequireSuperAdmin) ApplyFn(next http.HandlerFunc) http.HandlerFunc
See RequireAdmin.ApplyFn
type RequireUser ¶
type RequireUser struct {
models.UserService
}
RequireUser is used to limit access to certain parts of the app to logged-in users. If a user is not logged in, they will be redirected to the login page. This middleware assumes that the User middleware has already ran, and will otherwise always redirect users.
func (*RequireUser) Apply ¶
func (mw *RequireUser) Apply(next http.Handler) http.HandlerFunc
Apply will return an http.HandlerFunc that will check to see if a user is logged in and then either call next(w, r) if they are, or redirect them to the login page if they are not. Uses ApplyFn under the hood.
func (*RequireUser) ApplyFn ¶
func (mw *RequireUser) ApplyFn(next http.HandlerFunc) http.HandlerFunc
ApplyFn will return an http.HandlerFunc that will check to see if a user is logged in and then either call next(w, r) if they are, or redirect them to the login page if they are not.
type User ¶
type User struct {
models.UserService
}
User middleware will lookup the current user via their remember_token cookie using the UserService. If the user is found, they will be set on the request context. Regardless, the next handler is always called.
func (*User) Apply ¶
func (mw *User) Apply(next http.Handler) http.HandlerFunc
Apply adds the currently logged-in user (if any) to the context and then calls next, using ApplyFn under the hood.
func (*User) ApplyFn ¶
func (mw *User) ApplyFn(next http.HandlerFunc) http.HandlerFunc
ApplyFn adds the currently logged-in user (if any) to the context and then calls next.