|
5 | 5 | .module('app') |
6 | 6 | .factory('AuthenticationService', AuthenticationService); |
7 | 7 |
|
8 | | - AuthenticationService.$inject = ['$http', '$cookieStore', '$rootScope', '$timeout', 'UserService']; |
9 | | - function AuthenticationService($http, $cookieStore, $rootScope, $timeout, UserService) { |
| 8 | + AuthenticationService.$inject = ['$http', '$cookies', '$rootScope', '$timeout', 'UserService']; |
| 9 | + function AuthenticationService($http, $cookies, $rootScope, $timeout, UserService) { |
10 | 10 | var service = {}; |
11 | 11 |
|
12 | 12 | service.Login = Login; |
|
51 | 51 | } |
52 | 52 | }; |
53 | 53 |
|
54 | | - $http.defaults.headers.common['Authorization'] = 'Basic ' + authdata; // jshint ignore:line |
55 | | - $cookieStore.put('globals', $rootScope.globals); |
| 54 | + // set default auth header for http requests |
| 55 | + $http.defaults.headers.common['Authorization'] = 'Basic ' + authdata; |
| 56 | + |
| 57 | + // store user details in globals cookie that keeps user logged in for 1 week (or until they logout) |
| 58 | + var cookieExp = new Date(); |
| 59 | + cookieExp.setDate(cookieExp.getDate() + 7); |
| 60 | + $cookies.putObject('globals', $rootScope.globals, { expires: cookieExp }); |
56 | 61 | } |
57 | 62 |
|
58 | 63 | function ClearCredentials() { |
59 | 64 | $rootScope.globals = {}; |
60 | | - $cookieStore.remove('globals'); |
| 65 | + $cookies.remove('globals'); |
61 | 66 | $http.defaults.headers.common.Authorization = 'Basic'; |
62 | 67 | } |
63 | 68 | } |
|
0 commit comments