0f766eda5d9f

Change passwords.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Thu, 29 Sep 2011 00:04:05 -0400
parents 003077f697d6
children c8dc1c1f1202
branches/tags (none)
files resources/public/css/style.less src/newseasons/templates/main.clj src/newseasons/views/main.clj

Changes

--- a/resources/public/css/style.less	Wed Sep 28 23:50:41 2011 -0400
+++ b/resources/public/css/style.less	Thu Sep 29 00:04:05 2011 -0400
@@ -1,7 +1,7 @@
 header {
     text-align: center;
     margin-top: 24px;
-    margin-bottom: 32px !important;
+    margin-bottom: 48px !important;
     padding-bottom: 12px;
     border-bottom: 2px solid #ddd;
 }
@@ -28,9 +28,17 @@
 .page-title {
     position: relative;
 
-    .logout {
+    .profile {
         position: absolute;
-        top: -6px;
+        top: -42px;
         right: 2px;
+
+        form {
+            display: inline;
+
+            input {
+                margin-left: 12px;
+            }
+        }
     }
 }
--- a/src/newseasons/templates/main.clj	Wed Sep 28 23:50:41 2011 -0400
+++ b/src/newseasons/templates/main.clj	Thu Sep 29 00:04:05 2011 -0400
@@ -40,10 +40,13 @@
 
 (defpartial inner [title & content]
             (base
-              
-              [:h2.sixteen.columns.page-title [:div.logout
-               (form-to [:post "/logout"]
-                        (submit-button "Log Out"))]title]
+              [:h2.sixteen.columns.page-title
+               [:div.profile
+                (form-to [:post "/logout"]
+                         (submit-button "Log Out"))
+                (form-to [:get "/password"]
+                         (submit-button "Change Password"))]
+               title]
               content))
 
 
@@ -85,3 +88,11 @@
             (inner (str "Search results for &ldquo;" query "&rdquo;")
                    [:ul.sixteen.columns
                     (map result results)]))
+
+
+(defpartial password []
+            (inner "Change Your Password"
+                   [:section.sixteen.columns
+                    (form-to [:post ""]
+                             (field password-field "password" "New Password")
+                             (submit-button "Change Password"))]))
--- a/src/newseasons/views/main.clj	Wed Sep 28 23:50:41 2011 -0400
+++ b/src/newseasons/views/main.clj	Thu Sep 29 00:04:05 2011 -0400
@@ -108,6 +108,24 @@
            (resp/redirect "/")))
 
 
+; Change Password -------------------------------------------------------------
+(defpage [:get "/password"] []
+         (login-required
+           (t/password)))
+
+
+(defn- pass-valid? [password]
+  (not (empty? password)))
+
+(defpage [:post "/password"] {:keys [password]}
+         (login-required
+           (if-not (pass-valid? password)
+             (render "/password" password)
+             (do
+               (users/user-set-pass! (sess/get :email) password)
+               (resp/redirect "/")))))
+
+
 ; Log Out ---------------------------------------------------------------------
 (defpage [:post "/logout"] []
          (sess/remove! :email)