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,
	})

}
Exemple #2
0
func AdminDriverDocumentDelete(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	service.DeleteDocument(c.GetPathVar("documentId"))
	c.SetFlash("alertSuccess", "Successfully deleted document")
	http.Redirect(w, r, "/admin/driver/"+c.GetPathVar("driverId")+"/document", 303)
}
Exemple #3
0
func AdminVehicleDelete(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	service.DeleteVehicle(c.GetPathVar("vehicleId"))
	c.SetFlash("alertSuccess", "Successfuly deleted vehicle")
	http.Redirect(w, r, "/admin/vehicle", 303)
	return
}
Exemple #4
0
// POST admin delete company
func AdminCompanyDelete(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	service.DeleteCompany(c.GetPathVar("id"))
	c.SetFlash("alertSuccess", "Successfully deleted  company")
	http.Redirect(w, r, "/admin/company", 303)
	return
}
Exemple #5
0
func DevCommentSave(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "developer") {
		return
	}
	comment := service.FindOneComment(c.GetPathVar("id"))
	closed, _ := strconv.ParseBool(r.FormValue("closed"))
	comment.Closed = closed
	service.SaveComment(comment)
	http.Redirect(w, r, "/dev/comment", 303)
}
Exemple #6
0
func AdminDriverDocumentSave(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	document := service.FindOneDocument(r.FormValue("id"))
	document.Data = r.FormValue("data")
	service.SaveDocument(document)
	c.SetFlash("alertSuccess", "Successfully save document")
	fmt.Fprintf(w, "/admin/driver/%s/document", c.GetPathVar("driverId"))
}
// POSt driver save document
func saveDocument(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/"+c.GetPathVar("slug"), "driver") {
		return
	}
	document := service.FindOneDocument(r.FormValue("id"))
	document.Data = r.FormValue("data")
	service.SaveDocument(document)
	c.SetFlash("alertSuccess", "Successfully save document")
	fmt.Fprintf(w, "/%s/driver", c.GetPathVar("slug"))
}
Exemple #8
0
// GET admin get new vehicle page
func AdminCompanyVehicleNew(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "admin-company-vehicle-form.tmpl", tmpl.Model{
		msgK:       msgV,
		"vehicles": service.FindAllVehicleByCompany(c.GetPathVar("companyId")),
		"company":  service.FindOneCompany(c.GetPathVar("companyId")),
	})
}
Exemple #9
0
// GET admin get all company's drivers
func AdminCompanyDriverGetAll(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "admin-company-driver.tmpl", tmpl.Model{
		msgK:      msgV,
		"drivers": service.FindAllDriverByCompany(c.GetPathVar("companyId")),
		"company": service.FindOneCompany(c.GetPathVar("companyId")),
	})
	return
}
Exemple #10
0
func AdminVehicleGetOne(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "admin-vehicle-form.tmpl", tmpl.Model{
		msgK:        msgV,
		"vehicle":   service.FindOneVehicle(c.GetPathVar("id")),
		"vehicles":  service.FindAllVehicle(),
		"companies": service.CompanyNames(),
	})
	return
}
Exemple #11
0
func AdminDriverDocumentGetAll(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "admin-driver-document.tmpl", tmpl.Model{
		msgK:        msgV,
		"driver":    service.FindOneDriver(c.GetPathVar("driverId")),
		"documents": service.FindAllDocumentByDriver(c.GetPathVar("driverId")),
		"dqfs":      service.DQFS,
	})
	return
}
Exemple #12
0
// GET admin get company
func AdminCompanyGetOne(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "admin-company.tmpl", tmpl.Model{
		msgK:           msgV,
		"company":      service.FindOneCompany(c.GetPathVar("id")),
		"driverCount":  service.GetDriverCount(c.GetPathVar("id")),
		"vehicleCount": service.GetVehicleCount(c.GetPathVar("id")),
	})
	return
}
Exemple #13
0
func companyRegister(w http.ResponseWriter, r *http.Request, c *web.Context) {
	var company Company
	if ok := GetCompBySlug(c.GetPathVar("slug"), &company); !ok || !company.Feature {
		fmt.Fprintf(w, "404 Not Page Found")
		return
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "company-register.tmpl", tmpl.Model{
		msgK:      msgV,
		"company": company,
	})
	return
}
Exemple #14
0
func AdminDriverDocumentGetOne(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	driver := service.FindOneDriver(c.GetPathVar("driverId"))
	document := service.FindOneDocument(c.GetPathVar("documentId"))
	ts.Render(w, document.Name+".tmpl", tmpl.Model{
		"driver":   driver,
		"company":  service.FindOneCompany(driver.CompanyId),
		"document": document,
		"admin":    true,
	})
}
Exemple #15
0
// GET admin get one employee
func AdminEmployeeGetOne(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "developer") {
		return
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "admin-employee-form.tmpl", tmpl.Model{
		msgK:        msgV,
		"employees": service.FindAllEmployee(),
		"employee":  service.FindOneEmployee(c.GetPathVar("id")),
		"users":     service.UserRoles(),
	})
	return
}
// GET get company register page
func companyRegister(w http.ResponseWriter, r *http.Request, c *web.Context) {
	company, ok := service.FindOneCompanyBySlug(c.GetPathVar("slug"))
	if !ok || !company.Feature {
		fmt.Fprintf(w, "404 Not Page Found")
		return
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "company-register.tmpl", tmpl.Model{
		msgK:      msgV,
		"company": company,
	})
	return
}
Exemple #17
0
// POST admin save vehilce to company
func AdminCompanyVehicleSave(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	r.ParseForm()
	vehicle := service.FindOneVehicle(r.FormValue("id"))
	util.FormToStruct(&vehicle, r.Form, "")
	if vehicle.Id == "" {
		vehicle.Id = util.UUID4()
	}
	service.SaveVehicle(vehicle)
	c.SetFlash("alertSuccess", "Successfully saved vehicle")
	http.Redirect(w, r, "/admin/company/"+c.GetPathVar("companyId")+"/vehicle", 303)
	return
}
Exemple #18
0
// GET admin get driver
func AdminDriverGetOne(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	msgK, msgV := c.GetFlash()
	driver := service.FindOneDriver(c.GetPathVar("id"))
	ts.Render(w, "admin-driver-form.tmpl", tmpl.Model{
		msgK:        msgV,
		"driver":    driver,
		"drivers":   service.FindAllDriver(),
		"companies": service.CompanyNames(),
		"user":      service.FindOneUser(driver.UserId),
	})
	return
}
Exemple #19
0
// POST admin add driver to company
func AdminCompanyDriverAdd(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	if !service.CanUpdateUser("", r.FormValue("email")) {
		c.SetFlash("alertError", "Email already registered")
		http.Redirect(w, r, "/admin/company/"+c.GetPathVar("companyId")+"/driver/new", 303)
		return
	}
	r.ParseForm()
	driver, user := service.NewDriver(r.Form)
	service.SaveDriver(driver)
	service.SaveUser(user)
	c.SetFlash("alertSuccess", "Successfully added driver")
	http.Redirect(w, r, "/admin/company/"+c.GetPathVar("companyId")+"/driver", 303)
	return
}
func postCompanyRegister(w http.ResponseWriter, r *http.Request, c *web.Context) {
	company, ok := service.FindOneCompanyBySlug(c.GetPathVar("slug"))
	if !ok || !company.Feature {
		fmt.Fprintf(w, "404 Not Page Found")
		return
	}
	if !service.CanUpdate("", r.FormValue("email")) {
		c.SetFlash("alertError", "Email already registered")
		http.Redirect(w, r, "/"+c.GetPathVar("slug")+"/register", 303)
		return
	}
	driver, user := service.NewDriver(r.Form)
	fmt.Println(driver.DOB)
	dobTS, err := time.Parse("2006-01-02", driver.DOB)
	if err != nil {
		c.SetFlash("alertError", "Error invalid date of birth")
		http.Redirect(w, r, "/"+c.GetPathVar("slug")+"/register", 303)
		return
	}
	if age := service.GetDriverAge(dobTS.UnixNano()); age < company.AgeRequirement {
		c.SetFlash("alertError", "Not old enough sucker")
		user.Active = false
		driver.Status = 0
		driver.CompanyId = ""
		service.SaveUser(user)
		service.SaveDriver(driver)
		http.Redirect(w, r, "/"+c.GetPathVar("slug")+"/register", 303)
		return
	}
	document := service.Document{
		Id:         util.UUID4(),
		DocumentId: "100",
		CompanyId:  company.Id,
		DriverId:   driver.Id,
		Name:       "dqf-100",
		Complete:   false,
	}
	service.SaveUser(user)
	service.SaveDriver(driver)
	service.SaveDocument(document)
	c.SetFlash("alertSuccess", "Successfully Registered for "+company.Name+". Please Login")
	http.Redirect(w, r, "/"+c.GetPathVar("slug")+"/login", 303)
	return
}
Exemple #21
0
func AdminDriverDocumentAdd(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	driver := service.FindOneDriver(c.GetPathVar("driverId"))
	docIds := util.SliceString(r.FormValue("docIds"), ',')
	for _, id := range docIds {
		document := service.Document{
			Id:         util.UUID4(),
			Name:       "dqf-" + id,
			DocumentId: id,
			Complete:   false,
			CompanyId:  driver.CompanyId,
			DriverId:   driver.Id,
		}
		service.SaveDocument(document)
	}
	c.SetFlash("alertSuccess", "Successfully added documents")
	http.Redirect(w, r, "/admin/driver/"+c.GetPathVar("driverId")+"/document", 303)

}
Exemple #22
0
// POST admin save driver
func AdminDriverSave(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	if !service.CanUpdateUser(r.FormValue("userId"), r.FormValue("email")) {
		c.SetFlash("alertError", "Email already registered")
		http.Redirect(w, r, "/admin/driver/"+c.GetPathVar("id"), 303)
		return
	}
	r.ParseForm()
	driver := service.FindOneDriver(r.FormValue("id"))
	util.FormToStruct(&driver, r.Form, "")
	user := service.FindOneUser(driver.UserId)
	util.FormToStruct(&user, r.Form, "")
	user.Id = driver.UserId
	service.SaveDriver(driver)
	service.SaveUser(user)
	c.SetFlash("alertSuccess", "Successfully saved driver")
	http.Redirect(w, r, "/admin/driver", 303)
	return
}
// POST post to cmopany login
func postCompanyLogin(w http.ResponseWriter, r *http.Request, c *web.Context) {
	company, ok := service.FindOneCompanyBySlug(c.GetPathVar("slug"))
	if !ok || !company.Feature {
		fmt.Fprintf(w, "404 Not Page Found")
		return
	}
	driver, ok2 := service.FindOneDriverByCompanyLogin(r.FormValue("email"), r.FormValue("password"), company.Id)
	if !ok2 {
		c.SetFlash("alertError", "Invalid email or password")
		http.Redirect(w, r, "/"+company.Slug+"/login", 303)
		return
	}
	c.Login("driver")
	c.SetSession(map[string]interface{}{
		"id":        driver.Id,
		"companyId": driver.CompanyId,
		"userId":    driver.UserId,
		"email":     driver.Email,
		"slug":      company.Slug,
	})
	c.SetFlash("alertSuccess", "Welcome "+driver.FirstName+" "+driver.LastName)
	http.Redirect(w, r, "/"+c.GetPathVar("slug")+"/driver", 303)
	return
}
Exemple #24
0
func postCompanyLogin(w http.ResponseWriter, r *http.Request, c *web.Context) {
	var company Company
	if ok := db.GetAs("company", r.FormValue("companyId"), &company); !ok || !company.Feature {
		fmt.Fprintf(w, "404 Not Page Found")
		return
	}
	var driver Driver
	if ok := GetDriverFromLogin(r.FormValue("email"), r.FormValue("password"), company.Id, &driver); !ok {
		c.SetFlash("alertError", "Invalid email or password")
		http.Redirect(w, r, "/"+company.Slug+"/login", 303)
		return
	}
	c.Login("driver")
	c.SetSession(map[string]interface{}{
		"id":        driver.Id,
		"companyId": driver.CompanyId,
		"userId":    driver.UserId,
		"email":     driver.Email,
		"slug":      company.Slug,
	})
	c.SetFlash("alertSuccess", "Welcome "+driver.FirstName+" "+driver.LastName)
	http.Redirect(w, r, "/"+c.GetPathVar("slug")+"/driver", 303)
	return
}
// 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,
	})

}
Exemple #26
0
// POST admin upload company logo
func AdminUploadCompanyLogo(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	path := "static/logo/"
	if err := os.MkdirAll(path, 0755); err != nil {
		c.SetFlash("alertError", "Error uploading file")
		http.Redirect(w, r, "/admin/company/"+c.GetPathVar("id"), 303)
		return
	}
	r.ParseMultipartForm(32 << 20) // 32 MB
	file, handler, err := r.FormFile("logo")
	if err != nil || len(handler.Header["Content-Type"]) < 1 {
		fmt.Println(err)
		c.SetFlash("alertError", "Error uploading file")
		http.Redirect(w, r, "/admin/company/"+c.GetPathVar("id"), 303)
		return
	}
	defer file.Close()
	if handler.Header["Content-Type"][0] != "image/png" && handler.Header["Content-Type"][0] != "image/jpeg" {
		fmt.Println(err)
		c.SetFlash("alertError", "Error uploading file")
		http.Redirect(w, r, "/admin/company/"+c.GetPathVar("id"), 303)
		return
	}
	company := service.FindOneCompany(c.GetPathVar("id"))
	f, err := os.OpenFile(path+company.Id+".png", os.O_WRONLY|os.O_CREATE, 0666)
	if err != nil {
		fmt.Println(err)
		c.SetFlash("alertError", "Error uploading file")
		http.Redirect(w, r, "/admin/company/"+company.Id, 303)
		return
	}
	defer f.Close()
	io.Copy(f, file)
	company.Logo = true
	service.SaveCompany(company)
	c.SetFlash("alertSuccess", "Successfully uploaded file")
	http.Redirect(w, r, "/admin/company/"+company.Id, 303)
	return
}
Exemple #27
0
func saveDocument(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "driver", "/"+c.GetPathVar("slug")) {
		return
	}
	var document Document
	if ok := db.GetAs("document", r.FormValue("id"), &document); !ok {
		c.SetFlash("alertError", "Error finding document")
		http.Redirect(w, r, "/"+c.GetPathVar("slug")+"/driver", 303)
		return
	}
	document.Data = r.FormValue("data")
	db.Set("document", r.FormValue("id"), document)
	c.SetFlash("alertSuccess", "Successfully save document")
	fmt.Fprintf(w, "/%s/driver", c.GetPathVar("slug"))
}
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
}
Exemple #29
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
}
// POST company logout
func companyLogout(w http.ResponseWriter, r *http.Request, c *web.Context) {
	c.Logout()
	http.Redirect(w, r, "/"+c.GetPathVar("slug"), 303)
}