diff --git a/resources/templates/layout.html b/resources/templates/layout.html index d97379f..923c880 100644 --- a/resources/templates/layout.html +++ b/resources/templates/layout.html @@ -54,6 +54,12 @@
+ {% if flash.message %} + + {% endif %} + {% block content %} {% endblock %}
diff --git a/src/clj/yenu/handler.clj b/src/clj/yenu/handler.clj index 99df19e..f66499e 100644 --- a/src/clj/yenu/handler.clj +++ b/src/clj/yenu/handler.clj @@ -23,14 +23,12 @@ (wrap-routes middleware/wrap-csrf) (wrap-routes middleware/wrap-formats) (wrap-routes middleware/wrap-identity) - (wrap-routes middleware/wrap-auth) - ) + (wrap-routes middleware/wrap-auth)) (-> #'admin-routes (wrap-routes middleware/wrap-csrf) (wrap-routes middleware/wrap-formats) (wrap-routes middleware/wrap-identity) - (wrap-routes middleware/wrap-auth) - ) + (wrap-routes middleware/wrap-auth)) (route/not-found (:body (error-page {:status 404 diff --git a/src/clj/yenu/layout.clj b/src/clj/yenu/layout.clj index fb30e21..cb8c8cb 100644 --- a/src/clj/yenu/layout.clj +++ b/src/clj/yenu/layout.clj @@ -28,8 +28,7 @@ :page template :csrf-token *anti-forgery-token* :servlet-context *app-context* - :identity *identity* - ))) + :identity *identity*))) "text/html; charset=utf-8")) (defn error-page diff --git a/src/clj/yenu/routes/admin.clj b/src/clj/yenu/routes/admin.clj index 04a5653..221f628 100644 --- a/src/clj/yenu/routes/admin.clj +++ b/src/clj/yenu/routes/admin.clj @@ -36,13 +36,16 @@ (run! #(add-tag image-id %) all-tags))) (defroutes admin-routes - (GET "/upload" [] - (layout/render "admin/upload.html")) + (GET "/upload" [:as request] + (-> (layout/render + "admin/upload.html" + {:flash (:flash request)}))) (POST "/upload" [file title description tags] (-> (upload-file file) (images/process-image) (add-image-to-database title description tags)) - (redirect "/")) + (-> (redirect "/upload") + (assoc :flash {:message "Upload erfolgreich." :type "success"}))) (GET "/statistics" [] (layout/render "statistics.html")) diff --git a/src/clj/yenu/routes/auth.clj b/src/clj/yenu/routes/auth.clj index c2af0f2..00b7db4 100644 --- a/src/clj/yenu/routes/auth.clj +++ b/src/clj/yenu/routes/auth.clj @@ -15,16 +15,20 @@ user-identity (valid-identity password)] (if user-identity (let [updated-session (assoc session :identity user-identity)] - (-> (redirect "/") - (assoc :session updated-session)))))) + (-> (redirect "/page/1") + (assoc :flash {:message "Erfolgreich eingeloggt." :type "success"}) + (assoc :session updated-session))) + (-> (redirect "/login") + (assoc :flash {:message "Falsches Passwort." :type "danger"}))))) (defn logout! [request] - (-> (redirect "/") - (assoc :session {}))) + (-> (redirect "/login") + (assoc :session {}) + (assoc :flash {:message "Erfolgreich ausgeloggt." :type "success"}))) (defroutes auth-routes - (GET "/login" [] - (layout/render "login.html")) + (GET "/login" [:as request] + (layout/render "login.html", {:flash (:flash request)})) (POST "/login" [] login!) (GET "/logout" [] logout!)) diff --git a/src/clj/yenu/routes/core.clj b/src/clj/yenu/routes/core.clj index a168fbe..9b5f140 100644 --- a/src/clj/yenu/routes/core.clj +++ b/src/clj/yenu/routes/core.clj @@ -10,7 +10,7 @@ (int (Math/ceil (/ (:count (db/get-image-count)) images-on-page)))) -(defn index-page [current-page] +(defn index-page [current-page request] (let [image-count 15 offset (* (dec current-page) image-count) pages (number-of-pages image-count) @@ -18,7 +18,8 @@ (layout/render "index.html" {:images images :current-page current-page - :pages (range 1 (inc pages))}))) + :pages (range 1 (inc pages)) + :flash (:flash request)}))) (defn detail-page [image-id] (let [image (db/get-image {:id image-id}) @@ -39,8 +40,8 @@ (defroutes core-routes (GET "/" [] (redirect "/page/1")) - (GET "/page/:page-number" [page-number] - (index-page (Integer. page-number))) + (GET "/page/:page-number" [page-number :as request] + (index-page (Integer. page-number) request)) (GET "/show/:image-id" [image-id] (detail-page image-id)) (GET ["/images/:type/:hash.:ext"