Created
July 24, 2009 03:20
-
-
Save lrenn/153821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn login-view [flash] | |
(html [:html | |
[:body | |
[:h2 "Login"] | |
(if-let [message (:message flash)] | |
[:h4 message]) | |
(form-to [:post "/login"] | |
(text-field :username) | |
(password-field :password) | |
(submit-button "Login"))]])) | |
(defn login-controller [params request] | |
(if (= (:password params) "secret") | |
[(session-assoc :username (:username params)) | |
(redirect-to "/home")] | |
[(flash-assoc :message "Login failed.") | |
(redirect-to "/login")])) | |
(defn home-view [username] | |
(html | |
[:html | |
[:body | |
[:h2 "Home" | |
[:p (str "Hello " username ".")]]]])) | |
(defn home-controller [session] | |
(if-let [username (:username session)] | |
(home-view username) | |
(redirect-to "/login"))) | |
(defroutes app | |
(GET "/login" (login-view flash)) | |
(POST "/login" (login-controller params request)) | |
(GET "/home" (home-controller session))) | |
(decorate app | |
(with-session)) | |
(run-server {:port 8080} "/*" (servlet app)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment