Permalink
Browse files

Login page setup.

  • Loading branch information...
1 parent 50812f2 commit 5ae7b0eb5c964c3d429cb5fe60b5f3eb8c313446 @jwinnenb committed Jun 24, 2011
Showing with 37 additions and 7 deletions.
  1. +6 −3 src/kh/common/user.clj
  2. +31 −4 src/kh/server/login_page.clj
View
@@ -41,15 +41,18 @@
(defn create-cookie [user]
(DigestUtils/md5Hex (str user (System/currentTimeMillis))))
-(defn set-cookie [user & cookie0]
+(defn new-cookie [user & cookie0]
(let [cookie (or (first cookie0)
(create-cookie user))]
- (c "update khuser set khcookie='%s' where khuname='%s'" cookie user)))
+ (c "update khuser set khcookie='%s' where khuname='%s'" cookie user)
+ cookie))
(defn get-cookie [user]
(first
(q "select khcookie from khuser where khuname='%s'" user)))
(defn good-cookie? [user cookie]
(not (empty? (q "select * from khuser where khuname='%s' and khcookie='%s'" user cookie))))
-
+
+(defn good-pass? [user pass]
+ (not (empty? (q "select * from khuser where khuname='%s' and khpass='%s'" user pass))))
@@ -6,16 +6,43 @@
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
-
+;;
;; Knucklehead is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
-
+;;
;; You should have received a copy of the GNU General Public License
;; along with Foobar. If not, see <http://www.gnu.org/licenses/>.
;;
-(ns kh.server.login-page)
+(ns kh.server.login-page
+ (:use
+ [clojure.contrib string]
+ [hiccup core form-helpers]
+ [kh.common user))
+
+(defn default-page [title & body]
+ (html
+ [:head
+ [:title title]]
+ [:body
+ [:h1 title]
+ body]))
-(defn login-page [user pass])
+(defn login-page [user pass]
+ (cond
+ (good-pass? user pass) (let [cookie (str user (new-cookie user))]
+ ;; Send the cookie.
+ ;; Forward to comp/list
+ )
+ (or (blank? user)
+ (blank? pass)) (default-page
+ "Login"
+ [:table
+ [:tr
+ [:td "User: "]
+ [:td [:input#uname]]]
+ [:tr
+ [:td "Pass: "]
+ [:td (password-field "pass")]]])))

0 comments on commit 5ae7b0e

Please sign in to comment.