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) }) }
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) }
func GetMeHandler(w http.ResponseWriter, r *http.Request) { user := ctx.CurrentUser(r) httpres.Json(w, http.StatusOK, userResponse{User: *user}) }