Exemple #1
0
func fragmentPage(w http.ResponseWriter, req *http.Request) {

	// Do not show main page for now
	if req.URL.Path == "/" {
		http.Redirect(w, req, "/cursos", http.StatusSeeOther)
		return
	}

	// Extract Item ID from URL
	var itemId string
	path := req.URL.Path[1:]
	k := strings.Index(path, "/")
	if k != -1 {
		// serve file from item directory
		itemId = path[:k]
		dir := content.ToDir(itemId)
		if dir.Root == "" {
			NotFound(w, req)
			return
		}
		filename := dir.File(path[k+1:])
		log.Printf("%s", req.URL.Path)
		http.ServeFile(w, req, filename)
		return
	} else {
		itemId = path
	}

	// Determine fragment ID & Title
	var fid string
	fid, notfound := getFragmentID(itemId)
	if notfound {
		log.Printf("%s (NOT FOUND)", req.URL)
		NotFound(w, req)
		return
	}
	title := getTitle(itemId)

	// Get session
	session := data.GetOrCreateSession(req)
	id := session.Id
	if session.User != nil {
		id = session.User.Login
	}
	log.Printf("%s [%s]", req.URL, id)
	session.PutCookie(w)

	SendPage(w, req, session, fid, title)
	session.Message = "" // message delivered
}
Exemple #2
0
func hLogin(w http.ResponseWriter, req *http.Request) {
	session := data.GetOrCreateSession(req)
	log.Printf("%s [%s]", req.URL, session.Id)
	session.PutCookie(w)
	switch req.Method {
	case "GET":
		url, err := url.Parse(req.Header.Get("Referer"))
		if err == nil && url.Path != "/login" {
			session.Referer = url.Path
		}
		SendPage(w, req, session, "login", "Login")
		session.Message = ""
	case "POST":
		hLoginProcessForm(w, req, session)
	default:
		http.Error(w, "Wrong method", http.StatusBadRequest)
	}
}
Exemple #3
0
func hAbout(w http.ResponseWriter, req *http.Request) {
	session := data.GetOrCreateSession(req)
	log.Printf("%s [%s]", req.URL, session.Id)
	SendPage(w, req, session, "about", "Acerca de")
}