Пример #1
0
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,
		})
	}
}
Пример #2
0
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)
	}
}
Пример #3
0
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)
	}
}
Пример #4
0
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)
	}
}
Пример #5
0
func LogoutController(w http.ResponseWriter, r *http.Request) {
	helpers.SignOut(r)
	flash.Success(r, "Successfully signed out.")
	http.Redirect(w, r, "/", http.StatusFound)
}