[bknr-cvs] hans changed trunk/projects/quickhoney/

BKNR Commits bknr at bknr.net
Wed Aug 27 23:57:40 UTC 2008


Revision: 3744
Author: hans
URL: http://bknr.net/trac/changeset/3744

Reimplement login and logout, now a separate page is used to log in.

U   trunk/projects/quickhoney/src/handlers.lisp
U   trunk/projects/quickhoney/src/news.lisp
U   trunk/projects/quickhoney/src/tags.lisp
U   trunk/projects/quickhoney/src/webserver.lisp
U   trunk/projects/quickhoney/website/static/javascript.js
A   trunk/projects/quickhoney/website/static/login.css
U   trunk/projects/quickhoney/website/templates/index.xml
A   trunk/projects/quickhoney/website/templates/login.xml

Modified: trunk/projects/quickhoney/src/handlers.lisp
===================================================================
--- trunk/projects/quickhoney/src/handlers.lisp	2008-08-27 17:27:40 UTC (rev 3743)
+++ trunk/projects/quickhoney/src/handlers.lisp	2008-08-27 23:57:40 UTC (rev 3744)
@@ -92,8 +92,19 @@
 (defmethod handle ((handler json-login-handler))
   (with-json-response ()
     (encode-object-element "admin" (admin-p (bknr-session-user)))
+    (when (and (anonymous-p (bknr-session-user))
+               (query-param "__username"))
+      (encode-object-element "login_failed" t))
     (encode-object-element "login" (user-login (bknr-session-user)))))
 
+(defclass json-logout-handler (page-handler)
+  ())
+
+(defmethod handle ((handler json-logout-handler))
+  (setf (session-value 'bknr-session) nil)
+  (with-json-response ()
+    (encode-object-element "logged_out" t)))
+
 (defclass json-clients-handler (page-handler)
   ())
 

Modified: trunk/projects/quickhoney/src/news.lisp
===================================================================
--- trunk/projects/quickhoney/src/news.lisp	2008-08-27 17:27:40 UTC (rev 3743)
+++ trunk/projects/quickhoney/src/news.lisp	2008-08-27 23:57:40 UTC (rev 3744)
@@ -13,10 +13,9 @@
       (html-stream
        s
        ((:div :class (format nil "newsentry news_~(~A~)" category))
-        ((:img :src (format nil "http://~A/image/~A/cutout-button,,~A,98,98,4"
+        ((:img :src (format nil "http://~A/image/~A"
                             (website-host)
-                            (store-object-id image)
-                            (if is-vector "00ccff" "ff00ff")))
+                            (store-object-id image)))
         (:div
          (:h1 (:princ (store-image-name image)))
          (:princ (format nil "~A by ~A | "

Modified: trunk/projects/quickhoney/src/tags.lisp
===================================================================
--- trunk/projects/quickhoney/src/tags.lisp	2008-08-27 17:27:40 UTC (rev 3743)
+++ trunk/projects/quickhoney/src/tags.lisp	2008-08-27 23:57:40 UTC (rev 3744)
@@ -37,4 +37,14 @@
 (define-bknr-tag first-image-link ()
   (html
    ((:a :href #?"/image-browse/$((bknr.images:store-image-name (first (bknr.datastore:class-instances 'quickhoney-image))))")
-    (emit-tag-children))))
\ No newline at end of file
+    (emit-tag-children))))
+
+(define-bknr-tag login-status ()
+  (cond
+    ((bknr.web::admin-p (bknr-session-user))
+     (redirect "/index"))
+    ((and (bknr.web::anonymous-p (bknr-session-user))
+          (query-param "__username"))
+     (html (:h1 "Login failed, please try again")))
+    (t
+     (html (:h1 "Please login")))))
\ No newline at end of file

Modified: trunk/projects/quickhoney/src/webserver.lisp
===================================================================
--- trunk/projects/quickhoney/src/webserver.lisp	2008-08-27 17:27:40 UTC (rev 3743)
+++ trunk/projects/quickhoney/src/webserver.lisp	2008-08-27 23:57:40 UTC (rev 3744)
@@ -23,6 +23,7 @@
 					("/animation" animation-handler)
 					("/json-image-query" json-image-query-handler)
 					("/json-login" json-login-handler)
+					("/json-logout" json-logout-handler)
 					("/json-clients" json-clients-handler)
 					("/json-buttons" json-buttons-handler)
 					("/json-edit-image" json-edit-image-handler)

Modified: trunk/projects/quickhoney/website/static/javascript.js
===================================================================
--- trunk/projects/quickhoney/website/static/javascript.js	2008-08-27 17:27:40 UTC (rev 3743)
+++ trunk/projects/quickhoney/website/static/javascript.js	2008-08-27 23:57:40 UTC (rev 3744)
@@ -59,21 +59,12 @@
     debug('debug window cleared');
 }
 
-/* login */
+/* login status */
 
-function show_login() {
-    $("login_failure").style.visibility = 'hidden';
-    $("login_form").style.visibility = 'visible';
-}
+function login_status(json_result) {
 
-function hide_status() {
-    $("login_status").style.visibility = 'hidden';
-}
+    log('login_status, admin: ' + json_result.admin + ' login: ' + json_result.login);
 
-function login_complete(json_result) {
-
-    log('login_complete, admin: ' + json_result.admin + ' login: ' + json_result.login);
-
     logged_in = json_result.admin;
 
     if (logged_in) {
@@ -96,6 +87,7 @@
     var elements = $("cms").childNodes;
 
     if (logged_in) {
+
 	for (var i = 0; i < elements.length; i++) {
 	    if (elements[i].id) {
 		elements[i].style.visibility = (elements[i].id == name) ? "visible" : "hidden";
@@ -103,13 +95,13 @@
 	}
 
 	$("login_status").style.visibility = 'visible';
+
     } else {
 	for (var i = 0; i < elements.length; i++) {
 	    if (elements[i].id) {
 		elements[i].style.visibility = "hidden";
 	    }
 	}
-	$("login_form").style.visibility = 'visible';
     }
 }
 
@@ -121,10 +113,9 @@
 function send_logout() {
 
     logged_in = false;
-    loadJSONDoc("/logout")
+    show_cms_window();
+    loadJSONDoc("/json-logout")
         .addCallbacks(function () {}, alert);
-
-    show_cms_window("login_form");
 }
 
 /* image editing */
@@ -1170,7 +1161,7 @@
     }
 
     load_button_images();
-    loadJSONDoc("/json-login").addCallbacks(login_complete, alert);
+    loadJSONDoc("/json-login").addCallbacks(login_status, alert);
     loadJSONDoc('/json-news-archive/quickhoney').addCallbacks(initialize_news_archive, alert);
 
     if (!document.location.href.match(/#/)) {
@@ -1489,4 +1480,20 @@
         animator.attributes = { width: { to: 60 }, left: { to: 624 } };
         animator.animate();
     }
-}
\ No newline at end of file
+}
+
+/* login stuff */
+
+function init_login () {
+    $('username').focus();
+    $('login_form').style.display = 'block';
+}
+
+function do_login () {
+
+    $('login_form').style.display = 'none';
+    $('logging-in').style.display = 'block';
+
+    return true;
+}
+

Added: trunk/projects/quickhoney/website/static/login.css
===================================================================
--- trunk/projects/quickhoney/website/static/login.css	                        (rev 0)
+++ trunk/projects/quickhoney/website/static/login.css	2008-08-27 23:57:40 UTC (rev 3744)
@@ -0,0 +1,4 @@
+body { margin: 2em }
+table { margin-bottom: 1em }
+.label { padding-right: 1em }
+h1 { margin: 1em 0em 2em 0em }
\ No newline at end of file

Modified: trunk/projects/quickhoney/website/templates/index.xml
===================================================================
--- trunk/projects/quickhoney/website/templates/index.xml	2008-08-27 17:27:40 UTC (rev 3743)
+++ trunk/projects/quickhoney/website/templates/index.xml	2008-08-27 23:57:40 UTC (rev 3744)
@@ -358,23 +358,6 @@
         </p>
       </div>
       
-      <div id="login_form" class="cms_form">
-        <form method="post" name="login_form" onsubmit="return send_login();">
-          <b>Login</b> <br />
-          Username<br />
-          <input type="text" name="username" /><br />
-          Password<br />
-          <input type="password" name="password" /><br /><br />
-          <a href="#" onclick="send_login();" class="cmslink">login</a>
-          <input class="invisibleSubmit" type="submit" />
-        </form>
-      </div>
-
-      <div id="login_failure" class="cms_form">
-        <b>Login failed</b> <br />
-        Please check your user name and password.
-      </div>
-      
       <div id="login_status" class="cms_form">
         <p>You are logged in as <b id="username"> </b></p>
         <p><a href="#" onclick="send_logout();" class="cmslink">logout</a></p>

Added: trunk/projects/quickhoney/website/templates/login.xml
===================================================================
--- trunk/projects/quickhoney/website/templates/login.xml	                        (rev 0)
+++ trunk/projects/quickhoney/website/templates/login.xml	2008-08-27 23:57:40 UTC (rev 3744)
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
+   xmlns="http://www.w3.org/1999/xhtml"
+   xmlns:bknr="http://bknr.net/"
+   xmlns:quickhoney="http://quickhoney.com/"
+   >
+  <head>
+    <link rel="stylesheet" href="/static/yui/reset-fonts/reset-fonts.css" />
+    <link rel="stylesheet" href="/static/login.css" />
+    <script src="/MochiKit/MochiKit.js" type="text/javascript"> </script> 
+    <script src="/static/javascript.js" type="text/javascript"> </script> 
+    <title>QuickHoney CMS Login</title>
+  </head>
+
+  <body id="login">
+
+    <img id="logo" src="/image/quickhoney-black"/>
+
+    <form method="POST" id="login_form" style="display: none" onsubmit="do_login()">
+
+      <quickhoney:login-status />
+
+      <table>
+        <tbody>
+          <tr>
+            <td class="label"><label for="username">Username:</label></td>
+            <td><input name="__username" id="username" /><br/></td>
+          </tr>
+          <tr>
+            <td class="label"><label for="password">Password:</label></td>
+            <td><input name="__password" id="password" type="password" /></td>
+          </tr>
+        </tbody>
+      </table>
+      <button name="login" type="submit">login</button>
+    </form>
+
+    <h1 id="logging-in" style="display: none">Logging in...</h1>
+
+    <script language="javascript" type="text/javascript">
+      init_login();
+    </script>
+  </body>
+</html>




More information about the Bknr-cvs mailing list