added sample app for client-server authentication
This commit is contained in:
55
client/js/directives.js
Executable file
55
client/js/directives.js
Executable file
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('angular-client-side-auth')
|
||||
.directive('accessLevel', ['Auth', function(Auth) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: function($scope, element, attrs) {
|
||||
var prevDisp = element.css('display')
|
||||
, userRole
|
||||
, accessLevel;
|
||||
|
||||
$scope.user = Auth.user;
|
||||
$scope.$watch('user', function(user) {
|
||||
if(user.role)
|
||||
userRole = user.role;
|
||||
updateCSS();
|
||||
}, true);
|
||||
|
||||
attrs.$observe('accessLevel', function(al) {
|
||||
if(al) accessLevel = $scope.$eval(al);
|
||||
updateCSS();
|
||||
});
|
||||
|
||||
function updateCSS() {
|
||||
if(userRole && accessLevel) {
|
||||
if(!Auth.authorize(accessLevel, userRole))
|
||||
element.css('display', 'none');
|
||||
else
|
||||
element.css('display', prevDisp);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}]);
|
||||
|
||||
angular.module('angular-client-side-auth').directive('activeNav', ['$location', function($location) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: function(scope, element, attrs) {
|
||||
var nestedA = element.find('a')[0];
|
||||
var path = nestedA.href;
|
||||
|
||||
scope.location = $location;
|
||||
scope.$watch('location.absUrl()', function(newPath) {
|
||||
if (path === newPath) {
|
||||
element.addClass('active');
|
||||
} else {
|
||||
element.removeClass('active');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}]);
|
Reference in New Issue
Block a user