          (resp-ok))))
 
 (defmethod dispatch :user-delete [_]
-  (fn [{:keys [headers route-params]}]
-    (let [token (get headers "authorization")
-          username (token/user token)
-          user (api/user-by-username username)]
-      (if (= (:_id user)
-             (:id route-params))
-        (resp-error 400 "Operation not allowed")
-        (do (api/delete-user (:id route-params))
-            (resp-ok))))))
+  (fn [{:keys [route-params logged-user]}]
+    (if (= (:_id (api/user-by-username logged-user))
+           (:id route-params))
+      (resp-error 400 "Operation not allowed")
+      (do (api/delete-user (:id route-params))
+          (resp-ok)))))
 
 (defmethod dispatch :user-create [_]
   (fn [{:keys [params]}]
-    (let [payload (keywordize-keys params)
+    (let [payload (assoc (keywordize-keys params) :type "user")
           response (api/create-user payload)]
       (if (some? response)
         (resp-created (select-keys response [:id]))

      (api/update-user (:id route-params) payload)
      (resp-ok))))

;; Registry handler

(defmethod dispatch :registries [_]
  (fn [_]
    (->> (api/registries)
         (resp-ok))))

(defmethod dispatch :registry [_]
  (fn [{:keys [route-params]}]
    (->> (api/registry (:id route-params))
         (resp-ok))))

(defmethod dispatch :registries-list [_]
  (fn [_]
    (->> (api/registries-list)
         (resp-ok))))

(defmethod dispatch :registry-delete [_]
  (fn [{:keys [route-params]}]
    (api/delete-registry (:id route-params))
    (resp-ok)))

(defmethod dispatch :registry-create [_]
  (fn [{:keys [params]}]
    (let [payload (keywordize-keys params)]
      (if (api/registry-valid? payload)
        (let [response (api/create-registry payload)]
          (if (some? response)

;; Password handler

(defmethod dispatch :password [_]
  (fn [{:keys [params logged-user]}]
    (let [payload (keywordize-keys params)]
      (-> (api/user-by-username logged-user)
          (api/change-password (:password payload))))
    (resp-ok)))

