Exemplo n.º 1
0
func getDocument(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "driver", "/"+c.GetPathVar("slug")) {
		return
	}
	var driver Driver
	if ok := db.GetAs("driver", c.GetFromSession("id").(string), &driver); !ok {
		c.SetFlash("alertError", "Error finding driver")
		c.Logout()
		http.Redirect(w, r, "/"+c.GetPathVar("slug"), 303)
		return
	}
	var company Company
	if ok := db.GetAs("company", c.GetFromSession("companyId").(string), &company); !ok {
		c.SetFlash("alertError", "Error finding company")
		c.Logout()
		http.Redirect(w, r, "/"+c.GetPathVar("slug"), 303)
		return
	}
	var document Document
	if ok := db.GetAs("document", c.GetPathVar("id"), &document); !ok {
		c.SetFlash("alertError", "Error finding document")
		//c.Logout()
		http.Redirect(w, r, "/"+c.GetPathVar("slug")+"/driver", 303)
		return
	}
	ts.Render(w, document.Name+".tmpl", tmpl.Model{
		"driver":   driver,
		"company":  company,
		"document": document,
	})

}
Exemplo n.º 2
0
// GET root
func root(w http.ResponseWriter, r *http.Request, c *web.Context) {
	var url string
	switch c.GetRole() {
	case "admin", "employee":
		url = "/admin/home"
	case "driver":
		url = "/" + c.GetFromSession("slug").(string) + "/driver"
	default:
		url = "/login"
	}
	http.Redirect(w, r, url, 303)
}
Exemplo n.º 3
0
// GET driver get document
func getDocument(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/"+c.GetPathVar("slug"), "driver") {
		return
	}
	if c.GetFromSession("slug") != c.GetPathVar("slug") {
		http.Redirect(w, r, "/"+c.GetFromSession("slug").(string)+"/document/"+c.GetPathVar("id"), 303)
	}
	document := service.FindOneDocument(c.GetPathVar("id"))
	driver := service.FindOneDriver(c.GetFromSession("id").(string))
	if document.DriverId != driver.Id {
		http.Redirect(w, r, "/"+c.GetFromSession("slug").(string)+"/driver/", 303)
		return
	}
	ts.Render(w, document.Name+".tmpl", tmpl.Model{
		"driver":   driver,
		"company":  service.FindOneCompany(c.GetFromSession("companyId").(string)),
		"document": document,
	})

}
Exemplo n.º 4
0
func getDriverHome(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/"+c.GetPathVar("slug"), "driver") {
		return
	}
	if c.GetFromSession("slug") != c.GetPathVar("slug") {
		http.Redirect(w, r, "/"+c.GetFromSession("slug").(string)+"/driver", 303)
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "driver-home.tmpl", tmpl.Model{
		msgK:        msgV,
		"driver":    service.FindOneDriver(c.GetFromSession("id").(string)),
		"slug":      c.GetPathVar("slug"),
		"documents": service.FindAllIncompleteDocumentByDriver(c.GetFromSession("id").(string)),
	})
	return
}
Exemplo n.º 5
0
func getDriverHome(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "driver", "/"+c.GetPathVar("slug")) {
		return
	}
	if c.GetFromSession("slug") != c.GetPathVar("slug") {
		http.Redirect(w, r, "/"+c.GetFromSession("slug").(string), 303)
	}

	var driver Driver
	if ok := db.GetAs("driver", c.GetFromSession("id").(string), &driver); !ok {
		c.SetFlash("alertError", "Error finding driver")
		c.Logout()
		http.Redirect(w, r, "/"+c.GetPathVar("slug"), 303)
		return
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "driver-home.tmpl", tmpl.Model{
		msgK:        msgV,
		"driver":    driver,
		"slug":      c.GetPathVar("slug"),
		"documents": GetDriverDocuments(driver.Id),
	})
	return
}