diff options
-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> |