|
@@ -1,9 +1,34 @@
|
|
import Ember from 'ember';
|
|
import Ember from 'ember';
|
|
|
|
|
|
export default Ember.Service.extend({
|
|
export default Ember.Service.extend({
|
|
|
|
+ // State synchronization across tabs
|
|
|
|
+
|
|
|
|
+ needsSync: false, // becomes true if auth state between tabs differs
|
|
|
|
+ syncToUser: false, // becomes user obj to which we want to sync or none for anon
|
|
|
|
+
|
|
|
|
+ syncSession: function() {
|
|
|
|
+ this.session.setItem('auth-user', this.get('user'));
|
|
|
|
+ this.session.setItem('auth-is-authenticated', this.get('isAuthenticated'));
|
|
|
|
+
|
|
|
|
+ var self = this;
|
|
|
|
+ this.session.watchItem('auth-is-authenticated', function(isAuthenticated) {
|
|
|
|
+ if (!self.get('needsSync')) {
|
|
|
|
+ // display annoying "you were desynced" message
|
|
|
|
+ self.set('needsSync', true);
|
|
|
|
+
|
|
|
|
+ if (isAuthenticated) {
|
|
|
|
+ self.set('syncToUser', Ember.Object.create(self.session.getItem('auth-user')));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }.on('init'),
|
|
|
|
+
|
|
|
|
+ // Anon/auth state
|
|
isAnonymous: Ember.computed.not('isAuthenticated'),
|
|
isAnonymous: Ember.computed.not('isAuthenticated'),
|
|
|
|
|
|
logout: function() {
|
|
logout: function() {
|
|
|
|
+ this.session.setItem('auth-user', false);
|
|
|
|
+ this.session.setItem('auth-is-authenticated', false);
|
|
Ember.$('#hidden-logout-form').submit();
|
|
Ember.$('#hidden-logout-form').submit();
|
|
},
|
|
},
|
|
|
|
|