diff options
author | christoph <christoph@debian.uxul.homelinux.org> | 2009-02-20 22:40:10 +0100 |
---|---|---|
committer | christoph <christoph@debian.uxul.homelinux.org> | 2009-02-20 22:40:10 +0100 |
commit | f9c4cd0dad8f576229ca490e22588d7c770c9f98 (patch) | |
tree | 4fa0edb57284344de708ba8f63000da6e81e6941 | |
parent | eb9939d459cc177f87e0f2ca25d8ff415bed8c59 (diff) | |
parent | ebdeda08f19dd1f18220727fe80906c0c18c0db4 (diff) |
Merge branch 'master' of ssh://schoppenhauer@uxul.org:63332/home/matthias/public_html/cljssss-g
Conflicts:
cljssss-g.clj
-rw-r--r-- | cljssss-g.clj | 59 | ||||
-rw-r--r-- | login.st | 4 |
2 files changed, 32 insertions, 31 deletions
diff --git a/cljssss-g.clj b/cljssss-g.clj index 0588a59..f57275f 100644 --- a/cljssss-g.clj +++ b/cljssss-g.clj @@ -12,6 +12,19 @@ (def templates (new StringTemplateGroup "")) +(def db-connection-data {:classname "org.sqlite.JDBC" + :subprotocol "sqlite" + :subname "cljssss-g.sqlite3" + :create true}) + +(defmacro with-db [& body] + `(sql/with-connection db-connection-data + ~@body)) + +(defmacro with-dbt [& body] + `(with-db + (sql/transaction + ~@body))) (defn login-view [] (.toString (.getInstanceOf templates "login"))) @@ -19,7 +32,7 @@ (defservlet cljssss-g (GET "/login" - (if (= (params :wrong) "true") + (if (= (params :valuesofbetawillgiverisetodom) "true") (.toString (doto (.getInstanceOf templates "login") (.setAttributes {"logintext" "Login failed"}))) @@ -28,37 +41,25 @@ (.setAttributes {"logintext" "Login"}))))) (POST "/login" (dosync - (with-db - (sql/with-query-results [{id :id password :password}] - ["SELECT id, password FROM user WHERE name = ?" - (@params :name)] - (if (= password (@params :password)) - (do - (alter session assoc :id id) - (redirect-to "/")) - (redirect-to "/login?wrong=true")))))) - (GET "/blah/" - (.toString - (doto (.getInstanceOf templates "index") - (.setAttributes {"title" "Subscriptions", - "mainParagraph" "Hi there!"})))) + (with-db + (sql/with-query-results [{id :id password :password}] + ["SELECT id, password FROM user WHERE name = ?" + (@params :name)] + (if (= password (@params :password)) + (do + (alter session assoc :id id) + (redirect-to "/")) + (redirect-to "/login?valuesofbetawillgiverisetodom=true")))))) + (GET "/" + (if (@session :id) + (.toString + (doto (.getInstanceOf templates "index") + (.setAttributes {"title" "Subscriptions", + "mainParagraph" "Hi there!"}))) + (redirect-to "/login"))) (ANY "*" (page-not-found))) -(def db-connection-data {:classname "org.sqlite.JDBC" - :subprotocol "sqlite" - :subname "cljssss-g.sqlite3" - :create true}) - -(defmacro with-db [& body] - `(sql/with-connection db-connection-data - ~@body)) - -(defmacro with-dbt [& body] - `(with-db - (sql/transaction - ~@body))) - (defn trim-nil [thing] (and thing (.trim thing))) @@ -9,10 +9,10 @@ <body> $logintext$ - <form action="do_login" method="POST"> + <form action="login" method="POST"> Username: <input name="name" type="text" /> <br /> Password: <input name="password" type="password" /> <br /> <input type="submit" value="Log In" /> </form> </body> -</html>
\ No newline at end of file +</html> |