tellform/public/modules/users/controllers/settings.client.controller.js

68 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-06-29 22:51:29 +00:00
'use strict';
2015-07-07 01:21:43 +00:00
angular.module('users').controller('SettingsController', ['$scope', '$rootScope', '$http', '$state', 'Users',
function($scope, $rootScope, $http, $state, Users) {
$scope.user = $rootScope.user;
2015-06-29 22:51:29 +00:00
// Check if there are additional accounts
$scope.hasConnectedAdditionalSocialAccounts = function(provider) {
for (var i in $scope.user.additionalProvidersData) {
return true;
}
return false;
};
// 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]);
};
2015-06-29 22:51:29 +00:00
// Remove a user social account
$scope.removeUserSocialAccount = function(provider) {
$scope.success = $scope.error = null;
2015-06-29 22:51:29 +00:00
$http.delete('/users/accounts', {
params: {
provider: provider
}
}).success(function(response) {
// If successful show success message and clear form
$scope.success = true;
$scope.user = response;
}).error(function(response) {
$scope.error = response.message;
});
};
2015-06-29 22:51:29 +00:00
// Update a user profile
$scope.updateUserProfile = function(isValid) {
if (isValid) {
2015-06-29 22:51:29 +00:00
$scope.success = $scope.error = null;
var user = new Users($scope.user);
2015-06-29 22:51:29 +00:00
user.$update(function(response) {
2015-06-29 22:51:29 +00:00
$scope.success = true;
$scope.user = response;
}, function(response) {
$scope.error = response.data.message;
2015-06-29 22:51:29 +00:00
});
} else {
$scope.submitted = true;
}
};
2015-06-29 22:51:29 +00:00
// Change user password
$scope.changeUserPassword = function() {
$scope.success = $scope.error = null;
2015-06-29 22:51:29 +00:00
$http.post('/users/password', $scope.passwordDetails).success(function(response) {
// If successful show success message and clear form
$scope.success = true;
$scope.passwordDetails = null;
}).error(function(response) {
$scope.error = response.message;
});
};
2015-06-29 22:51:29 +00:00
}
]);