Exemple #1
0
// TODO
func rootRedirect(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path == "/" {
		http_util.Redirect(w, r, "/vsafe/home")
	} else {
		http_util.Error(w, http.StatusNotFound)
	}
}
Exemple #2
0
func goBack(w http.ResponseWriter, r *http.Request, id int64) {
	var u *url.URL
	u, err := url.Parse(r.Form.Get("prev"))
	if err != nil {
		http_util.ReportError(w, "Error parsing prev url", err)
		return
	}
	http_util.Redirect(w, r, withId(u, id).String())
}
Exemple #3
0
func (h *authHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	user, _, err := authorizeSession(r, kSessionStore)
	if err == errNotLoggedIn {
		http_util.Redirect(
			w,
			r,
			http_util.NewUrl("/auth/login", "prev", r.URL.String()).String())
		return
	}
	if err != nil {
		http_util.ReportError(w, "Error reading database.", err)
		return
	}
	logging.SetUserName(r, user.Name)
	h.ServeMux.ServeHTTP(w, r)
}
Exemple #4
0
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {
		http_util.WriteTemplate(w, kTemplate, nil)
	} else {
		r.ParseForm()
		userName := r.Form.Get("name")
		password := r.Form.Get("password")
		var user vsafe.User
		err := h.Store.UserByName(nil, userName, &user)
		if err == vsafedb.ErrNoSuchId {
			http_util.WriteTemplate(w, kTemplate, "Login incorrect.")
			return
		}
		if err != nil {
			http_util.ReportError(w, "Database error", err)
			return
		}
		key, err := user.VerifyPassword(password)
		if err == vsafe.ErrWrongPassword {
			http_util.WriteTemplate(w, kTemplate, "Login incorrect.")
			return
		}
		if err != nil {
			http_util.ReportError(w, "Error verifying password", err)
			return
		}
		gs, err := common.NewGorillaSession(h.SessionStore, r)
		if err != nil {
			http_util.ReportError(w, "Error creating session", err)
			return
		}
		session := common.CreateUserSession(gs)
		session.SetUserId(user.Id)
		session.SetKey(key)
		session.ID = "" // For added security, force a new session ID
		session.Save(r, w)
		http_util.Redirect(w, r, r.Form.Get("prev"))
	}
}
Exemple #5
0
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	session := common.GetUserSession(r)
	session.ClearAll()
	session.Save(r, w)
	http_util.Redirect(w, r, "/vsafe/home")
}