general improvements

This commit is contained in:
ston1th 2018-10-27 21:28:19 +02:00
commit ddb11f0619
25 changed files with 305 additions and 140 deletions

View file

@ -55,7 +55,7 @@ func newContext(w http.ResponseWriter, r *http.Request, s *HTTPServer) (ctx *Con
ctx.Token = *t
return
}
ctx.Redirect(core.TotpURI, 302)
ctx.Redirect(core.TotpURI, http.StatusFound)
return nil
}
@ -114,7 +114,7 @@ func (c *Context) Exec() {
}
c.Data.Token = newXsrf(c.Token.RawSig()[:keySize])
c.Data.Version = c.Srv.Version
c.Data.Version = c.Srv.Config.Version
if c.Data.BodyTitle == "" {
c.Data.BodyTitle = c.Data.Title
}
@ -162,6 +162,14 @@ func (c *Context) NotFound() {
c.Exec()
}
func (c *Context) Forbidden() {
c.Template("forbiddenHandler")
c.Data = webData{Title: "403"}
c.Status = http.StatusForbidden
c.Response.WriteHeader(http.StatusForbidden)
c.Exec()
}
func (c *Context) Template(name string) {
c.T = c.Srv.templ[name]
}
@ -221,7 +229,7 @@ func (c *Context) LoggedOn() (ok bool) {
}
func (c *Context) LogSetCookie(msg string, err error) {
log.Println(msg, err)
log.Printf("ctx: %s %s\n", msg, err)
c.SetCookie(nil)
}
@ -240,7 +248,7 @@ func (c *Context) SetCookieToken(t *jwt.Token) {
Value: c.Token.String(),
Path: "/",
MaxAge: int(jwt.DefaultExpiry.Seconds()),
Secure: c.Srv.Secure,
Secure: c.Srv.Config.SecureCookie,
HttpOnly: true,
SameSite: http.SameSiteStrictMode,
}