Create profile settings page

Adding a profile settings page so readonly and operator
roles are able to change their own password.

Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com>
Change-Id: Iee9536255ad47f4df4af8746c1e01da37c407f2b
diff --git a/app/profile-settings/controllers/profile-settings-controller.js b/app/profile-settings/controllers/profile-settings-controller.js
new file mode 100644
index 0000000..404e055
--- /dev/null
+++ b/app/profile-settings/controllers/profile-settings-controller.js
@@ -0,0 +1,75 @@
+/**
+ * Controller for the profile settings page
+ *
+ * @module app/profile-settings/controllers/index
+ * @exports ProfileSettingsController
+ * @name ProfileSettingsController
+ */
+
+window.angular && (function(angular) {
+  'use strict';
+
+  angular.module('app.profileSettings')
+      .controller('profileSettingsController', [
+        '$scope', 'APIUtils', 'dataService', 'toastService',
+        function($scope, APIUtils, dataService, toastService) {
+          $scope.username;
+          $scope.minPasswordLength;
+          $scope.maxPasswordLength;
+          $scope.password;
+          $scope.passwordConfirm;
+
+          /**
+           * Make API call to update user password
+           * @param {string} password
+           */
+          const updatePassword = function(password) {
+            $scope.loading = true;
+            APIUtils.updateUser($scope.username, null, password)
+                .then(
+                    () => toastService.success(
+                        'Password has been updated successfully.'))
+                .catch((error) => {
+                  console.log(JSON.stringify(error));
+                  toastService.error('Unable to update password.')
+                })
+                .finally(() => {
+                  $scope.password = '';
+                  $scope.passwordConfirm = '';
+                  $scope.form.$setPristine();
+                  $scope.form.$setUntouched();
+                  $scope.loading = false;
+                })
+          };
+
+          /**
+           * API call to get account settings for min/max
+           * password length requirement
+           */
+          const getAllUserAccountProperties = function() {
+            APIUtils.getAllUserAccountProperties().then((accountSettings) => {
+              $scope.minPasswordLength = accountSettings.MinPasswordLength;
+              $scope.maxPasswordLength = accountSettings.MaxPasswordLength;
+            })
+          };
+
+          /**
+           * Callback after form submitted
+           */
+          $scope.onSubmit = function(form) {
+            if (form.$valid) {
+              const password = form.password.$viewValue;
+              updatePassword(password);
+            }
+          };
+
+          /**
+           * Callback after view loaded
+           */
+          $scope.$on('$viewContentLoaded', () => {
+            getAllUserAccountProperties();
+            $scope.username = dataService.getUser();
+          });
+        }
+      ]);
+})(angular);