ember-auth-rails 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,13 @@
1
1
  // Generated by CoffeeScript 1.4.0
2
2
  (function() {
3
+ var evented;
3
4
 
4
- window.Auth = Em.Object.create({
5
+ evented = Em.Object.extend(Em.Evented);
6
+
7
+ window.Auth = evented.create({
5
8
  authToken: null,
6
9
  currentUserId: null,
7
- error: null,
10
+ jqxhr: null,
8
11
  prevRoute: null,
9
12
  signIn: function(data) {
10
13
  var _this = this;
@@ -13,15 +16,20 @@
13
16
  }
14
17
  return this.ajax(this.resolveUrl(Auth.Config.get('tokenCreateUrl')), 'POST', {
15
18
  data: data,
16
- success: function(json) {
19
+ success: function(json, status, jqxhr) {
17
20
  _this.set('authToken', json[Auth.Config.get('tokenKey')]);
18
- return _this.set('currentUserId', json[Auth.Config.get('idKey')]);
21
+ _this.set('currentUserId', json[Auth.Config.get('idKey')]);
22
+ _this.set('jqxhr', jqxhr);
23
+ return _this.trigger('signInSuccess');
19
24
  },
20
- error: function(json) {
21
- return _this.set('error', json);
25
+ error: function(jqxhr) {
26
+ _this.set('jqxhr', jqxhr);
27
+ return _this.trigger('signInError');
22
28
  },
23
- complete: function() {
24
- return _this.set('prevRoute', null);
29
+ complete: function(jqxhr) {
30
+ _this.set('prevRoute', null);
31
+ _this.set('jqxhr', jqxhr);
32
+ return _this.trigger('signInComplete');
25
33
  }
26
34
  });
27
35
  },
@@ -33,15 +41,20 @@
33
41
  data[Auth.Config.get('tokenKey')] = this.get('authToken');
34
42
  return this.ajax(this.resolveUrl(Auth.Config.get('tokenDestroyUrl')), 'DELETE', {
35
43
  data: data,
36
- success: function(json) {
44
+ success: function(json, status, jqxhr) {
37
45
  _this.set('authToken', null);
38
- return _this.set('currentUserId', null);
46
+ _this.set('currentUserId', null);
47
+ _this.set('jqxhr', jqxhr);
48
+ return _this.trigger('signOutSuccess');
39
49
  },
40
- error: function(json) {
41
- return _this.set('error', json);
50
+ error: function(jqxhr) {
51
+ _this.set('jqxhr', jqxhr);
52
+ return _this.trigger('signOutError');
42
53
  },
43
- complete: function() {
44
- return _this.set('prevRoute', null);
54
+ complete: function(jqxhr) {
55
+ _this.set('prevRoute', null);
56
+ _this.set('jqxhr', jqxhr);
57
+ return _this.trigger('signOutComplete');
45
58
  }
46
59
  });
47
60
  },
@@ -98,7 +111,10 @@
98
111
  smartSignInRedirect: false,
99
112
  smartSignOutRedirect: false,
100
113
  signInRedirectFallbackRoute: 'index',
101
- signOutRedirectFallbackRoute: 'index'
114
+ signOutRedirectFallbackRoute: 'index',
115
+ rememberMe: false,
116
+ rememberTokenKey: null,
117
+ rememberPeriod: 14
102
118
  });
103
119
 
104
120
  Auth.Route = Em.Route.extend({
@@ -146,4 +162,52 @@
146
162
  }
147
163
  });
148
164
 
165
+ Auth.Module = Em.Object.create();
166
+
167
+ Auth.Module.RememberMe = Em.Object.create({
168
+ init: function() {
169
+ var _this = this;
170
+ Auth.on('signInSuccess', function() {
171
+ return _this.remember();
172
+ });
173
+ Auth.on('signInError', function() {
174
+ return _this.forget();
175
+ });
176
+ return Auth.on('signOutSuccess', function() {
177
+ return _this.forget();
178
+ });
179
+ },
180
+ recall: function() {
181
+ var data, token;
182
+ if (!Auth.Config.get('rememberMe')) {
183
+ return;
184
+ }
185
+ if (token = $.cookie('ember-auth-remember-me')) {
186
+ data = {};
187
+ data[Auth.Config.get('rememberTokenKey')] = token;
188
+ return Auth.signIn(data);
189
+ }
190
+ },
191
+ remember: function() {
192
+ var curToken, json, token;
193
+ if (!Auth.Config.get('rememberMe')) {
194
+ return;
195
+ }
196
+ json = JSON.parse((Auth.get('jqxhr')).responseText);
197
+ token = json[Auth.Config.get('rememberTokenKey')];
198
+ curToken = $.cookie('ember-auth-remember-me');
199
+ if (token !== curToken) {
200
+ return $.cookie('ember-auth-remember-me', token, {
201
+ expires: Auth.Config.get('rememberPeriod')
202
+ });
203
+ }
204
+ },
205
+ forget: function() {
206
+ if (!Auth.Config.get('rememberMe')) {
207
+ return;
208
+ }
209
+ return $.removeCookie('ember-auth-remember-me');
210
+ }
211
+ });
212
+
149
213
  }).call(this);
@@ -1 +1,2 @@
1
+ //= require ./jquery.cookie
1
2
  //= require ./ember-auth
@@ -0,0 +1,92 @@
1
+ /*!
2
+ * jQuery Cookie Plugin v1.3.1
3
+ * https://github.com/carhartl/jquery-cookie
4
+ *
5
+ * Copyright 2013 Klaus Hartl
6
+ * Released under the MIT license
7
+ */
8
+ (function (factory) {
9
+ if (typeof define === 'function' && define.amd && define.amd.jQuery) {
10
+ // AMD. Register as anonymous module.
11
+ define(['jquery'], factory);
12
+ } else {
13
+ // Browser globals.
14
+ factory(jQuery);
15
+ }
16
+ }(function ($) {
17
+
18
+ var pluses = /\+/g;
19
+
20
+ function raw(s) {
21
+ return s;
22
+ }
23
+
24
+ function decoded(s) {
25
+ return decodeURIComponent(s.replace(pluses, ' '));
26
+ }
27
+
28
+ function converted(s) {
29
+ if (s.indexOf('"') === 0) {
30
+ // This is a quoted cookie as according to RFC2068, unescape
31
+ s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
32
+ }
33
+ try {
34
+ return config.json ? JSON.parse(s) : s;
35
+ } catch(er) {}
36
+ }
37
+
38
+ var config = $.cookie = function (key, value, options) {
39
+
40
+ // write
41
+ if (value !== undefined) {
42
+ options = $.extend({}, config.defaults, options);
43
+
44
+ if (typeof options.expires === 'number') {
45
+ var days = options.expires, t = options.expires = new Date();
46
+ t.setDate(t.getDate() + days);
47
+ }
48
+
49
+ value = config.json ? JSON.stringify(value) : String(value);
50
+
51
+ return (document.cookie = [
52
+ encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
53
+ options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
54
+ options.path ? '; path=' + options.path : '',
55
+ options.domain ? '; domain=' + options.domain : '',
56
+ options.secure ? '; secure' : ''
57
+ ].join(''));
58
+ }
59
+
60
+ // read
61
+ var decode = config.raw ? raw : decoded;
62
+ var cookies = document.cookie.split('; ');
63
+ var result = key ? undefined : {};
64
+ for (var i = 0, l = cookies.length; i < l; i++) {
65
+ var parts = cookies[i].split('=');
66
+ var name = decode(parts.shift());
67
+ var cookie = decode(parts.join('='));
68
+
69
+ if (key && key === name) {
70
+ result = converted(cookie);
71
+ break;
72
+ }
73
+
74
+ if (!key) {
75
+ result[name] = converted(cookie);
76
+ }
77
+ }
78
+
79
+ return result;
80
+ };
81
+
82
+ config.defaults = {};
83
+
84
+ $.removeCookie = function (key, options) {
85
+ if ($.cookie(key) !== undefined) {
86
+ $.cookie(key, '', $.extend(options, { expires: -1 }));
87
+ return true;
88
+ }
89
+ return false;
90
+ };
91
+
92
+ }));
@@ -1,5 +1,5 @@
1
1
  module EmberAuth
2
2
  module Rails
3
- VERSION = '3.1.0'
3
+ VERSION = '3.2.0'
4
4
  end
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module EmberAuth
2
- VERSION = '1.1.0'
2
+ VERSION = '2.0.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.1.0
4
+ version: 3.2.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-02-18 00:00:00.000000000 Z
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ember-rails
@@ -41,6 +41,7 @@ files:
41
41
  - Rakefile
42
42
  - app/assets/javascripts/ember-auth/ember-auth.js
43
43
  - app/assets/javascripts/ember-auth/index.js
44
+ - app/assets/javascripts/ember-auth/jquery.cookie.js
44
45
  - ember-auth-rails.gemspec
45
46
  - lib/ember-auth-rails.rb
46
47
  - lib/ember-auth/rails/engine.rb