You haven't included the code where the flash and session middleware are
applied to the handler, or the handler that consumes the flash message.

On 14 September 2017 at 02:31, Luis Medina <lm.no...@gmail.com> wrote:

> Hello to everybody!
>
> I'm pretty new in clojure, i trying to figure out how to redirect to
> another page with a flash value with a error message, could be something
> easy but i don't understood how to make that. Session it's relatibely fine,
> but flash it's empty every time. It's really dificult to find good and
> updated examples and answers.
>
> (ns my-app.routes.auth
>   (:require [my-app.layout :as layout]
>             [my-app.db.core :as db]
>             [my-app.db.user :as dbuser]
>             [compojure.core :refer [defroutes GET POST]]
>             [ring.util.response :refer [response redirect]]
>             [clojure.java.io :as io]
>             [buddy.auth :refer [authenticated?]]))
>
> (defn login-page
>   [request]
>   (layout/render "login.html" (println (:flash request))))
>
> (defn login-authenticate
>   [request]
>   (let [username (get-in request [:form-params "username"])
>         password (get-in request [:form-params "password"])
>         session (:session request)]
>     (if (dbuser/check-password username password)
>       (let [updated-session (assoc session
>                                    :identity (:id (db/get-user-id
> {:username username})))]
>         (-> (redirect "/")
>             (assoc :session updated-session))))
>     (assoc (redirect "/") :flash "errro")))
>
> (defn logout-authenticate
>   [{session :session}]
>   (-> (redirect "/login")
>       (assoc :session (dissoc session :identity))))
>
> (defroutes routes
>   (GET "/login" [] login-page)
>   (POST "/login" [] login-authenticate)
>   (GET "/logout" [] logout-authenticate))
>
>
>
> As you can see i have a println in login-page just for see in the console
> output if :flash have something...
>
> Thanks for taking the time to read.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
James Reeves
booleanknot.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to