Last active
December 19, 2015 23:09
-
-
Save fnakstad/6032902 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('angular-client-side-auth') | |
.factory('Auth', function($http, $rootScope, $cookieStore){ | |
// ... | |
$rootScope.accessLevels = accessLevels; | |
$rootScope.userRoles = userRoles; | |
return { | |
authorize: function(accessLevel, role) { | |
if(role === undefined) | |
role = $rootScope.user.role; | |
return accessLevel & role; | |
}, | |
isLoggedIn: function(user) { | |
if(user === undefined) | |
user = $rootScope.user; | |
return user.role === userRoles.user || user.role === userRoles.admin; | |
}, | |
register: function(user, success, error) { | |
$http.post('/register', user).success(success).error(error); | |
}, | |
login: function(user, success, error) { | |
$http.post('/login', user).success(function(user){ | |
$rootScope.user = user; | |
success(user); | |
}).error(error); | |
}, | |
logout: function(success, error) { | |
$http.post('/logout').success(function(){ | |
$rootScope.user = { | |
username = '', | |
role = userRoles.public | |
}; | |
success(); | |
}).error(error); | |
}, | |
accessLevels: accessLevels, | |
userRoles: userRoles | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI, line 36 and 37 do not correctly set object properties, should be
:
instead of=