Add flash messages #10
This commit is contained in:
parent
81fe574b7b
commit
c0270f5f4b
6 changed files with 30 additions and 19 deletions
|
@ -54,6 +54,12 @@
|
|||
</nav>
|
||||
|
||||
<div id="content" class="col-md-12">
|
||||
{% if flash.message %}
|
||||
<div class="alert alert-{{ flash.type }}" role="alert">
|
||||
{{ flash.message }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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!))
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue