func (ah *AuthHandler) Get(ctx web.Context) (bool, error) { logger.Infof("scene ID: %s", ctx.Scene().ID()) password, err := ctx.Scene().Fetch("password") if err == nil { logger.Infof("scene is logged in") return true, nil } password = ctx.Request().Header.Get("password") if password != ah.password { ctx.Redirect("authentication", "login", "") return false, nil } logger.Infof("logging scene in") ctx.Scene().Store("password", password) return true, nil }
func (th *TestHandler) Post(ctx web.Context) (bool, error) { var data TestCounterData err := ctx.ReadGOB(&data) if err != nil { ctx.WriteGOB(err) } else { ctx.WriteGOB(data) } return true, nil }
func (th *TestHandler) Put(ctx web.Context) (bool, error) { var data TestRequestData switch { case ctx.HasContentType(web.ContentTypeJSON): err := ctx.ReadJSON(&data) if err != nil { ctx.WriteJSON(TestErrorData{err.Error()}, true) } else { ctx.WriteJSON(data, true) } case ctx.HasContentType(web.ContentTypeXML): err := ctx.ReadXML(&data) if err != nil { ctx.WriteXML(TestErrorData{err.Error()}) } else { ctx.WriteXML(data) } } return true, nil }
func (th *TestHandler) Get(ctx web.Context) (bool, error) { data := TestRequestData{ctx.Domain(), ctx.Resource(), ctx.ResourceID()} switch { case ctx.AcceptsContentType(web.ContentTypeXML): logger.Infof("get XML") ctx.WriteXML(data) case ctx.AcceptsContentType(web.ContentTypeJSON): logger.Infof("get JSON") ctx.WriteJSON(data, true) default: logger.Infof("get HTML") ctx.RenderTemplate("test:context:html", data) } return true, nil }