summaryrefslogtreecommitdiffstats
path: root/app/profile-settings/controllers/profile-settings-controller.js
diff options
context:
space:
mode:
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