aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchristoph <christoph@debian.uxul.homelinux.org>2009-02-20 22:37:45 +0100
committerchristoph <christoph@debian.uxul.homelinux.org>2009-02-20 22:37:45 +0100
commitdc698a62c5ad27cbe7df98b66c2937b56abc06ee (patch)
tree1831cf811b107b77f8607cfa7007001d99b7dd28
parenteb9939d459cc177f87e0f2ca25d8ff415bed8c59 (diff)
parentebdeda08f19dd1f18220727fe80906c0c18c0db4 (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.clj59
-rw-r--r--login.st4
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)))
diff --git a/login.st b/login.st
index 3583b88..41cd2fa 100644
--- a/login.st
+++ b/login.st
@@ -9,10 +9,10 @@
<body>
$logintext$
- <form action="do_login" method="POST">
+ <form 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>