summaryrefslogtreecommitdiffstats
path: root/app/profile-settings/controllers/profile-settings-controller.js
diff options
context:
space:
mode:
authorYoshie Muranaka <yoshiemuranaka@gmail.com>2020-01-29 13:21:12 -0800
committerGunnar Mills <gmills@us.ibm.com>2020-02-11 16:43:22 +0000
commit4148f2eee6313068d3223871005160b2902abb18 (patch)
tree5266cfee8f41eda2224479d2c911c3128988a38a /app/profile-settings/controllers/profile-settings-controller.js
parentb0a0847a8eb02ae21f755942799a81c6e3475e64 (diff)
downloadphosphor-webui-master.tar.gz
phosphor-webui-master.zip
Create profile settings pageHEADmaster
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
Diffstat (limited to 'app/profile-settings/controllers/profile-settings-controller.js')
-rw-r--r--app/profile-settings/controllers/profile-settings-controller.js75
1 files changed, 75 insertions, 0 deletions
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);
OpenPOWER on IntegriCloud