Nuestro burocrata preferido: Sam Lowry
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.5 KiB

package server
import (
type responseT struct {
User string
IsAdmin bool
Role ldap.Role
Section string
Data interface{}
w http.ResponseWriter
r *http.Request
tmpl *template.Template
func initTemplate() *template.Template {
return template.Must(template.ParseFiles(
func (s *server) newResponse(template string, w http.ResponseWriter, r *http.Request) responseT {
session := s.sess.get(w, r)
user := ""
role := ldap.Undefined
admin := false
if session != nil {
user = session.user
admin = s.isAdmin(user)
role = s.ldap.GetUserRole(user)
return responseT{
User: user,
IsAdmin: admin,
Role: role,
Section: template,
Data: nil,
w: w,
r: r,
tmpl: s.tmpl,
func (r *responseT) execute(data interface{}) {
r.Data = data
if err := r.tmpl.ExecuteTemplate(r.w, r.Section+".html", r); err != nil {
log.Println("An error ocurred loading template '", r.Section, "': ", err)
r.tmpl.ExecuteTemplate(r.w, "500.html", r)
func (s *server) isAdmin(user string) bool {
return s.ldap.InGroup(user, "adm")