ember-auth-rails 3.7.0 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,26 +22,24 @@
22
22
  }
23
23
  return this.ajax(this.resolveUrl(Auth.Config.get('tokenCreateUrl')), 'POST', {
24
24
  data: data,
25
- async: async,
26
- success: function(json, status, jqxhr) {
27
- var model;
28
- _this.set('authToken', json[Auth.Config.get('tokenKey')]);
29
- _this.set('currentUserId', json[Auth.Config.get('idKey')]);
30
- if (model = Auth.Config.get('userModel')) {
31
- _this.set('currentUser', model.find(_this.get('currentUserId')));
32
- }
33
- _this.set('jqxhr', jqxhr);
34
- return _this.trigger('signInSuccess');
35
- },
36
- error: function(jqxhr) {
37
- _this.set('jqxhr', jqxhr);
38
- return _this.trigger('signInError');
39
- },
40
- complete: function(jqxhr) {
41
- _this.set('prevRoute', null);
42
- _this.set('jqxhr', jqxhr);
43
- return _this.trigger('signInComplete');
25
+ async: async
26
+ }).done(function(json, status, jqxhr) {
27
+ var model;
28
+ _this.set('authToken', json[Auth.Config.get('tokenKey')]);
29
+ _this.set('currentUserId', json[Auth.Config.get('idKey')]);
30
+ if (model = Auth.Config.get('userModel')) {
31
+ _this.set('currentUser', model.find(_this.get('currentUserId')));
44
32
  }
33
+ _this.set('json', json);
34
+ _this.set('jqxhr', jqxhr);
35
+ return _this.trigger('signInSuccess');
36
+ }).fail(function(jqxhr) {
37
+ _this.set('jqxhr', jqxhr);
38
+ return _this.trigger('signInError');
39
+ }).always(function(jqxhr) {
40
+ _this.set('prevRoute', null);
41
+ _this.set('jqxhr', jqxhr);
42
+ return _this.trigger('signInComplete');
45
43
  });
46
44
  },
47
45
  signOut: function(data) {
@@ -57,23 +55,20 @@
57
55
  }
58
56
  return this.ajax(this.resolveUrl(Auth.Config.get('tokenDestroyUrl')), 'DELETE', {
59
57
  data: data,
60
- async: async,
61
- success: function(json, status, jqxhr) {
62
- _this.set('authToken', null);
63
- _this.set('currentUserId', null);
64
- _this.set('currentUser', null);
65
- _this.set('jqxhr', jqxhr);
66
- return _this.trigger('signOutSuccess');
67
- },
68
- error: function(jqxhr) {
69
- _this.set('jqxhr', jqxhr);
70
- return _this.trigger('signOutError');
71
- },
72
- complete: function(jqxhr) {
73
- _this.set('prevRoute', null);
74
- _this.set('jqxhr', jqxhr);
75
- return _this.trigger('signOutComplete');
76
- }
58
+ async: async
59
+ }).done(function(json, status, jqxhr) {
60
+ _this.set('authToken', null);
61
+ _this.set('currentUserId', null);
62
+ _this.set('currentUser', null);
63
+ _this.set('jqxhr', jqxhr);
64
+ return _this.trigger('signOutSuccess');
65
+ }).fail(function(jqxhr) {
66
+ _this.set('jqxhr', jqxhr);
67
+ return _this.trigger('signOutError');
68
+ }).always(function(jqxhr) {
69
+ _this.set('prevRoute', null);
70
+ _this.set('jqxhr', jqxhr);
71
+ return _this.trigger('signOutComplete');
77
72
  });
78
73
  },
79
74
  resolveUrl: function(path) {
@@ -108,8 +103,13 @@
108
103
  ajax: function(url, type, hash) {
109
104
  var token;
110
105
  if (token = this.get('authToken')) {
111
- hash.data || (hash.data = {});
112
- hash.data[Auth.Config.get('tokenKey')] = this.get('authToken');
106
+ if (Auth.Config.get('requestHeaderAuthorization')) {
107
+ hash.headers || (hash.headers = {});
108
+ hash.headers[Auth.Config.get('requestHeaderKey')] = this.get('authToken');
109
+ } else {
110
+ hash.data || (hash.data = {});
111
+ hash.data[Auth.Config.get('tokenKey')] = this.get('authToken');
112
+ }
113
113
  }
114
114
  hash.url = url;
115
115
  hash.type = type;
@@ -129,6 +129,8 @@
129
129
  idKey: null,
130
130
  userModel: null,
131
131
  baseUrl: null,
132
+ requestHeaderAuthorization: false,
133
+ requestHeaderKey: null,
132
134
  signInRoute: null,
133
135
  signOutRoute: null,
134
136
  authRedirect: false,
@@ -139,7 +141,8 @@
139
141
  rememberMe: false,
140
142
  rememberTokenKey: null,
141
143
  rememberPeriod: 14,
142
- rememberAutoRecall: true
144
+ rememberAutoRecall: true,
145
+ rememberUsingLocalStorage: false
143
146
  });
144
147
 
145
148
  Auth.Route = Em.Route.extend(Em.Evented, {
@@ -208,7 +211,7 @@
208
211
  if (!Auth.Config.get('rememberMe')) {
209
212
  return;
210
213
  }
211
- if (!Auth.get('authToken') && (token = $.cookie('ember-auth-remember-me'))) {
214
+ if (!Auth.get('authToken') && (token = this.retrieveToken())) {
212
215
  data = {};
213
216
  if (opts.async != null) {
214
217
  data['async'] = opts.async;
@@ -218,33 +221,59 @@
218
221
  }
219
222
  },
220
223
  remember: function() {
221
- var curToken, json, token;
224
+ var token;
222
225
  if (!Auth.Config.get('rememberMe')) {
223
226
  return;
224
227
  }
225
- json = JSON.parse((Auth.get('jqxhr')).responseText);
226
- token = json[Auth.Config.get('rememberTokenKey')];
227
- curToken = $.cookie('ember-auth-remember-me');
228
- if (token && token !== curToken) {
229
- return $.cookie('ember-auth-remember-me', token, {
230
- expires: Auth.Config.get('rememberPeriod')
231
- });
228
+ token = Auth.get('json')[Auth.Config.get('rememberTokenKey')];
229
+ if (token && token !== this.retrieveToken()) {
230
+ return this.storeToken(token);
232
231
  }
233
232
  },
234
233
  forget: function() {
235
234
  if (!Auth.Config.get('rememberMe')) {
236
235
  return;
237
236
  }
238
- return $.removeCookie('ember-auth-remember-me');
237
+ return this.removeToken();
238
+ },
239
+ retrieveToken: function() {
240
+ if (Auth.Config.get('rememberUsingLocalStorage')) {
241
+ return localStorage.getItem('ember-auth-remember-me');
242
+ } else {
243
+ return $.cookie('ember-auth-remember-me');
244
+ }
245
+ },
246
+ storeToken: function(token) {
247
+ if (Auth.Config.get('rememberUsingLocalStorage')) {
248
+ return localStorage.setItem('ember-auth-remember-me', token);
249
+ } else {
250
+ return $.cookie('ember-auth-remember-me', token, {
251
+ expires: Auth.Config.get('rememberPeriod')
252
+ });
253
+ }
254
+ },
255
+ removeToken: function() {
256
+ if (Auth.Config.get('rememberUsingLocalStorage')) {
257
+ return localStorage.removeItem('ember-auth-remember-me');
258
+ } else {
259
+ return $.removeCookie('ember-auth-remember-me');
260
+ }
239
261
  }
240
262
  });
241
263
 
242
264
  Auth.Route.reopen({
243
265
  redirect: function() {
266
+ var callback, request, self;
244
267
  if (Auth.Config.get('rememberMe') && Auth.Config.get('rememberAutoRecall')) {
245
- Auth.Module.RememberMe.recall({
268
+ if (request = Auth.Module.RememberMe.recall({
246
269
  async: false
247
- });
270
+ })) {
271
+ self = this;
272
+ callback = this._super;
273
+ return request.always(function() {
274
+ return callback.call(self);
275
+ });
276
+ }
248
277
  }
249
278
  return this._super();
250
279
  }
@@ -1,5 +1,5 @@
1
1
  module EmberAuth
2
2
  module Rails
3
- VERSION = '3.7.0'
3
+ VERSION = '3.8.0'
4
4
  end
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module EmberAuth
2
- VERSION = '2.5.0'
2
+ VERSION = '2.6.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ember-auth-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-02 00:00:00.000000000 Z
12
+ date: 2013-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ember-rails