Пример #1
0
func Auth(h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		user := ctx.CurrentUser(r)

		if user == nil {
			w.WriteHeader(http.StatusUnauthorized)
			return
		}

		h.ServeHTTP(w, r)
	})
}
Пример #2
0
func DeleteAllTokensHandler(w http.ResponseWriter, r *http.Request) {
	user := ctx.CurrentUser(r)

	if _, err := ctx.M(r).DB("").C("tokens").RemoveAll(bson.M{
		"user_id": user.ID,
	}); err != nil && err != mgo.ErrNotFound {
		log.Println(err)
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	w.WriteHeader(http.StatusNoContent)
}
Пример #3
0
func GetMeHandler(w http.ResponseWriter, r *http.Request) {
	user := ctx.CurrentUser(r)
	httpres.Json(w, http.StatusOK, userResponse{User: *user})
}