2014-11-10 23:12:33 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('users').controller('EditProfileController', ['$scope', '$http', '$location', 'Users', 'Authentication',
|
2015-07-25 16:53:11 -04:00
|
|
|
function ($scope, $http, $location, Users, Authentication) {
|
|
|
|
|
$scope.user = Authentication.user;
|
2014-11-10 23:12:33 +02:00
|
|
|
|
2015-07-25 16:53:11 -04:00
|
|
|
// Update a user profile
|
|
|
|
|
$scope.updateUserProfile = function (isValid) {
|
2015-08-05 00:40:54 -04:00
|
|
|
$scope.success = $scope.error = null;
|
2014-11-10 23:12:33 +02:00
|
|
|
|
2015-08-05 00:40:54 -04:00
|
|
|
if (!isValid) {
|
|
|
|
|
$scope.$broadcast('show-errors-check-validity', 'userForm');
|
|
|
|
|
|
|
|
|
|
return false;
|
2015-07-25 16:53:11 -04:00
|
|
|
}
|
2015-08-05 00:40:54 -04:00
|
|
|
|
|
|
|
|
var user = new Users($scope.user);
|
|
|
|
|
|
|
|
|
|
user.$update(function (response) {
|
|
|
|
|
$scope.$broadcast('show-errors-reset', 'userForm');
|
|
|
|
|
|
|
|
|
|
$scope.success = true;
|
|
|
|
|
Authentication.user = response;
|
|
|
|
|
}, function (response) {
|
|
|
|
|
$scope.error = response.data.message;
|
|
|
|
|
});
|
2015-07-25 16:53:11 -04:00
|
|
|
};
|
|
|
|
|
}
|
2014-11-10 23:12:33 +02:00
|
|
|
]);
|