ember-auth-source 6.0.5 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/dist/ember-auth.js +111 -83
  2. metadata +5 -29
@@ -20,6 +20,39 @@ set$(Em, 'Auth', get$(Em, 'Object').extend(get$(Em, 'Evented'), {
20
20
  get$(get$(this, '_session'), 'syncEvent').apply(get$(this, '_session'), arguments);
21
21
  return get$(get$(this, '_module'), 'syncEvent').apply(get$(this, '_module'), arguments);
22
22
  },
23
+ ensurePromise: function (callback) {
24
+ var cache$, deferred, ret;
25
+ if (null != (null != (cache$ = ret = callback()) ? get$(cache$, 'then') : void 0)) {
26
+ return ret;
27
+ } else {
28
+ deferred = get$(Em, 'Deferred').create();
29
+ deferred.resolve(deferred);
30
+ return deferred;
31
+ }
32
+ },
33
+ followPromise: function (ret, callback) {
34
+ if (null != (null != ret ? get$(ret, 'then') : void 0)) {
35
+ return ret.then(function () {
36
+ return callback();
37
+ });
38
+ } else {
39
+ return this.ensurePromise(function () {
40
+ return callback();
41
+ });
42
+ }
43
+ },
44
+ wrapDeferred: function (callback) {
45
+ var deferred, reject, resolve;
46
+ deferred = get$(Em, 'Deferred').create();
47
+ resolve = function () {
48
+ return deferred.resolve(deferred);
49
+ };
50
+ reject = function () {
51
+ return deferred.reject(deferred);
52
+ };
53
+ callback(resolve, reject);
54
+ return deferred;
55
+ },
23
56
  requestAdapter: 'jquery',
24
57
  responseAdapter: 'json',
25
58
  strategyAdapter: 'token',
@@ -69,17 +102,26 @@ set$(get$(Em, 'Auth'), 'Request', Ember.Object.extend({
69
102
  return get$(get$(this, 'adapter'), 'syncEvent').apply(get$(this, 'adapter'), arguments);
70
103
  },
71
104
  signIn: function (opts) {
72
- var url;
73
- url = this.resolveUrl(get$(get$(this, 'auth'), 'signInEndPoint'));
74
- return get$(this, 'adapter').signIn(url, get$(get$(this, 'auth'), '_strategy').serialize(opts));
105
+ var this$;
106
+ return get$(this, 'auth').ensurePromise((this$ = this, function () {
107
+ var url;
108
+ url = this$.resolveUrl(get$(get$(this$, 'auth'), 'signInEndPoint'));
109
+ return get$(this$, 'adapter').signIn(url, get$(get$(this$, 'auth'), '_strategy').serialize(opts));
110
+ }));
75
111
  },
76
112
  signOut: function (opts) {
77
- var url;
78
- url = this.resolveUrl(get$(get$(this, 'auth'), 'signOutEndPoint'));
79
- return get$(this, 'adapter').signOut(url, get$(get$(this, 'auth'), '_strategy').serialize(opts));
113
+ var this$;
114
+ return get$(this, 'auth').ensurePromise((this$ = this, function () {
115
+ var url;
116
+ url = this$.resolveUrl(get$(get$(this$, 'auth'), 'signOutEndPoint'));
117
+ return get$(this$, 'adapter').signOut(url, get$(get$(this$, 'auth'), '_strategy').serialize(opts));
118
+ }));
80
119
  },
81
120
  send: function (opts) {
82
- return get$(this, 'adapter').send(get$(get$(this, 'auth'), '_strategy').serialize(opts));
121
+ var this$;
122
+ return get$(this, 'auth').ensurePromise((this$ = this, function () {
123
+ return get$(this$, 'adapter').send(get$(get$(this$, 'auth'), '_strategy').serialize(opts));
124
+ }));
83
125
  },
84
126
  resolveUrl: function (path) {
85
127
  var base;
@@ -624,8 +666,6 @@ void function () {
624
666
  set$(get$(get$(Em, 'Auth'), 'Module'), 'ActionRedirectable', Ember.Object.extend({
625
667
  init: function () {
626
668
  null != get$(this, 'config') || set$(this, 'config', get$(get$(this, 'auth'), 'actionRedirectable'));
627
- null != get$(this, 'initPath') || set$(this, 'initPath', null);
628
- null != get$(this, 'isInit') || set$(this, 'isInit', true);
629
669
  null != get$(this, 'signInRedir') || set$(this, 'signInRedir', null);
630
670
  null != get$(this, 'signOutRedir') || set$(this, 'signOutRedir', null);
631
671
  null != get$(this, 'router') || set$(this, 'router', null);
@@ -666,34 +706,16 @@ void function () {
666
706
  if (!fallback)
667
707
  return null;
668
708
  if (!isSmart)
669
- return [fallback];
670
- return this.get('' + env + 'Redir') || get$(this, 'initPath');
671
- },
672
- registerInitRedirect: function (routeName) {
673
- if (!get$(this, 'isInit'))
674
- return;
675
- routeName = this.canonicalizeRoute(routeName);
676
- return function (accum$) {
677
- var env;
678
- for (var cache$ = [
679
- 'signIn',
680
- 'signOut'
681
- ], i$ = 0, length$ = cache$.length; i$ < length$; ++i$) {
682
- env = cache$[i$];
683
- this.set('' + env + 'Redir', null);
684
- accum$.push($.inArray(routeName, this.getBlacklist(env)) !== -1 ? this.set('' + env + 'Redir', [get$(this, 'config')['' + env + 'Route']]) : void 0);
685
- }
686
- return accum$;
687
- }.call(this, []);
709
+ return fallback;
710
+ return this.get('' + env + 'Redir') || fallback;
688
711
  },
689
- registerRedirect: function (args) {
712
+ registerRedirect: function (transition) {
690
713
  var routeName;
691
- routeName = this.canonicalizeRoute(args[0]);
692
- set$(this, 'isInit', false);
714
+ routeName = this.canonicalizeRoute(get$(transition, 'targetName'));
693
715
  if ($.inArray(routeName, this.getBlacklist('signIn')) === -1)
694
- set$(this, 'signInRedir', args);
716
+ set$(this, 'signInRedir', transition);
695
717
  if ($.inArray(routeName, this.getBlacklist('signOut')) === -1)
696
- return set$(this, 'signOutRedir', args);
718
+ return set$(this, 'signOutRedir', transition);
697
719
  },
698
720
  redirect: Ember.observer(function () {
699
721
  var env, result;
@@ -702,38 +724,24 @@ void function () {
702
724
  return;
703
725
  switch (typeof result) {
704
726
  case 'object':
705
- return get$(get$(this, 'router'), 'transitionTo').apply(this, result);
727
+ return result.retry();
706
728
  case 'string':
707
- get$(get$(this, 'router'), 'location').setURL(result);
708
- return get$(this, 'router').handleURL(result);
729
+ return get$(this, 'router').transitionTo(result);
709
730
  }
710
731
  }, 'auth.signedIn'),
711
732
  patch: function () {
712
733
  var self;
713
734
  self = this;
714
- get$(Em, 'Route').reopen({
715
- activate: function () {
716
- this._super.apply(this, arguments);
717
- self.router || (self.router = get$(this, 'router'));
718
- return self.registerInitRedirect(get$(this, 'routeName'));
719
- }
720
- });
721
- return get$(Em, 'Router').reopen({
735
+ return get$(Em, 'Route').reopen({
722
736
  init: function () {
723
- this._super.apply(this, arguments);
724
- return self.initPath || (self.initPath = get$(this, 'location').getURL());
725
- },
726
- transitionTo: function () {
727
- var args;
728
- args = Array.prototype.slice.call(arguments);
729
- self.registerRedirect(args);
730
- return this._super.apply(this, args);
737
+ self.router || (self.router = get$(this, 'router'));
738
+ return this._super.apply(this, arguments);
731
739
  },
732
- replaceWith: function () {
733
- var args;
734
- args = Array.prototype.slice.call(arguments);
735
- self.registerRedirect(args);
736
- return this._super.apply(this, args);
740
+ beforeModel: function (transition) {
741
+ return get$(self, 'auth').followPromise(this._super.apply(this, arguments), function () {
742
+ self.registerRedirect(transition);
743
+ return null;
744
+ });
737
745
  }
738
746
  });
739
747
  }
@@ -750,12 +758,14 @@ set$(get$(get$(Em, 'Auth'), 'Module'), 'AuthRedirectable', Ember.Object.extend({
750
758
  var self;
751
759
  self = this;
752
760
  set$(this, 'AuthRedirectable', Ember.Mixin.create({
753
- redirect: function () {
754
- this._super.apply(this, arguments);
755
- if (!get$(get$(self, 'auth'), 'signedIn')) {
761
+ beforeModel: function () {
762
+ var this$;
763
+ return get$(self, 'auth').followPromise(this._super.apply(this, arguments), (this$ = this, function () {
764
+ if (get$(get$(self, 'auth'), 'signedIn'))
765
+ return;
756
766
  get$(self, 'auth').trigger('authAccess');
757
- return this.transitionTo(get$(get$(self, 'config'), 'route'));
758
- }
767
+ return this$.transitionTo(get$(get$(self, 'config'), 'route'));
768
+ }));
759
769
  }
760
770
  }));
761
771
  return set$(get$(this, 'auth'), 'AuthRedirectable', get$(this, 'AuthRedirectable'));
@@ -801,15 +811,24 @@ set$(get$(get$(Em, 'Auth'), 'Module'), 'Rememberable', Ember.Object.extend({
801
811
  }
802
812
  },
803
813
  recall: function (opts) {
804
- var token;
814
+ var this$;
805
815
  if (null == opts)
806
816
  opts = {};
807
- if (!get$(get$(this, 'auth'), 'signedIn') && (token = this.retrieveToken())) {
808
- set$(this, 'fromRecall', true);
809
- opts.data || (opts.data = {});
810
- get$(opts, 'data')[get$(get$(this, 'config'), 'tokenKey')] = token;
811
- return get$(this, 'auth').signIn(opts);
812
- }
817
+ return get$(this, 'auth').wrapDeferred((this$ = this, function (resolve, reject) {
818
+ var token;
819
+ if (!get$(get$(this$, 'auth'), 'signedIn') && (token = this$.retrieveToken())) {
820
+ set$(this$, 'fromRecall', true);
821
+ opts.data || (opts.data = {});
822
+ get$(opts, 'data')[get$(get$(this$, 'config'), 'tokenKey')] = token;
823
+ return get$(this$, 'auth').signIn(opts).then(function () {
824
+ return resolve();
825
+ }, function () {
826
+ return reject();
827
+ });
828
+ } else {
829
+ return resolve();
830
+ }
831
+ }));
813
832
  },
814
833
  remember: function () {
815
834
  var token;
@@ -838,10 +857,11 @@ set$(get$(get$(Em, 'Auth'), 'Module'), 'Rememberable', Ember.Object.extend({
838
857
  var self;
839
858
  self = this;
840
859
  return get$(Em, 'Route').reopen({
841
- redirect: function () {
842
- this._super.apply(this, arguments);
843
- if (get$(get$(self, 'config'), 'autoRecall') && !get$(get$(self, 'auth'), 'signedIn'))
844
- return self.recall({ async: false });
860
+ beforeModel: function () {
861
+ return get$(self, 'auth').followPromise(this._super.apply(this, arguments), function () {
862
+ if (get$(get$(self, 'config'), 'autoRecall') && !get$(get$(self, 'auth'), 'signedIn'))
863
+ return self.recall();
864
+ });
845
865
  }
846
866
  });
847
867
  }
@@ -1130,15 +1150,22 @@ void function () {
1130
1150
  return this.patch();
1131
1151
  },
1132
1152
  authenticate: function (opts) {
1153
+ var this$;
1133
1154
  if (null == opts)
1134
1155
  opts = {};
1135
- if (get$(get$(this, 'auth'), 'signedIn'))
1136
- return;
1137
- this.canonicalizeParams();
1138
- if ($.isEmptyObject(get$(this, 'params')))
1139
- return;
1140
- set$(opts, 'data', $.extend(true, get$(this, 'params'), get$(opts, 'data') || {}));
1141
- return get$(this, 'auth').signIn(opts);
1156
+ return get$(this, 'auth').wrapDeferred((this$ = this, function (resolve, reject) {
1157
+ if (get$(get$(this$, 'auth'), 'signedIn'))
1158
+ return resolve();
1159
+ this$.canonicalizeParams();
1160
+ if ($.isEmptyObject(get$(this$, 'params')))
1161
+ return resolve();
1162
+ set$(opts, 'data', $.extend(true, get$(this$, 'params'), get$(opts, 'data') || {}));
1163
+ return get$(this$, 'auth').signIn(opts).then(function () {
1164
+ return resolve();
1165
+ }, function () {
1166
+ return reject();
1167
+ });
1168
+ }));
1142
1169
  },
1143
1170
  retrieveParams: function () {
1144
1171
  return set$(this, 'params', $.url().param(get$(get$(this, 'config'), 'paramsKey')));
@@ -1182,9 +1209,10 @@ void function () {
1182
1209
  var self;
1183
1210
  self = this;
1184
1211
  get$(Em, 'Route').reopen({
1185
- redirect: function () {
1186
- this._super.apply(this, arguments);
1187
- return self.authenticate({ async: false });
1212
+ beforeModel: function () {
1213
+ return get$(self, 'auth').followPromise(this._super.apply(this, arguments), function () {
1214
+ return self.authenticate();
1215
+ });
1188
1216
  }
1189
1217
  });
1190
1218
  return get$(Em, 'Router').reopen({
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ember-auth-source
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.5
4
+ version: 7.0.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-05-29 00:00:00.000000000 Z
12
+ date: 2013-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ember-source
@@ -18,19 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.0.2
22
- - - ! '!='
23
- - !ruby/object:Gem::Version
24
- version: 1.0.0.pre4.1
25
- - - ! '!='
26
- - !ruby/object:Gem::Version
27
- version: 1.0.0.rc1.0.0
28
- - - ! '!='
29
- - !ruby/object:Gem::Version
30
- version: 1.0.0.rc1.1
31
- - - ! '!='
32
- - !ruby/object:Gem::Version
33
- version: 1.0.0.rc1.2
21
+ version: 1.0.0.rc6
34
22
  type: :runtime
35
23
  prerelease: false
36
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,19 +26,7 @@ dependencies:
38
26
  requirements:
39
27
  - - ! '>='
40
28
  - !ruby/object:Gem::Version
41
- version: 0.0.2
42
- - - ! '!='
43
- - !ruby/object:Gem::Version
44
- version: 1.0.0.pre4.1
45
- - - ! '!='
46
- - !ruby/object:Gem::Version
47
- version: 1.0.0.rc1.0.0
48
- - - ! '!='
49
- - !ruby/object:Gem::Version
50
- version: 1.0.0.rc1.1
51
- - - ! '!='
52
- - !ruby/object:Gem::Version
53
- version: 1.0.0.rc1.2
29
+ version: 1.0.0.rc6
54
30
  description: Ember-auth source code wrapper for ruby libs.
55
31
  email:
56
32
  - heartsentwined@cogito-lab.com
@@ -75,7 +51,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
51
  version: '0'
76
52
  segments:
77
53
  - 0
78
- hash: -527079107
54
+ hash: 262689745
79
55
  required_rubygems_version: !ruby/object:Gem::Requirement
80
56
  none: false
81
57
  requirements: