Ejemplo n.º 1
0
func ResetPassViewHandler(w http.ResponseWriter, r *http.Request) {
	token := mux.Vars(r)["token"]

	templates := loadTemplates(
		"header.html",
		"footer.html",
		"nav.html",
		"resetpass.html",
	)

	user_id := model.ValidateResetToken(token)
	if user_id == 0 {
		fmt.Fprintf(w, "Invalid or expired token...")
		return
	}

	templates.ExecuteTemplate(w, "resetpass", TokenResetPage{
		Data: token,
	})
}
Ejemplo n.º 2
0
func ResetPassHandler(w http.ResponseWriter, r *http.Request) {
	password := r.PostFormValue("password")
	if len(password) == 0 {
		fmt.Fprintf(w, "Password can't be empty.")
		return
	}

	token := mux.Vars(r)["token"]
	user_id := model.ValidateResetToken(token)
	if user_id == 0 {
		fmt.Fprintf(w, "Invalid or expired token...")
		return
	}

	model.DeleteResetToken(token)
	model.SetUserPassword(user_id, password)

	session.Set(w, r, user_id)

	http.Redirect(w, r, "/", 302)
}