From eaef327b37d77192ec15df0ef6669aaf906ff0ff Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Sat, 28 Oct 2017 01:17:43 -0700 Subject: [PATCH] fixed reloading bug for settings pages --- .../users/config/users.client.routes.js | 19 ++++--- .../change_password.client.controller.js | 29 +++++++++++ .../controllers/settings.client.controller.js | 51 +------------------ .../settings/change-password.client.view.html | 2 +- 4 files changed, 41 insertions(+), 60 deletions(-) create mode 100644 public/modules/users/controllers/change_password.client.controller.js diff --git a/public/modules/users/config/users.client.routes.js b/public/modules/users/config/users.client.routes.js index b51f4771..e53d877d 100755 --- a/public/modules/users/config/users.client.routes.js +++ b/public/modules/users/config/users.client.routes.js @@ -5,25 +5,24 @@ angular.module('users').config(['$stateProvider', function($stateProvider) { var checkLoggedin = function($q, $timeout, $state, User, Auth) { - var deferred = $q.defer(); if (Auth.currentUser && Auth.currentUser.email) { - $timeout(deferred.resolve); + return; } else { - Auth.currentUser = User.getCurrent( - function() { - Auth.login(); - $timeout(deferred.resolve()); + return User.getCurrent().then( + function(user) { + Auth.login(user); + return; }, function() { - Auth.logout(); - $timeout(deferred.reject()); - $state.go('signin', {reload: true}); + Auth.logout(); + $state.go('signin', {reload: true}); + return; }); } - return deferred.promise; + }; var checkSignupDisabled = function($window, $timeout, $q) { diff --git a/public/modules/users/controllers/change_password.client.controller.js b/public/modules/users/controllers/change_password.client.controller.js new file mode 100644 index 00000000..e4114bf8 --- /dev/null +++ b/public/modules/users/controllers/change_password.client.controller.js @@ -0,0 +1,29 @@ +'use strict'; + +angular.module('users').controller('ChangePasswordController', ['$scope', '$rootScope', '$http', '$state', 'Users', 'Auth', + function($scope, $rootScope, $http, $state, Users, Auth) { + + $scope.user = Auth.currentUser; + console.log($scope.user) + + $scope.cancel = function(){ + $scope.user = Auth.currentUser; + } + + // Change user password + $scope.changeUserPassword = function() { + $scope.success = $scope.error = null; + + $http.post('/users/password', $scope.passwordDetails).success(function(response) { + // If successful show success message and clear form + $scope.success = true; + $scope.error = null; + $scope.passwordDetails = null; + }).error(function(response) { + $scope.success = null; + $scope.error = response.message; + }); + }; + */ + } +]); diff --git a/public/modules/users/controllers/settings.client.controller.js b/public/modules/users/controllers/settings.client.controller.js index fef50189..1404cddf 100755 --- a/public/modules/users/controllers/settings.client.controller.js +++ b/public/modules/users/controllers/settings.client.controller.js @@ -5,41 +5,9 @@ angular.module('users').controller('SettingsController', ['$scope', '$rootScope' $scope.user = Auth.currentUser; - // Check if there are additional accounts - $scope.hasConnectedAdditionalSocialAccounts = function(provider) { - for (var i in $scope.user.additionalProvidersData) { - return true; - } - return false; - }; - $scope.cancel = function(){ $scope.user = Auth.currentUser; - }; - - // Check if provider is already in use with current user - $scope.isConnectedSocialAccount = function(provider) { - return $scope.user.provider === provider || ($scope.user.additionalProvidersData && $scope.user.additionalProvidersData[provider]); - }; - - // Remove a user social account - $scope.removeUserSocialAccount = function(provider) { - $scope.success = $scope.error = null; - - $http.delete('/users/accounts', { - params: { - provider: provider - } - }).success(function(response) { - // If successful show success message and clear form - $scope.success = true; - $scope.error = null; - $scope.user = response; - }).error(function(response) { - $scope.success = null; - $scope.error = response.message; - }); - }; + } // Update a user profile $scope.updateUserProfile = function(isValid) { @@ -51,6 +19,7 @@ angular.module('users').controller('SettingsController', ['$scope', '$rootScope' $scope.success = true; $scope.error = null; $scope.user = response; + $scope.$apply(); }, function(response) { $scope.success = null; $scope.error = response.data.message; @@ -59,21 +28,5 @@ angular.module('users').controller('SettingsController', ['$scope', '$rootScope' $scope.submitted = true; } }; - - // Change user password - $scope.changeUserPassword = function() { - $scope.success = $scope.error = null; - - $http.post('/users/password', $scope.passwordDetails).success(function(response) { - // If successful show success message and clear form - $scope.success = true; - $scope.error = null; - $scope.passwordDetails = null; - }).error(function(response) { - $scope.success = null; - $scope.error = response.message; - }); - }; - } ]); diff --git a/public/modules/users/views/settings/change-password.client.view.html b/public/modules/users/views/settings/change-password.client.view.html index 3a8565fa..cd039916 100755 --- a/public/modules/users/views/settings/change-password.client.view.html +++ b/public/modules/users/views/settings/change-password.client.view.html @@ -1,6 +1,6 @@
-
+

{{ 'CHANGE_PASSWORD' | translate }}