Documentation ¶
Index ¶
- type Env
- func (env *Env) AdminOnly(next http.Handler) http.Handler
- func (env *Env) CreateAccount(w http.ResponseWriter, r *http.Request)
- func (env *Env) CreatePost(w http.ResponseWriter, r *http.Request)
- func (env *Env) Dashboard(w http.ResponseWriter, r *http.Request)
- func (env *Env) DeletePost(w http.ResponseWriter, r *http.Request)
- func (env *Env) GetPost(w http.ResponseWriter, r *http.Request)
- func (env *Env) GetPosts(w http.ResponseWriter, r *http.Request)
- func (env *Env) GetPublishedPosts(w http.ResponseWriter, r *http.Request)
- func (env *Env) GetUnpublishedPosts(w http.ResponseWriter, r *http.Request)
- func (env *Env) Login(w http.ResponseWriter, r *http.Request)
- func (env *Env) Logout(w http.ResponseWriter, r *http.Request)
- func (env *Env) UpdatePost(w http.ResponseWriter, r *http.Request)
- func (env *Env) UserCtx(next http.Handler) http.Handler
- type UserCustomClaim
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Env ¶
type Env struct { DB models.Datastore S *securecookie.SecureCookie Hmac []byte Salt string Sugar *zap.SugaredLogger }
Env carries database access to controllers
func (*Env) AdminOnly ¶
AdminOnly blocks all requests unless from a user with a role of ADMIN assumes user is stored in context (run UserCtx before running this middleware)
func (*Env) CreateAccount ¶
func (env *Env) CreateAccount(w http.ResponseWriter, r *http.Request)
CreateAccount takes user, email, gpg, password, password2 from a form cleans any data that might show up on a page and returns 500 if the two passwords do not match 409 if there is an error in hashing and 200 if the user is added to the database successfully
func (*Env) CreatePost ¶
func (env *Env) CreatePost(w http.ResponseWriter, r *http.Request)
CreatePost takes form data and inserts a post into the database expects the user and role to be in the request context.
func (*Env) Dashboard ¶
func (env *Env) Dashboard(w http.ResponseWriter, r *http.Request)
Dashboard is a function that wraps calls commonly used on the homepage
func (*Env) DeletePost ¶
func (env *Env) DeletePost(w http.ResponseWriter, r *http.Request)
DeletePost removes a post from the database if the user is the owner
func (*Env) GetPost ¶
func (env *Env) GetPost(w http.ResponseWriter, r *http.Request)
GetPost if ID matches a post return a json post. If the post is unpublished check if user is an admin otherwise return 404
func (*Env) GetPosts ¶
func (env *Env) GetPosts(w http.ResponseWriter, r *http.Request)
GetPosts is an admin only function that returns posts Query string s and e define which rows to query s defaults to 0 and e defaults to 10
func (*Env) GetPublishedPosts ¶
func (env *Env) GetPublishedPosts(w http.ResponseWriter, r *http.Request)
GetPublishedPosts returns all published / public posts
func (*Env) GetUnpublishedPosts ¶
func (env *Env) GetUnpublishedPosts(w http.ResponseWriter, r *http.Request)
GetUnpublishedPosts returns all published / public posts
func (*Env) Login ¶
func (env *Env) Login(w http.ResponseWriter, r *http.Request)
Login takes a user and password from a login form and checks it against the hashed password in the database sets jwt if accepted
func (*Env) Logout ¶
func (env *Env) Logout(w http.ResponseWriter, r *http.Request)
Logout will delete the authentication cookie
func (*Env) UpdatePost ¶
func (env *Env) UpdatePost(w http.ResponseWriter, r *http.Request)
UpdatePost takes form data and a post ID to update stored information
type UserCustomClaim ¶
type UserCustomClaim struct { UUID uuid.UUID `json:"uuid"` jwt.StandardClaims }
UserCustomClaim is the custom claim for user authentication contains a uuid.UUID and jwt.StandardClaims