TwoToc code
[YouAndWeb_TwoToc] / client / app / account / settings / settings.controller.js
diff --git a/client/app/account/settings/settings.controller.js b/client/app/account/settings/settings.controller.js
new file mode 100755 (executable)
index 0000000..b57829d
--- /dev/null
@@ -0,0 +1,21 @@
+'use strict';
+
+angular.module('dashboardApp')
+  .controller('SettingsCtrl', function($scope, User, Auth) {
+    $scope.errors = {};
+
+    $scope.changePassword = function(form) {
+      $scope.submitted = true;
+      if (form.$valid) {
+        Auth.changePassword($scope.user.oldPassword, $scope.user.newPassword)
+          .then(function() {
+            $scope.message = 'Password successfully changed.';
+          })
+          .catch(function() {
+            form.password.$setValidity('mongoose', false);
+            $scope.errors.other = 'Incorrect password';
+            $scope.message = '';
+          });
+      }
+    };
+  });