Exemplo n.º 1
0
// PageHandler is the standard page loader
func PageHandler(w http.ResponseWriter, r *http.Request) {
	title := r.URL.Path[len("/"):]
	if len(title) == 0 {
		title = "home"
	}
	// Check if they are attempting to view the backend... must be logged in to do that
	// TODO: there should be a flag that says "this page requires login"
	if strings.HasPrefix(title, "backend/") && !auth.IsConnected(r) {
		login := LoadPage(w, PageLocation, "login")
		RenderTemplate(w, r, login)
		return
	}
	var p *Page
	if strings.HasSuffix(title, "backend") || strings.HasSuffix(title, "backend/") {
		title = "backend/users"
	}

	if title == "base" {
		p = OnError(w, 404)
	} else {
		p = LoadPage(w, PageLocation, title)
	}
	//check if page needs to be fed any data before being rendered (pretty much all of the backend and some public pages)
	if f, ok := feeds[title]; ok && auth.IsConnected(r) {
		p.Info = f(w, r)
	}
	RenderTemplate(w, r, p)
}
Exemplo n.º 2
0
// AuthHandler is used to verify that a client is logged in.
// If they are not, they are instead redirected to the login page.
// TODO: after the login page, it should direct the user to the page they
// requested originally
func AuthHandler(w http.ResponseWriter, r *http.Request) {
	if auth.IsConnected(r) {
		PageHandler(w, r)
		return
	}
	RenderTemplate(w, r, LoadPage(w, PageLocation, "login"))
}
Exemplo n.º 3
0
// DevHandler is used to refresh a specific page within the page cache
// A client must be authenticated before they are able to use this. If they are
// not authenticated they will simply be redirected to the cached version of the
// page
func DevHandler(w http.ResponseWriter, r *http.Request) {
	title := r.URL.Path[len("/dev/"):]
	if auth.IsConnected(r) {
		delete(pages, PageLocation+title+".html")
		PageHandler(w, r)
	} else {
		title = "/" + title
		http.Redirect(w, r, title, http.StatusFound)
	}
}