コード例 #1
0
ファイル: admin-controllers.go プロジェクト: gregpechiro/cns
// POST edit employee
func AdminEmployeeEdit(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "developer") {
		return
	}
	if !service.CanUpdateUser(r.FormValue("userId"), r.FormValue("email")) {
		c.SetFlash("alertError", "Email already registered")
		http.Redirect(w, r, "/admin/employee/"+r.FormValue("id"), 303)
		return
	}
	r.ParseForm()
	employee := service.FindOneEmployee(r.FormValue("id"))
	util.FormToStruct(&employee, r.Form, "")
	user := service.FindOneUser(employee.UserId)
	util.FormToStruct(&user, r.Form, "")
	user.Id = employee.UserId
	service.SaveEmployee(employee)
	service.SaveUser(user)
	c.SetFlash("alertSuccess", "Successfully saved employee")
	http.Redirect(w, r, "/admin/employee", 303)
	return
}
コード例 #2
0
ファイル: admin-controllers.go プロジェクト: gregpechiro/cns
// 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
}
コード例 #3
0
ファイル: admin-controllers.go プロジェクト: gregpechiro/cns
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
}
コード例 #4
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
}
コード例 #5
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
}
コード例 #6
0
ファイル: driver.go プロジェクト: gregpechiro/cns
func NewDriver(dat url.Values) (Driver, User) {
	user := User{
		Id:       util.UUID4(),
		Email:    dat.Get("email"),
		Password: dat.Get("email"),
		Role:     "driver",
		Active:   true,
	}
	var driver Driver
	util.FormToStruct(&driver, dat, "")
	driver.Id = util.UUID4()
	driver.UserId = user.Id
	return driver, user
}
コード例 #7
0
ファイル: admin-controllers.go プロジェクト: gregpechiro/cns
// 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
}
コード例 #8
0
ファイル: employee.go プロジェクト: gregpechiro/go-cns
func NewEmployee(dat url.Values) (Employee, User) {
	user := User{
		Id:       util.UUID4(),
		Email:    dat.Get("email"),
		Password: dat.Get("email"),
		Role:     dat.Get("role"),
	}
	a, _ := strconv.ParseBool(dat.Get("active"))
	user.Active = a
	var employee Employee
	util.FormToStruct(&employee, dat, "")
	employee.Id = util.UUID4()
	employee.UserId = user.Id
	return employee, user
}