Example #1
0
// POST submit main login
func postLogin(w http.ResponseWriter, r *http.Request, c *web.Context) {
	employee, role, ok := service.FindOneEmployeeByLogin(r.FormValue("email"), r.FormValue("password"))
	if role == "developer" {
		c.Login(role)
		c.SetSession(map[string]interface{}{
			"emplyeeId": "developer",
			"email":     "*****@*****.**",
		})
		http.Redirect(w, r, "/admin/home", 303)
		return
	}
	if !ok {
		c.SetFlash("alertError", "Incorrect email or password")
		http.Redirect(w, r, "/login", 303)
		return
	}
	c.Login(role)
	c.SetSession(map[string]interface{}{
		"emplyeeId": employee.Id,
		"email":     employee.Email,
	})
	//if role == "employee" {
	//	http.Redirect(w, r, "/employee/home", 303)
	//	return
	//}
	//if role == "admin" {
	//	http.Redirect(w, r, "/admin/home", 303)
	//	return
	//}
	http.Redirect(w, r, "/admin/home", 303)
	return
}
Example #2
0
func getLogin(w http.ResponseWriter, r *http.Request, c *web.Context) {
	msgK, msgV := c.GetFlash()
	ts.Render(w, "login.tmpl", tmpl.Model{
		msgK: msgV,
	})
	return
}
Example #3
0
// GET admin home
func AdminHome(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-home.tmpl", tmpl.Model{
		msgK: msgV,
	})
	return
}
Example #4
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)
}
Example #5
0
func DevComments(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "developer") {
		return
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "dev-comments.tmpl", tmpl.Model{
		msgK:       msgV,
		"comments": service.FindAllComment(),
	})
}
Example #6
0
// GET get main login page
func getLogin(w http.ResponseWriter, r *http.Request, c *web.Context) {
	msgK, msgV := c.GetFlash()
	m := map[string]string{"key1": "val1", "key2": "val2"}
	ts.Render(w, "login.tmpl", tmpl.Model{
		msgK:       msgV,
		"m":        m,
		"keyToMap": "key1",
	})
	return
}
Example #7
0
// GET admin new company page
func AdminCompanyNew(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-companies-form.tmpl", tmpl.Model{
		msgK:        msgV,
		"companies": service.FindAllCompany(),
	})
	return
}
Example #8
0
// GET admin get all vehicles
func AdminVehicleGetAll(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.tmpl", tmpl.Model{
		msgK:        msgV,
		"vehicles":  service.FindAllVehicle(),
		"companies": service.CompanyNames(),
	})
	return
}
Example #9
0
func AdminVehicleSave(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, "")
	service.SaveVehicle(vehicle)
	c.SetFlash("alertSuccess", "Successfully saved vehicle")
	http.Redirect(w, r, "/admin/vehicle", 303)
	return
}
Example #10
0
func PostComment(w http.ResponseWriter, r *http.Request, c *web.Context) {
	comment := service.Comment{
		Id:     util.UUID4(),
		Com:    r.FormValue("comment"),
		Url:    r.FormValue("return"),
		Name:   r.FormValue("name"),
		Closed: false,
	}
	service.SaveComment(comment)
	c.SetFlash("alertSuccess", "Successfully save your comment")
	http.Redirect(w, r, r.FormValue("return"), 303)
}
Example #11
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)
}
Example #12
0
// POST admin edit company
func AdminCompanyEdit(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	r.ParseForm()
	company := service.FindOneCompany(r.FormValue("id"))
	util.FormToStruct(&company, r.Form, "")
	service.SaveCompany(company)
	c.SetFlash("alertSuccess", "Successfully saved company")
	http.Redirect(w, r, "/admin/company/"+r.FormValue("id"), 303)
	return
}
Example #13
0
// GET admin new employee page
func AdminEmployeeNew(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(),
		"users":     service.UserRoles(),
	})
	return
}
Example #14
0
// POST admin add company
func AdminCompanyAdd(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	r.ParseForm()
	var company service.Company
	util.FormToStruct(&company, r.Form, "")
	company.Id = util.UUID4()
	service.SaveCompany(company)
	c.SetFlash("alertSuccess", "Successfully saved company")
	http.Redirect(w, r, "/admin/company", 303)
	return
}
Example #15
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
}
Example #16
0
// 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
}
Example #17
0
func postLogin(w http.ResponseWriter, r *http.Request, c *web.Context) {
	email, password := r.FormValue("email"), r.FormValue("password")
	user, ok := GetUser(email, password)
	if !ok || (user.Role != "employee" && user.Role != "admin") {
		c.SetFlash("alertError", "Incorrect email or password")
		http.Redirect(w, r, "/login", 303)
		return
	}
	employee, ok := GetEmployee(user.Id)
	if !ok {
		c.SetFlash("alertError", "Error finding user")
		http.Redirect(w, r, "/login", 303)
		return
	}
	c.Login(user.Role)
	c.SetSession(map[string]interface{}{
		"emplyeeId": employee.Id,
		"email":     employee.Email,
	})
	if user.Role == "employee" {
		http.Redirect(w, r, "/employee/home", 303)
		return
	}
	if user.Role == "admin" {
		http.Redirect(w, r, "/admin/home", 303)
		return
	}
	return
}
Example #18
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)
}
Example #19
0
// GET admin get driver from company
func AdminCompanyDriverGetOne(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("driverId"))
	ts.Render(w, "admin-company-driver-form.tmpl", tmpl.Model{
		msgK:      msgV,
		"drivers": service.FindAllDriverByCompany(c.GetPathVar("companyId")),
		"driver":  driver,
		"company": service.FindOneCompany(c.GetPathVar("companyId")),
		"user":    service.FindOneUser(driver.UserId),
	})
	return
}
Example #20
0
// POST admin delete vehicle from company
func AdminCompanyVehicleDelete(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/company/"+c.GetPathVar("companyId")+"/vehicle", 303)
	return
}
Example #21
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
}
Example #22
0
// 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"))
}
Example #23
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")),
	})
}
Example #24
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
}
Example #25
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
}
Example #26
0
// POST admin edit driver
func AdminCompanyDriverEdit(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/company/"+c.GetPathVar("companyId")+"/driver/"+r.FormValue("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/company/"+c.GetPathVar("companyId")+"/driver", 303)
	return
}
Example #27
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
}
Example #28
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
}
Example #29
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"))
}
Example #30
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,
	})
}