2014-02-10 13:09:31 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
2014-08-02 21:29:38 +03:00
|
|
|
angular.module('users').controller('AuthenticationController', ['$scope', '$http', '$location', 'Authentication',
|
|
|
|
|
function($scope, $http, $location, Authentication) {
|
2014-07-31 11:27:14 +03:00
|
|
|
$scope.authentication = Authentication;
|
2014-02-10 13:09:31 +02:00
|
|
|
|
2014-07-31 11:27:14 +03:00
|
|
|
// If user is signed in then redirect back home
|
2014-05-20 18:22:38 +03:00
|
|
|
if ($scope.authentication.user) $location.path('/');
|
2014-03-26 01:11:24 +02:00
|
|
|
|
2014-08-02 21:29:38 +03:00
|
|
|
$scope.signup = function() {
|
2014-11-10 23:12:33 +02:00
|
|
|
$http.post('/api/auth/signup', $scope.credentials).success(function(response) {
|
2014-08-02 21:29:38 +03:00
|
|
|
// If successful we assign the response to the global user model
|
|
|
|
|
$scope.authentication.user = response;
|
2014-07-31 11:27:14 +03:00
|
|
|
|
2014-08-02 21:29:38 +03:00
|
|
|
// And redirect to the index page
|
|
|
|
|
$location.path('/');
|
|
|
|
|
}).error(function(response) {
|
|
|
|
|
$scope.error = response.message;
|
|
|
|
|
});
|
2014-05-20 18:22:38 +03:00
|
|
|
};
|
2014-02-10 13:09:31 +02:00
|
|
|
|
2014-05-20 18:22:38 +03:00
|
|
|
$scope.signin = function() {
|
2014-11-10 23:12:33 +02:00
|
|
|
$http.post('/api/auth/signin', $scope.credentials).success(function(response) {
|
2014-07-31 11:27:14 +03:00
|
|
|
// If successful we assign the response to the global user model
|
2014-05-20 18:22:38 +03:00
|
|
|
$scope.authentication.user = response;
|
2014-02-10 13:09:31 +02:00
|
|
|
|
2014-07-31 11:27:14 +03:00
|
|
|
// And redirect to the index page
|
|
|
|
|
$location.path('/');
|
|
|
|
|
}).error(function(response) {
|
|
|
|
|
$scope.error = response.message;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
2015-02-16 21:35:33 +01:00
|
|
|
]);
|