Exemple #1
0
func afterUserServiceRegister(h *hitch.Hitch) {
	h.Get("/api/user", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		sess := ab.GetSession(r)
		if sess["uid"] != "" {
			db := ab.GetDB(r)

			user, err := LoadUser(db, sess["uid"])
			ab.MaybeFail(r, http.StatusInternalServerError, err)

			ab.Render(r).
				JSON(user)
		}
	}))
}
Exemple #2
0
func getLogUserID(r *http.Request) string {
	db := ab.GetDB(r)
	userid := r.RemoteAddr
	uid := ab.GetSession(r)["uid"]
	if uid != "" {
		user, err := LoadUser(db, uid)
		if err != nil {
			log.Println(err)
		} else {
			userid = user.Mail
		}
	}

	return userid
}