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