Exemple #1
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 #2
0
func (h pollHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	keyId, _ := strconv.ParseInt(r.Form.Get("kid"), 10, 64)
	user, key, err := authorizeSession(r, kPollingStore)
	if err == errNotLoggedIn {
		http_util.Error(w, 401)
		return
	}
	if err != nil {
		http_util.ReportError(w, "Error reading database.", err)
		return
	}
	logging.SetUserName(r, user.Name)
	if keyId != key.Id {
		http_util.Error(w, 401)
		return
	}
	http_util.Error(w, 200)
}