Add password change functionality
authorChip Black <bytex64@bytex64.net>
Wed, 30 May 2012 23:29:32 +0000 (16:29 -0700)
committerChip Black <bytex64@bytex64.net>
Wed, 30 May 2012 23:29:32 +0000 (16:29 -0700)
www/jssrc/blerg/API.js
www/jssrc/blerg/Blerg.js
www/jssrc/blerg/Controls.js
www/jssrc/blerg/PasswdDialog.js

index 30dc7b5..4a0602b 100644 (file)
@@ -88,6 +88,24 @@ enyo.kind({
         });
         enyo.setCookie('username', '', {"Max-Age": 0});
     },
+    changePassword: function(oldpassword, newpassword) {
+        var req = new enyo.Ajax({
+            url: baseURL + '/passwd',
+            method: 'POST'
+        });
+        req.response(function(inSender, inResponse) {
+            if (inResponse.status == 'success') {
+                this.bubble('onPasswordChangeSuccessful');
+            } else {
+                this.bubble('onPasswordChangeFailed');
+            }
+        }.bind(this));
+        req.go({
+            username: blerg.API.username,
+            password: oldpassword,
+            new_password: newpassword
+        });
+    },
     loadUserRecords: function(username, from ,to) {
         var url;
         if (from != undefined && to != undefined) {
index 22bfddb..9285d2b 100644 (file)
@@ -9,7 +9,8 @@ enyo.kind({
         onTryLogout: "tryLogout",
         onSetTitle: "setTitle",
         onPostVisibility: "postVisibilityUpdate",
-        onReload: "sendReload"
+        onReload: "sendReload",
+        onShowChangePassword: "showChangePassword",
     },
     components: [
         {classes: "blerg-header", components: [
@@ -92,5 +93,8 @@ enyo.kind({
     },
     sendReload: function() {
         this.$.main.waterfall('onReload');
+    },
+    showChangePassword: function() {
+        this.$.passwdDialog.show();
     }
 });
index 480e552..165b100 100644 (file)
@@ -32,14 +32,11 @@ enyo.kind({
                 {name: "userlink", tag: "a"},
                 {tag: null, content: ". "},
                 {kind: "blerg.Link", content: "Logout", onNavigate: "logoutClicked"},
+                {tag: null, content: "."},
+                {tag: "br"},
+                {kind: "blerg.Link", content: "Change Password", onNavigate: "changePasswordClicked"},
                 {tag: null, content: "."}
             ]},
-            {components: [
-                {name: "rssButton", kind: "blerg.Link", showing: false, components: [
-                    {kind: "Image", src: "/images/rss.png", width: 16, height: 16},
-                    {tag: null, content: " RSS"}
-                ]}
-            ]},
             {classes: "blerg-controls-toolbar", components: [
                 {kind: "onyx.Button", content: "Feed Your Vanity", onclick: "chatterClicked"},
                 {name: "feedButton", kind: "onyx.Button", classes: "feed-button", content: "Stalk Your Victims", onclick: "feedClicked"},
@@ -94,6 +91,9 @@ enyo.kind({
         this.setLoggedIn(false);
         clearInterval(this.feedStatusUpdateInterval);
     },
+    changePasswordClicked: function() {
+        this.bubble('onShowChangePassword');
+    },
     spewToggle: function(inSender, inEvent) {
         this.postShowing = !this.postShowing;
         this.bubble('onPostVisibility', {showing: this.postShowing});
index 6144220..fc8dde2 100644 (file)
@@ -7,22 +7,63 @@ enyo.kind({
     floating: true,
     modal: true,
     components: [
-        {tag: "h2", content: "Sign Up"},
+        {tag: "h2", content: "Change Password"},
+        {name: "spinner", kind: "OldSchoolSpinner", showing: false, style: "position: absolute; top: 8px; right: 8px;"},
         {kind: "onyx.Groupbox", components: [
             {kind: "onyx.InputDecorator", components: [
-                {name: "password1", kind: "onyx.Input", placeholder: "Username", type: "password"}
+                {name: "oldpassword", kind: "onyx.Input", placeholder: "Old Password", type: "password"}
+            ]}
+        ]},
+        {kind: "onyx.Groupbox", components: [
+            {kind: "onyx.InputDecorator", components: [
+                {name: "password1", kind: "onyx.Input", placeholder: "New Password", type: "password"}
             ]},
             {kind: "onyx.InputDecorator", components: [
-                {name: "password2", kind: "onyx.Input", placeholder: "Password", type: "password"}
+                {name: "password2", kind: "onyx.Input", placeholder: "New Password (again)", type: "password"}
             ]}
         ]},
-        {kind: "onyx.Button", content: "Change", onclick: "changeClick", classes: "onyx.affirmative"},
-        {kind: "onyx.Button", content: "Cancel", onclick: "cancelClick", classes: "onyx-negative"}
+        {name: "changePasswordError", tag: "p", showing: false, classes: "blerg-error", content: "I couldn't change your password. Are you sure you have the right old password?"},
+        {name: "passwordMatchError", tag: "p", showing: false, classes: "blerg-error", content: "Your new passwords don't match."},
+        {name: "changeButton", kind: "onyx.Button", content: "Change", onclick: "changeClick", classes: "onyx.affirmative"},
+        {kind: "onyx.Button", content: "Cancel", onclick: "cancelClick", classes: "onyx-negative"},
+        {name: "api", kind: "blerg.API",
+         onPasswordChangeSuccessful: "passwordChangeSuccessful",
+         onPasswordChangeFailed: "passwordChangeFailed"}
     ],
+    hideErrors: function() {
+        this.$.changePasswordError.hide();
+        this.$.passwordMatchError.hide();
+    },
     changeClick: function() {
-        // Do stuff
+        this.hideErrors();
+        if (this.$.oldpassword.getValue() == '') {
+            this.$.changePasswordError.show();
+            return;
+        }
+        if (this.$.password1.getValue() != this.$.password2.getValue()) {
+            this.$.passwordMatchError.show();
+            return;
+        }
+        this.$.changeButton.setDisabled(true);
+        this.$.spinner.show();
+        this.$.spinner.start();
+        this.$.api.changePassword(this.$.oldpassword.getValue(), this.$.password1.getValue());
     },
     cancelClick: function() {
         this.hide();
+    },
+    passwordChangeSuccessful: function(inSender, inEvent) {
+        this.$.changeButton.setDisabled(false);
+        this.$.spinner.hide();
+        this.$.spinner.stop();
+        this.cancelClick();
+        alert("Password Changed Successfully");
+    },
+    passwordChangeFailed: function(inSender, inEvent) {
+        this.$.changeButton.setDisabled(false);
+        this.$.spinner.hide();
+        this.$.spinner.stop();
+        this.hideErrors();
+        this.$.changePasswordError.show();
     }
 });