userId := web.GetSess(r, "id").(string) var user User db.Get("user", userId, &user) tmpl.Render(w, r, "user.tmpl", web.Model{ "user": user, }) return }} var updateUser = web.Route{"POST", "/user", func(w http.ResponseWriter, r *http.Request) { r.ParseForm() userId := web.GetSess(r, "id").(string) var user User db.Get("user", userId, &user) oldPass := user.Password FormToStruct(&user, r.Form, "") if user.Password == "" { user.Password = oldPass } var users []User db.TestQuery("user", &users, adb.Eq("email", user.Email), adb.Ne("id", `"`+user.Id+`"`)) // exist := db2.Query("user", &users, repono.C("Email", repono.EQ, user.Email), repono.C("Id", repono.NE, `"`+user.Id+`"`)) if len(users) > 0 { web.SetErrorRedirect(w, r, "/user", "A user with that email already exists") return } db.Set("user", userId, user) web.SetSuccessRedirect(w, r, "/user", "Successfully updated user<br>*NOTE* Changing your email in the portal will NOT change it at zoomenvelopes.com") return }}
} else { var users []User db.TestQuery("user", &users, adb.Eq("zoomId", strconv.Itoa(user.ZoomId))) // exists := db2.Query("user", &users, repono.Eq("ZoomId", strconv.Itoa(user.ZoomId))) if len(users) > 0 { web.SetErrorRedirect(w, r, "/admin/user", "Error Zoom user is already a portal user") return } user.Id = strconv.Itoa(int(time.Now().UnixNano())) u := bpt.UUID() user.Auth = fmt.Sprintf("%x-%x-%x-%x-%x", u[0:4], u[4:6], u[6:8], u[8:10], u[10:]) user.Password = user.Email user.Active = true db.Add("user", user.Id, user) } web.SetSuccessRedirect(w, r, "/admin", "Successfully saved user") return }} var adminUpdateUserColor = web.Route{"POST", "/admin/user/color", func(w http.ResponseWriter, r *http.Request) { userId := r.FormValue("id") if userId == "" { web.SetErrorRedirect(w, r, "/admin", "Error updating user color") return } r.ParseForm() var user User db.Get("user", userId, &user) FormToStruct(&user, r.Form, "") db.Set("user", userId, user) web.SetSuccessRedirect(w, r, "/admin", "Successfully updated user colors")
} f, err := os.OpenFile(path+handler.Filename, os.O_WRONLY|os.O_CREATE, 0666) if err != nil { fmt.Printf("uploadImage >> OpenFile: %v\n", err) web.SetErrorRedirect(w, r, "/webmaster", "Error uploading file") return } defer f.Close() io.Copy(f, file) doc := map[string]interface{}{ "category": r.FormValue("category"), "description": r.FormValue("description"), "source": handler.Filename, } db.Add("image", doc) web.SetSuccessRedirect(w, r, "/webmaster", "Successfully uploaded image") return }} var saveImage = web.Route{"POST", "/webmaster/save-image/:id", func(w http.ResponseWriter, r *http.Request) { id := ParseId(r.FormValue(":id")) img := db.Get("image", id).Data img["category"] = r.FormValue("category") img["description"] = r.FormValue("description") db.Set("image", id, img) web.SetSuccessRedirect(w, r, "/webmaster", "Successfully saved image") return }} var oneImage = web.Route{"GET", "/webmaster/:id", func(w http.ResponseWriter, r *http.Request) { tmpl.Render(w, r, "webmaster.tmpl", web.Model{
"github.com/cagnosolutions/web" ) var login = web.Route{"GET", "/login", func(w http.ResponseWriter, r *http.Request) { tmpl.Render(w, r, "login.tmpl", web.Model{}) return }} var loginPost = web.Route{"POST", "/login", func(w http.ResponseWriter, r *http.Request) { email := r.FormValue("email") password := r.FormValue("password") if email == "zoomadmin" { if password == "zoomadmin" { web.Login(w, r, "ADMIN") web.SetSuccessRedirect(w, r, "/admin", "Welcome Admin") return } web.SetErrorRedirect(w, r, "/login", "Incorrect email of password") return } var user User // exists := db2.QueryOne("user", &user, repono.Eq("Email", email), repono.Eq("Password", password), repono.Eq("Active", "true")) if !db.Auth("user", email, password, &user) { web.SetErrorRedirect(w, r, "/login", "Incorrect email or password") return } sess := web.Login(w, r, "USER") sess["id"] = user.Id web.PutMultiSess(w, r, sess) web.SetSuccessRedirect(w, r, "/user", "Welcome "+user.Name)
return } web.SetErrorRedirect(w, r, fmt.Sprintf("/pay/%v?a=%s", userId, r.FormValue("a")), "Error uploading files") return }} var uploadSuccess = web.Route{"GET", "/up/success/:id", func(w http.ResponseWriter, r *http.Request) { userId := r.FormValue(":id") var user User db.Get("user", userId, &user) if user.Auth != r.FormValue("a") || userId != user.Id || !user.Active || user.PaypalEmail == "" { http.Redirect(w, r, "https://zoomenvelopes.com", 303) return } fmt.Println(web.GetCookie(r, "cart")) web.SetSuccessRedirect(w, r, fmt.Sprintf("/pay/%v?a=%s", userId, r.FormValue("a")), "Successfully uploaded files uploading files") return }} var deleteJob = web.Route{"POST", "/job/:id", func(w http.ResponseWriter, r *http.Request) { jobId, err := strconv.Atoi(r.FormValue(":id")) if err != nil { log.Printf("deleteJob() -> strconv.Atoi() -> %v\n", err) web.SetErrorRedirect(w, r, r.FormValue("redirect"), "Error deleting job") } printing := r.FormValue("printing") front, back := printing[0] == '4', printing[2] == '4' if front { err = os.Remove(PDFPath + fmt.Sprintf("front_%d.pdf", jobId)) if err != nil { log.Printf("deleteJob() -> os.Remove() -> front -> %v\n", err)
"listings": db.GetAll("listing"), }) return }} var floorPlans = web.Route{"GET", "/floor-plans", func(w http.ResponseWriter, r *http.Request) { tmpl.Render(w, r, "floor-plans.tmpl", web.Model{ "floorplans": GetFloorPlans(), }) return }} var login = web.Route{"POST", "/login", func(w http.ResponseWriter, r *http.Request) { if r.FormValue("username") == USERNAME && r.FormValue("password") == PASSWORD { web.Login(w, r, "webmaster") web.SetSuccessRedirect(w, r, "/webmaster", "You are now logged in") return } http.Redirect(w, r, "/", 303) return }} var logout = web.Route{"GET", "/logout", func(w http.ResponseWriter, r *http.Request) { web.Logout(w) web.SetSuccessRedirect(w, r, "/", "You are now logged out") return }} func ParseId(v interface{}) float64 { var id float64 var err error