1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-30 02:39:41 +02:00

feat(authentication): add a --no-auth flag to disable authentication (#553)

This commit is contained in:
Anthony Lapenna 2017-02-01 22:13:48 +13:00 committed by GitHub
parent 779fcf8e7f
commit 10f7744a62
16 changed files with 203 additions and 191 deletions

View file

@ -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;
}
};
}]);