Add front-end password changing bits
authorChip Black <bytex64@bytex64.net>
Thu, 19 Jan 2012 08:02:16 +0000 (02:02 -0600)
committerChip Black <bytex64@bytex64.net>
Thu, 19 Jan 2012 08:02:46 +0000 (02:02 -0600)
www/index.html
www/js/blerg.js

index 42a1c01..d99212b 100644 (file)
       username: <input type="text" id="login.username" size="10">
       password: <input type="password" id="login.password" size="10">
       <input type="submit" value="login">
-      <p style="font-size: large"><a href="#" onclick="$('welcome').hide(); $('items').hide(); $('post').hide(); $('signup').show(); return false;">I want to blërg!</a></p>
+      <p style="font-size: large"><a href="#" onclick="$('welcome').hide(); $('items').hide(); $('post').hide(); $('signup').show(); return false">I want to blërg!</a></p>
     </form>
     <div id="logout" style="display: none">
-      Hello, <a href="#" id="userlink" onclick="return qlink()"></a>. <a href="#" onclick="loginStatus.logout(); return false">logout</a><br>
+      Hello, <a href="#" id="userlink" onclick="return qlink()"></a>. <a href="#" onclick="$('welcome').hide(); $('items').hide(); $('post').hide(); $('navigation').hide(); $('passwd').show(); return false">change password</a> <a href="#" onclick="loginStatus.logout(); return false">logout</a><br>
       <a href="#" onclick="postPopup(); return false">Write new entry</a><br>
       <a href="#" id="reflink" onclick="return qlink()">Chatter about me</a><br>
       <a href="#/feed" onclick="return qlink()">Stalk your victims <span id="newFeedMessages"></span></a>
   <div id="signup" style="display:none">
     <h2>Sign Up</h2>
     <table>
-      <tr><td>Username:</td><td><input type="text" id="signup.username" width="40"></td>
-      <tr><td>Password:</td><td><input type="password" id="signup.password" width="40"></td>
+      <tr><td>Username:</td><td><input type="text" id="signup.username" width="40"></td></tr>
+      <tr><td>Password:</td><td><input type="password" id="signup.password" width="40"></td></tr>
     </table>
     <button onclick="signup()">Signup</button> <button onclick="signup_cancel()">Cancel</button>
   </div>
+
+  <div id="passwd" style="display:none">
+    <h2>Change Your Password</h2>
+    <table>
+      <tr><td>Old Password:</td><td><input type="text" id="passwd.old_password" width="40"></td></tr>
+      <tr><td>New Password:</td><td><input type="text" id="passwd.new_password" width="40"></td></tr>
+    </table>
+    <button onclick="passwd()">Change</button> <button onclick="passwd_cancel()">Cancel</button>
+  </div>
+
 </div>
 
 </body>
index 83483fa..2ef48d9 100644 (file)
@@ -647,6 +647,36 @@ function signup_cancel() {
     urlSwitch();
 }
 
+function passwd() {
+    var old_password = $('passwd.old_password').value;
+    var new_password = $('passwd.new_password').value;
+
+    new Ajax.Request(baseURL + '/passwd', {
+        parameters: {
+            username: loginStatus.username,
+            password: old_password,
+            new_password: new_password
+        },
+        onSuccess: function(r) {
+            if (r.responseJSON.status == 'success') {
+                alert('Password changed');
+                passwd_cancel();
+            } else {
+                alert('Password change failed.  Your password has NOT been changed.');
+            }
+        },
+        onFailure: function(r) {
+            alert('Password change error');
+        }
+    });
+}
+
+function passwd_cancel() {
+    $('passwd').hide();
+    $('navigation').show();
+    urlSwitch();
+}
+
 function subscribe() {
     new Ajax.Request(baseURL + '/subscribe/' + currentPager.username, {
         method: 'post',
@@ -814,6 +844,10 @@ Welcome.prototype.hide = function() {
     $('welcome').hide();
 }
 
+Welcome.prototype.updateState = function() {
+    this.show();
+}
+
 function ExternalURLPost(m) {
     this.title = decodeURIComponent(m[1]).replace(']','').replace('[','');
     this.url = decodeURIComponent(m[2]);