1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-05 16:24:21 +01:00
fab-manager/app/assets/javascripts/services/auth.js.erb

19 lines
528 B
Plaintext

'use strict';
Application.Services.factory('AuthService', ['Session', 'CSRF', function (Session, CSRF) {
let service = {};
service.isAuthenticated = function() {
return (Session.currentUser != null) && (Session.currentUser.id != null);
};
service.isAuthorized = function(authorizedRoles) {
if (!angular.isArray(authorizedRoles)) {
authorizedRoles = [authorizedRoles];
}
return service.isAuthenticated() && (authorizedRoles.indexOf(Session.currentUser.role) !== -1);
};
return service;
}]);