You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cache.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Created by robin on 11/1/15.
  3. */
  4. (function () {
  5. 'use strict';
  6. angular.module('luticateAuth')
  7. .factory('luticateAuthCache', ['localStorageService', function (localStorageService) {
  8. var luticateAuthCache = {};
  9. luticateAuthCache.setUser = function(user)
  10. {
  11. localStorageService.set('lu_user', user);
  12. };
  13. luticateAuthCache.getUser = function()
  14. {
  15. return localStorageService.get('lu_user');
  16. };
  17. luticateAuthCache.getToken = function()
  18. {
  19. var user = luticateAuthCache.getUser();
  20. if (user == null) {
  21. return null;
  22. }
  23. return user.Token;
  24. };
  25. luticateAuthCache.removeUser = function()
  26. {
  27. localStorageService.remove('lu_user');
  28. luticateAuthCache.removeEffectivePermissions();
  29. };
  30. luticateAuthCache.setEffectivePermissions = function(permissions)
  31. {
  32. localStorageService.set('lu_effective_permissions', permissions);
  33. };
  34. luticateAuthCache.getEffectivePermissions = function()
  35. {
  36. return localStorageService.get('lu_effective_permissions');
  37. };
  38. luticateAuthCache.hasEffectivePermissions = function(permission_name)
  39. {
  40. var permissions = luticateAuthCache.getEffectivePermissions();
  41. if (permissions == null) {
  42. return null;
  43. }
  44. var value = permissions[permission_name];
  45. return value == null ? null : value;
  46. };
  47. luticateAuthCache.removeEffectivePermissions = function()
  48. {
  49. localStorageService.remove('lu_effective_permissions');
  50. };
  51. return luticateAuthCache;
  52. }]);
  53. })();