Files
meanTorrent/modules/users/client/controllers/authentication.client.controller.js
Ryan Hutchison ef3a3f9548 formatting reboot (space-2 and consistency)
JSCS fixes

update editorconfig
2015-07-31 10:04:02 -04:00

52 lines
1.8 KiB
JavaScript

'use strict';
angular.module('users').controller('AuthenticationController', ['$scope', '$state', '$http', '$location', '$window', 'Authentication',
function ($scope, $state, $http, $location, $window, Authentication) {
$scope.authentication = Authentication;
// Get an eventual error defined in the URL query string:
$scope.error = $location.search().err;
// If user is signed in then redirect back home
if ($scope.authentication.user) {
$location.path('/');
}
$scope.signup = function () {
$http.post('/api/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 previous or home page
$state.go($state.previous.state.name || 'home', $state.previous.params);
}).error(function (response) {
$scope.error = response.message;
});
};
$scope.signin = function () {
$http.post('/api/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 previous or home page
$state.go($state.previous.state.name || 'home', $state.previous.params);
}).error(function (response) {
$scope.error = response.message;
});
};
// OAuth provider request
$scope.callOauthProvider = function (url) {
var redirect_to;
if ($state.previous) {
redirect_to = $state.previous.href;
}
// Effectively call OAuth authentication route:
$window.location.href = url + (redirect_to ? '?redirect_to=' + encodeURIComponent(redirect_to) : '');
};
}
]);