Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Controller for user Accounts |
| 3 | * |
| 4 | * @module app/users |
| 5 | * @exports userAccountsController |
| 6 | * @name userAccountsController |
| 7 | * @version 0.1.0 |
| 8 | */ |
| 9 | |
| 10 | window.angular && (function (angular) { |
| 11 | 'use strict'; |
| 12 | |
| 13 | angular |
| 14 | .module('app.users') |
| 15 | .controller('userAccountsController', [ |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 16 | '$scope', |
| 17 | '$window', |
| 18 | 'APIUtils', |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 19 | 'dataService', |
| 20 | function($scope, $window, APIUtils, dataService){ |
| 21 | $scope.dataService = dataService; |
Gunnar Mills | 6b97dde | 2018-03-14 17:04:58 -0500 | [diff] [blame] | 22 | $scope.changePassword = function(oldPassword, newPassword, confirmNewPassword){ |
| 23 | if(!oldPassword || !newPassword || !confirmNewPassword ){ |
| 24 | // TODO: Display error |
| 25 | return false; |
| 26 | } |
| 27 | if (newPassword !== confirmNewPassword){ |
| 28 | // TODO: Display error |
| 29 | return false; |
| 30 | } |
| 31 | if (newPassword === oldPassword){ |
| 32 | // TODO: Display error |
| 33 | return false; |
| 34 | } |
Gunnar Mills | 6b97dde | 2018-03-14 17:04:58 -0500 | [diff] [blame] | 35 | |
Gunnar Mills | 32581cf | 2018-03-16 15:52:54 -0500 | [diff] [blame^] | 36 | // Verify the oldPassword is correct |
| 37 | APIUtils.testPassword($scope.dataService.getUser(), oldPassword).then(function(state){ |
| 38 | APIUtils.changePassword($scope.dataService.getUser(), newPassword).then(function(response){ |
| 39 | // Clear the textboxes on a success |
| 40 | $scope.passwordVerify = ''; |
| 41 | $scope.password = ''; |
| 42 | $scope.oldPassword = ''; |
| 43 | }, function(error){ |
| 44 | // TODO: Display error |
| 45 | }); |
Gunnar Mills | 6b97dde | 2018-03-14 17:04:58 -0500 | [diff] [blame] | 46 | }, function(error){ |
| 47 | // TODO: Display error |
| 48 | }); |
| 49 | } |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 50 | } |
| 51 | ] |
| 52 | ); |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 53 | })(angular); |