Пример #1
0
func UserCurrentHandler(w http.ResponseWriter, r *http.Request) {
	noCache(w)

	u := bugzilla.CurrentUser()

	if u == nil {
		http.Error(w, "Not logged in", http.StatusNoContent)
		return
	}

	JsonResponse(w, u)
}
Пример #2
0
func UserLogoutHandler(w http.ResponseWriter, r *http.Request) {
	noCache(w)

	if bugzilla.CurrentUser() == nil {
		return
	}

	client, err := Bz()

	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	if err := client.Users().Logout(); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	bz = nil
}
Пример #3
0
func BugCommentHandler(w http.ResponseWriter, r *http.Request) {
	noCache(w)

	if bugzilla.CurrentUser() == nil {
		http.Error(w, "Not logged in", http.StatusBadRequest)
		return
	}

	comment := r.FormValue("comment")

	if len(comment) == 0 {
		http.Error(w, "No comment specified", http.StatusBadRequest)
		return
	}

	vars := mux.Vars(r)

	idl, err := strconv.ParseInt(vars["id"], 10, 32)

	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	id := int(idl)

	client, err := Bz()

	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	if _, err := client.Bugs().AddComment(client, id, comment); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	go SaveCookies()
}