2016-12-15 03:33:47 +00:00
|
|
|
angular.module('auth', [])
|
2017-01-22 23:14:34 +00:00
|
|
|
.controller('AuthenticationController', ['$scope', '$state', '$stateParams', '$window', '$timeout', '$sanitize', 'Config', 'Authentication', 'Users', 'EndpointService', 'StateManager', 'Messages',
|
|
|
|
function ($scope, $state, $stateParams, $window, $timeout, $sanitize, Config, Authentication, Users, EndpointService, StateManager, Messages) {
|
2016-12-15 03:33:47 +00:00
|
|
|
|
|
|
|
$scope.authData = {
|
|
|
|
username: 'admin',
|
|
|
|
password: '',
|
|
|
|
error: ''
|
|
|
|
};
|
|
|
|
$scope.initPasswordData = {
|
|
|
|
password: '',
|
|
|
|
password_confirmation: '',
|
|
|
|
error: false
|
|
|
|
};
|
|
|
|
|
2017-02-01 09:13:48 +00:00
|
|
|
if (!$scope.applicationState.application.authentication) {
|
|
|
|
EndpointService.getActive().then(function success(data) {
|
|
|
|
StateManager.updateEndpointState(true)
|
|
|
|
.then(function success() {
|
|
|
|
$state.go('dashboard');
|
|
|
|
}, function error(err) {
|
|
|
|
Messages.error("Failure", err, 'Unable to connect to the Docker endpoint');
|
|
|
|
});
|
|
|
|
}, function error(err) {
|
|
|
|
if (err.status === 404) {
|
|
|
|
$state.go('endpointInit');
|
|
|
|
} else {
|
|
|
|
Messages.error("Failure", err, 'Unable to verify Docker endpoint existence');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-15 03:33:47 +00:00
|
|
|
if ($stateParams.logout) {
|
|
|
|
Authentication.logout();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($stateParams.error) {
|
|
|
|
$scope.authData.error = $stateParams.error;
|
|
|
|
Authentication.logout();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Authentication.isAuthenticated()) {
|
|
|
|
$state.go('dashboard');
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.$promise.then(function (c) {
|
|
|
|
$scope.logo = c.logo;
|
|
|
|
});
|
|
|
|
|
|
|
|
Users.checkAdminUser({}, function (d) {},
|
|
|
|
function (e) {
|
|
|
|
if (e.status === 404) {
|
|
|
|
$scope.initPassword = true;
|
|
|
|
} else {
|
|
|
|
Messages.error("Failure", e, 'Unable to verify administrator account existence');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.createAdminUser = function() {
|
|
|
|
var password = $sanitize($scope.initPasswordData.password);
|
|
|
|
Users.initAdminUser({password: password}, function (d) {
|
|
|
|
$scope.initPassword = false;
|
|
|
|
$timeout(function() {
|
|
|
|
var element = $window.document.getElementById('password');
|
|
|
|
if(element) {
|
|
|
|
element.focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, function (e) {
|
|
|
|
$scope.initPassword.error = true;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.authenticateUser = function() {
|
|
|
|
$scope.authenticationError = false;
|
|
|
|
var username = $sanitize($scope.authData.username);
|
|
|
|
var password = $sanitize($scope.authData.password);
|
2016-12-25 20:34:02 +00:00
|
|
|
Authentication.login(username, password).then(function success() {
|
|
|
|
EndpointService.getActive().then(function success(data) {
|
2017-01-22 23:14:34 +00:00
|
|
|
StateManager.updateEndpointState(true)
|
|
|
|
.then(function success() {
|
|
|
|
$state.go('dashboard');
|
|
|
|
}, function error(err) {
|
|
|
|
Messages.error("Failure", err, 'Unable to connect to the Docker endpoint');
|
|
|
|
});
|
2016-12-25 20:34:02 +00:00
|
|
|
}, function error(err) {
|
|
|
|
if (err.status === 404) {
|
|
|
|
$state.go('endpointInit');
|
|
|
|
} else {
|
|
|
|
Messages.error("Failure", err, 'Unable to verify Docker endpoint existence');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, function error() {
|
2016-12-15 03:33:47 +00:00
|
|
|
$scope.authData.error = 'Invalid credentials';
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}]);
|