Files
meanTorrent/modules/users/client/controllers/settings.client.controller.js

28 lines
743 B
JavaScript
Raw Normal View History

2014-03-26 01:30:58 +02:00
'use strict';
2014-04-02 19:34:32 +03:00
angular.module('users').controller('SettingsController', ['$scope', '$http', '$location', 'Users', 'Authentication',
2014-05-20 18:22:38 +03:00
function($scope, $http, $location, Users, Authentication) {
$scope.user = Authentication.user;
2014-03-26 01:30:58 +02:00
2014-05-20 18:22:38 +03:00
// If user is not signed in then redirect back home
if (!$scope.user) $location.path('/');
2014-03-26 01:30:58 +02:00
2014-05-20 18:22:38 +03:00
// Update a user profile
2014-06-05 22:32:32 -07:00
$scope.updateUserProfile = function(isValid) {
2014-11-10 23:12:33 +02:00
if (isValid){
2014-06-05 22:32:32 -07:00
$scope.success = $scope.error = null;
var user = new Users($scope.user);
2014-11-10 23:12:33 +02:00
2014-06-05 22:32:32 -07:00
user.$update(function(response) {
$scope.success = true;
Authentication.user = response;
}, function(response) {
$scope.error = response.data.message;
});
} else {
$scope.submitted = true;
}
2014-05-20 18:22:38 +03:00
};
}
2014-11-10 23:12:33 +02:00
]);