Call changePassword() on "Save change" press
Call the changePassword() function when a user presses the
"Save change" Change password button.
Also, validate the password fields.
Tested: Changed the password on a Witherspoon.
Change-Id: I479929c82c5e405591fa7b1cf01e5491d35079e7
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/app/users/controllers/user-accounts-controller.html b/app/users/controllers/user-accounts-controller.html
index 3f05bff..80b6c7d 100644
--- a/app/users/controllers/user-accounts-controller.html
+++ b/app/users/controllers/user-accounts-controller.html
@@ -11,7 +11,7 @@
<legend aria-label="user manager" class="accessible-text">Change password form</legend>
<div class="row column">
<label for="user-manage__current-password">Current password</label>
- <input id="user-manage__current-password" type="password" class="user-manage__current-password inline"/>
+ <input id="user-manage__current-password" type="password" ng-model="oldPassword" class="user-manage__current-password inline"/>
</div>
<div class="inline">
<label for="user-manage__new-password">New password</label>
@@ -35,8 +35,8 @@
</div>
</fieldset>
<div class="user-manage__submit-wrapper">
- <button class="btn-primary inline">Save change</button>
+ <button class="btn-primary inline" ng-click="changePassword(oldPassword, password, passwordVerify)">Save change</button>
</div>
</form>
</section>
-</div>
\ No newline at end of file
+</div>
diff --git a/app/users/controllers/user-accounts-controller.js b/app/users/controllers/user-accounts-controller.js
index f3d7160..8847f35 100644
--- a/app/users/controllers/user-accounts-controller.js
+++ b/app/users/controllers/user-accounts-controller.js
@@ -19,8 +19,31 @@
'dataService',
function($scope, $window, APIUtils, dataService){
$scope.dataService = dataService;
+ $scope.changePassword = function(oldPassword, newPassword, confirmNewPassword){
+ if(!oldPassword || !newPassword || !confirmNewPassword ){
+ // TODO: Display error
+ return false;
+ }
+ if (newPassword !== confirmNewPassword){
+ // TODO: Display error
+ return false;
+ }
+ if (newPassword === oldPassword){
+ // TODO: Display error
+ return false;
+ }
+ // TODO: Verify the oldPassword is correct
+
+ APIUtils.changePassword($scope.dataService.getUser(), newPassword).then(function(response){
+ // Clear the textboxes on a success
+ $scope.passwordVerify = '';
+ $scope.password = '';
+ $scope.oldPassword = '';
+ }, function(error){
+ // TODO: Display error
+ });
+ }
}
]
);
-
})(angular);