Files
meanTorrent/public/modules/users/controllers/authentication.client.controller.js

34 lines
1.0 KiB
JavaScript
Raw Normal View History

2014-02-10 13:09:31 +02:00
'use strict';
2014-04-02 19:34:32 +03:00
angular.module('users').controller('AuthenticationController', ['$scope', '$http', '$location', 'Authentication',
2014-05-20 18:22:38 +03:00
function($scope, $http, $location, Authentication) {
$scope.authentication = Authentication;
2014-02-10 13:09:31 +02:00
2014-05-20 18:22:38 +03:00
//If user is signed in then redirect back home
if ($scope.authentication.user) $location.path('/');
2014-03-26 01:11:24 +02:00
2014-05-20 18:22:38 +03:00
$scope.signup = function() {
$http.post('/auth/signup', $scope.credentials).success(function(response) {
//If successful we assign the response to the global user model
$scope.authentication.user = response;
2014-02-10 13:09:31 +02:00
2014-05-20 18:22:38 +03:00
//And redirect to the index page
$location.path('/');
}).error(function(response) {
$scope.error = response.message;
});
};
2014-02-10 13:09:31 +02:00
2014-05-20 18:22:38 +03:00
$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;
2014-02-10 13:09:31 +02:00
2014-05-20 18:22:38 +03:00
//And redirect to the index page
$location.path('/');
}).error(function(response) {
$scope.error = response.message;
});
};
}
]);