Files
meanTorrent/public/modules/users/controllers/authentication.client.controller.js
2014-07-31 11:27:14 +03:00

38 lines
1.2 KiB
JavaScript

'use strict';
angular.module('users').controller('AuthenticationController', ['$scope', '$stateParams', '$http', '$location', 'Authentication',
function($scope, $stateParams, $http, $location, Authentication) {
$scope.authentication = Authentication;
// If user is signed in then redirect back home
if ($scope.authentication.user) $location.path('/');
$scope.signup = function(isValid) {
if (isValid) {
$http.post('/auth/signup', $scope.credentials).success(function(response) {
// If successful we assign the response to the global user model
$scope.authentication.user = response;
// And redirect to the index page
$location.path('/');
}).error(function(response) {
$scope.error = response.message;
});
} else {
$scope.submitted = true;
}
};
$scope.signin = function() {
$http.post('/auth/signin', $scope.credentials).success(function(response) {
// If successful we assign the response to the global user model
$scope.authentication.user = response;
// And redirect to the index page
$location.path('/');
}).error(function(response) {
$scope.error = response.message;
});
};
}
]);