Add the middleware to prevent access to the admin panel if authorized.
This commit is contained in:
@@ -62,6 +62,21 @@
|
|||||||
(.redirect res "/")
|
(.redirect res "/")
|
||||||
))))
|
))))
|
||||||
|
|
||||||
|
(defn is-user-authorized
|
||||||
|
"Middleware to check if user is authorized."
|
||||||
|
[req res next]
|
||||||
|
(if (some? (.-user (.-session req)))
|
||||||
|
(next)
|
||||||
|
(next (new js/Error "User not authorized!!!"))))
|
||||||
|
|
||||||
|
(defn user-not-authorized-factory
|
||||||
|
"Middleware to redirect authorized users to a url."
|
||||||
|
([url]
|
||||||
|
(fn [err req res next]
|
||||||
|
(.redirect res "/login")))
|
||||||
|
([]
|
||||||
|
(user-not-authorized-factory "/login")))
|
||||||
|
|
||||||
(defn admin-panel-handler-factory
|
(defn admin-panel-handler-factory
|
||||||
[client]
|
[client]
|
||||||
(fn [req res]
|
(fn [req res]
|
||||||
|
|||||||
@@ -77,34 +77,66 @@
|
|||||||
|
|
||||||
|
|
||||||
(. app get "/admin"
|
(. app get "/admin"
|
||||||
|
handlers/is-user-authorized
|
||||||
(handlers/admin-panel-handler-factory client))
|
(handlers/admin-panel-handler-factory client))
|
||||||
|
|
||||||
|
(. app use "/admin"
|
||||||
|
(handlers/user-not-authorized-factory))
|
||||||
|
|
||||||
(. app post "/htmx/search/articles/"
|
(. app post "/htmx/search/articles/"
|
||||||
(handlers/htmx-search-articles-handler-factory client))
|
(handlers/htmx-search-articles-handler-factory client))
|
||||||
|
|
||||||
(. app post "/htmx/articles/"
|
(. app post "/htmx/articles/"
|
||||||
|
handlers/is-user-authorized
|
||||||
(handlers/htmx-create-article-handler-factory client))
|
(handlers/htmx-create-article-handler-factory client))
|
||||||
|
|
||||||
|
(. app use "/htmx/articles/"
|
||||||
|
(handlers/user-not-authorized-factory))
|
||||||
|
|
||||||
(. app get "/htmx/articles/:id"
|
(. app get "/htmx/articles/:id"
|
||||||
(handlers/htmx-get-article-handler-factory client))
|
(handlers/htmx-get-article-handler-factory client))
|
||||||
|
|
||||||
(. app post "/htmx/admin/search/articles/"
|
(. app post "/htmx/admin/search/articles/"
|
||||||
|
handlers/is-user-authorized
|
||||||
(handlers/htmx-admin-search-articles-handler-factory client))
|
(handlers/htmx-admin-search-articles-handler-factory client))
|
||||||
|
|
||||||
|
(. app use "/htmx/admin/search/articles/"
|
||||||
|
(handlers/user-not-authorized-factory))
|
||||||
|
|
||||||
(. app get "/htmx/admin/rows/article/:id/"
|
(. app get "/htmx/admin/rows/article/:id/"
|
||||||
|
handlers/is-user-authorized
|
||||||
(handlers/htmx-get-article-row-handler-factory client))
|
(handlers/htmx-get-article-row-handler-factory client))
|
||||||
|
|
||||||
|
(. app use "/htmx/admin/rows/article/:id/"
|
||||||
|
(handlers/user-not-authorized-factory))
|
||||||
|
|
||||||
(. app patch "/htmx/admin/rows/article/:id/"
|
(. app patch "/htmx/admin/rows/article/:id/"
|
||||||
|
handlers/is-user-authorized
|
||||||
(handlers/htmx-update-article-handler-factory client))
|
(handlers/htmx-update-article-handler-factory client))
|
||||||
|
|
||||||
|
(. app use "/htmx/admin/rows/article/:id/"
|
||||||
|
(handlers/user-not-authorized-factory))
|
||||||
|
|
||||||
(. app delete "/htmx/admin/rows/article/:id/"
|
(. app delete "/htmx/admin/rows/article/:id/"
|
||||||
|
handlers/is-user-authorized
|
||||||
(handlers/htmx-delete-article-row-handler-factory client))
|
(handlers/htmx-delete-article-row-handler-factory client))
|
||||||
|
|
||||||
|
(. app use "/htmx/admin/rows/article/:id/"
|
||||||
|
(handlers/user-not-authorized-factory))
|
||||||
|
|
||||||
(. app get "/htmx/admin/modals/article/content/:id/"
|
(. app get "/htmx/admin/modals/article/content/:id/"
|
||||||
|
handlers/is-user-authorized
|
||||||
(handlers/htmx-get-article-preview-content-handler-factory client))
|
(handlers/htmx-get-article-preview-content-handler-factory client))
|
||||||
|
|
||||||
|
(. app use "/htmx/admin/modals/article/content/:id/"
|
||||||
|
(handlers/user-not-authorized-factory))
|
||||||
|
|
||||||
(. app get "/htmx/admin/modals/article/edit-content/:id/"
|
(. app get "/htmx/admin/modals/article/edit-content/:id/"
|
||||||
|
handlers/is-user-authorized
|
||||||
(handlers/htmx-get-article-edit-content-handler-factory client))
|
(handlers/htmx-get-article-edit-content-handler-factory client))
|
||||||
|
|
||||||
|
(. app use "/htmx/admin/modals/article/edit-content/:id/"
|
||||||
|
(handlers/user-not-authorized-factory))
|
||||||
)
|
)
|
||||||
|
|
||||||
(defn start
|
(defn start
|
||||||
|
|||||||
Reference in New Issue
Block a user