mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 05:45:22 +02:00
feat(authentication): add a --no-auth flag to disable authentication (#553)
This commit is contained in:
parent
779fcf8e7f
commit
10f7744a62
16 changed files with 203 additions and 191 deletions
|
@ -1,12 +1,14 @@
|
|||
angular.module('portainer.services')
|
||||
.factory('Authentication', ['$q', '$rootScope', 'Auth', 'jwtHelper', 'LocalStorage', 'StateManager', function AuthenticationFactory($q, $rootScope, Auth, jwtHelper, LocalStorage, StateManager) {
|
||||
.factory('Authentication', ['$q', 'Auth', 'jwtHelper', 'LocalStorage', 'StateManager', function AuthenticationFactory($q, Auth, jwtHelper, LocalStorage, StateManager) {
|
||||
'use strict';
|
||||
|
||||
var credentials = {};
|
||||
return {
|
||||
init: function() {
|
||||
var jwt = LocalStorage.getJWT();
|
||||
if (jwt) {
|
||||
var tokenPayload = jwtHelper.decodeToken(jwt);
|
||||
$rootScope.username = tokenPayload.username;
|
||||
credentials.username = tokenPayload.username;
|
||||
}
|
||||
},
|
||||
login: function(username, password) {
|
||||
|
@ -14,7 +16,7 @@ angular.module('portainer.services')
|
|||
Auth.login({username: username, password: password}).$promise
|
||||
.then(function(data) {
|
||||
LocalStorage.storeJWT(data.jwt);
|
||||
$rootScope.username = username;
|
||||
credentials.username = username;
|
||||
resolve();
|
||||
}, function() {
|
||||
reject();
|
||||
|
@ -28,6 +30,9 @@ angular.module('portainer.services')
|
|||
isAuthenticated: function() {
|
||||
var jwt = LocalStorage.getJWT();
|
||||
return jwt && !jwtHelper.isTokenExpired(jwt);
|
||||
},
|
||||
getCredentials: function() {
|
||||
return credentials;
|
||||
}
|
||||
};
|
||||
}]);
|
||||
|
|
|
@ -8,6 +8,12 @@ angular.module('portainer.services')
|
|||
getEndpointState: function() {
|
||||
return localStorageService.get('ENDPOINT_STATE');
|
||||
},
|
||||
storeApplicationState: function(state) {
|
||||
localStorageService.set('APPLICATION_STATE', state);
|
||||
},
|
||||
getApplicationState: function() {
|
||||
return localStorageService.get('APPLICATION_STATE');
|
||||
},
|
||||
storeJWT: function(jwt) {
|
||||
localStorageService.set('JWT', jwt);
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
angular.module('portainer.services')
|
||||
.factory('StateManager', ['$q', 'Info', 'InfoHelper', 'Version', 'LocalStorage', function StateManagerFactory($q, Info, InfoHelper, Version, LocalStorage) {
|
||||
.factory('StateManager', ['$q', 'Config', 'Info', 'InfoHelper', 'Version', 'LocalStorage', function StateManagerFactory($q, Config, Info, InfoHelper, Version, LocalStorage) {
|
||||
'use strict';
|
||||
|
||||
var state = {
|
||||
|
@ -9,12 +9,31 @@ angular.module('portainer.services')
|
|||
};
|
||||
|
||||
return {
|
||||
init: function() {
|
||||
initialize: function() {
|
||||
var endpointState = LocalStorage.getEndpointState();
|
||||
if (endpointState) {
|
||||
state.endpoint = endpointState;
|
||||
}
|
||||
state.loading = false;
|
||||
|
||||
var deferred = $q.defer();
|
||||
var applicationState = LocalStorage.getApplicationState();
|
||||
if (applicationState) {
|
||||
state.application = applicationState;
|
||||
state.loading = false;
|
||||
deferred.resolve(state);
|
||||
} else {
|
||||
Config.$promise.then(function success(data) {
|
||||
state.application.authentication = data.authentication;
|
||||
state.application.logo = data.logo;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
state.loading = false;
|
||||
deferred.resolve(state);
|
||||
}, function error(err) {
|
||||
state.loading = false;
|
||||
deferred.reject({msg: 'Unable to retrieve server configuration', err: err});
|
||||
});
|
||||
}
|
||||
return deferred.promise;
|
||||
},
|
||||
clean: function() {
|
||||
state.endpoint = {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue