func UserEditController(w http.ResponseWriter, r *http.Request) { id := getId(r) u := user.Find(id) // TODO Render 404 if user not found. templates.Render(w, r, "admin/user/edit", map[string]interface{}{ "User": u, }) }
func UserUpdateController(w http.ResponseWriter, r *http.Request) { r.ParseForm() id := getId(r) u := user.Find(id) updateAttributes(u, r) if u.Save() { flash.Success(r, "Account successfully updated!") http.Redirect(w, r, "/admin/users", http.StatusFound) } else { data := make(map[string]interface{}) data["User"] = u // Render form to fix templates.Render(w, r, "admin/user/edit", map[string]interface{}{ "User": u, }) } }
func UserIndexController(w http.ResponseWriter, r *http.Request) { r.ParseForm() c := r.Form.Get("c") o := r.Form.Get("o") // Next order value var n string = "ASC" if o != "DESC" { // Everything else but DESC evals to ASC so we only need to set DESC // if it isn't DESC already. n = "DESC" } templates.Render(w, r, "admin/user/index", map[string]interface{}{ "c": c, "o": o, "n": n, "Users": user.AllSorted(c, o), }) }
func LoginController(w http.ResponseWriter, r *http.Request) { r.ParseForm() u := user.User{ Email: r.PostForm.Get("user[email]"), Password: r.PostForm.Get("user[password]"), } if u.Login() { helpers.SignIn(r, u) flash.Success(r, "Successfully logged in!") http.Redirect(w, r, "/", http.StatusFound) } else { // Erase password for good practice. u.Password = "" data := make(map[string]interface{}) data["User"] = u // Render form to fix templates.Render(w, r, "user/sign_in", data) } }
func UpdateController(w http.ResponseWriter, r *http.Request) { r.ParseForm() u := helpers.CurrentUser(r) updateAttributes(u, r) old_password := r.PostForm.Get("user[password]") new_password := r.PostForm.Get("user[new_password]") new_password_conf := r.PostForm.Get("user[new_password_confirmation]") u.UpdatePassword(old_password, new_password, new_password_conf) if u.Save() { flash.Success(r, "Account successfully updated!") http.Redirect(w, r, "/app", http.StatusFound) } else { // Erase password for good practice. u.Password = "" data := make(map[string]interface{}) data["User"] = u // Render form to fix templates.Render(w, r, "user/edit", data) } }
func CreateController(w http.ResponseWriter, r *http.Request) { r.ParseForm() u := user.User{ FirstName: r.PostForm.Get("user[first_name]"), LastName: r.PostForm.Get("user[last_name]"), Company: r.PostForm.Get("user[company]"), Email: r.PostForm.Get("user[email]"), Password: r.PostForm.Get("user[password]"), Role: "viewer", } if u.Save() { helpers.SignIn(r, u) flash.Success(r, "Account successfully created!") http.Redirect(w, r, "/app", http.StatusFound) } else { // Erase password for good practice. u.Password = "" data := make(map[string]interface{}) data["User"] = u // Render form to fix templates.Render(w, r, "user/new", data) } }
func MobileController(w http.ResponseWriter, r *http.Request) { templates.Render(w, r, "mobile/index", nil) }
func HomeController(w http.ResponseWriter, r *http.Request) { templates.Render(w, r, "marketing/index", nil) }
func EditController(w http.ResponseWriter, r *http.Request) { data := make(map[string]interface{}) data["User"] = helpers.CurrentUser(r) templates.Render(w, r, "user/edit", data) }