fixed reloading bug for settings pages

This commit is contained in:
David Baldwynn 2017-10-28 01:17:43 -07:00
parent 3b9f01f92a
commit eaef327b37
4 changed files with 41 additions and 60 deletions

View file

@ -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});
return;
});
}
return deferred.promise;
};
var checkSignupDisabled = function($window, $timeout, $q) {

View file

@ -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;
});
};
*/
}
]);

View file

@ -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;
});
};
}
]);

View file

@ -1,6 +1,6 @@
<header data-ng-include="'/static/modules/core/views/header.client.view.html'"></header>
<section class="row" data-ng-controller="SettingsController">
<section class="row" data-ng-controller="ChangePasswordController">
<h3 class="col-md-12 text-center">{{ 'CHANGE_PASSWORD' | translate }}</h3>
<div class="col-xs-offset-2 col-xs-8 col-md-offset-3 col-md-6">
<form data-ng-submit="changeUserPassword()" class="signin form-horizontal" autocomplete="off">