Exemplo n.º 1
0
func updateAttributes(u *user.User, r *http.Request) {
	// TODO this needs to be changed.  Not a good place to put this.
	if first_name := r.PostForm.Get("user[first_name]"); first_name != "" {
		u.FirstName = first_name
	}
	if last_name := r.PostForm.Get("user[last_name]"); last_name != "" {
		u.LastName = last_name
	}
	if company := r.PostForm.Get("user[company]"); company != "" {
		u.Company = company
	}
	if email := r.PostForm.Get("user[email]"); email != "" {
		u.Email = email
	}
}
Exemplo n.º 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)
	}
}
Exemplo n.º 3
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)
	}
}