Advertisement
lidia_defreitas

Untitled

Dec 11th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. (function () {
  2. 'use strict';
  3.  
  4. angular
  5. .module('nBlogsApplicationApp')
  6. .factory('authToken', authToken);
  7.  
  8. function authToken($window) {
  9. var service = {
  10. setToken: setToken,
  11. getToken: getToken,
  12. isAuthenticated: isAuthenticated,
  13. removeToken: removeToken
  14. };
  15.  
  16. return service;
  17.  
  18. function setToken(token) {
  19. $window.localStorage.setItem('userToken', token);
  20. }
  21.  
  22. function getToken() {
  23. return $window.localStorage.getItem('userToken');
  24. }
  25.  
  26. function isAuthenticated() {
  27. return !!authToken.getToken();
  28. }
  29.  
  30. function removeToken() {
  31. $window.localStorage.removeItem('userToken');
  32. }
  33. }
  34. })();
  35.  
  36. (function () {
  37. angular
  38. .module('nBlogsApplicationApp')
  39. .run(appRun);
  40.  
  41. function appRun(Restangular, authToken) {
  42. authToken.setToken('ZmVtYWxlOmZlbWFsZQ==');
  43. Restangular.setDefaultHeaders(
  44. {
  45. 'Authorization': 'Basic ' + authToken.getToken() + '',
  46. 'Prefer': 'status=422'
  47. }
  48. );
  49. }
  50.  
  51. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement