Esempio n. 1
0
func (s TemplatingShortcuts) Render500(res http.ResponseWriter, req *http.Request) {
	res.WriteHeader(http.StatusInternalServerError)

	err := s.RenderTemplate(res, templating.NewBaseContext("500.html"))

	if err != nil {
		log.Println("Error when rendering 500 template:", err)
	}
}
Esempio n. 2
0
func (s TemplatingShortcuts) Render401(res http.ResponseWriter) {
	res.WriteHeader(http.StatusUnauthorized)

	err := s.RenderTemplate(res, templating.NewBaseContext("401.html"))

	if err != nil {
		log.Println("Error when rendering 401 template:", err)
	}
}
Esempio n. 3
0
func (s TemplatingShortcuts) Render404(res http.ResponseWriter, req *http.Request) {
	res.WriteHeader(http.StatusNotFound)

	err := s.RenderTemplate(res, templating.NewBaseContext("404.html"))

	if err != nil {
		log.Println("Error when rendering 404 template:", err)
	}
}
Esempio n. 4
0
func (s TemplatingShortcuts) FormContextOr500(res http.ResponseWriter, req *http.Request, templateName string) *templating.FormContext {
	baseCtx := templating.NewBaseContext(templateName)
	formCtx, err := templating.NewFormContext(res, req, baseCtx)

	if err != nil {
		s.Render500(res, req)

		return nil
	}

	return formCtx
}
Esempio n. 5
0
func (h *HomeHandler) LoadHomePage(res http.ResponseWriter, req *http.Request) {
	ctx := HomeContext{templating.NewBaseContext("index.html"), nil}
	users, err := h.Users.All()

	if err != nil {
		log.Println("Error loading users from repository:", err)
		ctx.AddError(errors.New("Unable to load users"))
	} else {
		ctx.Users = users
	}

	h.RenderPage(res, ctx)
}
Esempio n. 6
0
func (h *LoginHandler) LoadUserProfilePage(res http.ResponseWriter, req *http.Request) {
	id, _ := context.Params(req).GetInt(":id")

	// A user can only see his/her own profile
	if context.CurrentUser(req).Id != id {
		h.Render401(res)

		return
	}

	entity := h.FindEntityOr404(res, req, h.Users, id)

	if user, ok := entity.(*entities.User); ok {
		ctx := ProfileContext{templating.NewBaseContext("profile.html"), user}
		h.RenderPage(res, &ctx)
	}
}
Esempio n. 7
0
func newSignupContext() *templating.BaseContext {
	return templating.NewBaseContext("signup.html")
}