1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-08 06:55:28 +02:00

WIP fix session.get property issues

This commit is contained in:
zinyando 2016-06-28 23:09:59 +02:00
parent cbac8d2d59
commit 1e22c7cbe7
6 changed files with 63 additions and 82 deletions

View file

@ -5,7 +5,8 @@ import netUtil from '../utils/net';
import models from '../utils/model'; import models from '../utils/model';
const { const {
isPresent isPresent,
RSVP: { resolve, reject }
} = Ember; } = Ember;
export default Base.extend({ export default Base.extend({
@ -13,6 +14,13 @@ export default Base.extend({
ajax: Ember.inject.service(), ajax: Ember.inject.service(),
restore(data) {
if (data) {
return resolve(data)
}
return reject();
},
authenticate({password, email}) { authenticate({password, email}) {
let domain = netUtil.getSubdomain(); let domain = netUtil.getSubdomain();

View file

@ -1,6 +1,7 @@
import Ember from 'ember'; import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend({ export default Ember.Route.extend(AuthenticatedRouteMixin, {
folderService: Ember.inject.service('folder'), folderService: Ember.inject.service('folder'),
folder: {}, folder: {},

View file

@ -9,66 +9,50 @@
// //
// https://documize.com // https://documize.com
import Ember from 'ember'; import Ember from 'ember';
import netUtil from '../utils/net';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin'; import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
const { const {
inject: { service } inject: { service }
} = Ember; } = Ember;
export default Ember.Route.extend(ApplicationRouteMixin, { export default Ember.Route.extend(ApplicationRouteMixin, {
userService: service('user'), appMeta: service(),
session: service('session'), session: service(),
appMeta: service(), beforeModel() {
return this.get('appMeta').boot().then( data => {
transitioning: false, if ( data.allowAnonymousAccess ) {
return this.get('session').authenticate('authenticator:anonymous', data);
beforeModel: function(transition) { }
let self = this; return;
let session = this.get('session'); });
let appMeta = this.get('appMeta'); },
// Session ready? actions: {
return this.get('appMeta').boot().then(function() { willTransition: function( /*transition*/ ) {
// Need to authenticate? $("#zone-sidebar").css('height', 'auto');
if (!appMeta.get("allowAnonymousAccess") && !session.get("isAuthenticated") && Mousetrap.reset();
is.not.startWith(transition.targetName, 'auth.')) {
if (!self.transitioning) {
session.set('previousTransition', transition);
self.set('transitioning', true);
}
transition.abort();
self.transitionTo('auth.login');
}
});
}, },
actions: { didTransition() {
willTransition: function( /*transition*/ ) { Ember.run.schedule("afterRender",this,function() {
$("#zone-sidebar").css('height', 'auto'); $("#zone-sidebar").css('height', $(document).height() - $("#zone-navigation").height() - $("#zone-header").height() - 35);
Mousetrap.reset(); });
},
didTransition() { return true;
Ember.run.schedule("afterRender",this,function() { },
$("#zone-sidebar").css('height', $(document).height() - $("#zone-navigation").height() - $("#zone-header").height() - 35);
});
return true; error(error, transition) { // jshint ignore: line
}, if (error) {
if (netUtil.isAjaxAccessError(error)) {
error(error, transition) { // jshint ignore: line localStorage.clear();
if (error) { return this.transitionTo('auth.login');
if (netUtil.isAjaxAccessError(error)) {
localStorage.clear();
return this.transitionTo('auth.login');
}
}
// Return true to bubble this event to any parent route.
return true;
} }
}, }
// Return true to bubble this event to any parent route.
return true;
}
},
}); });

View file

@ -15,7 +15,7 @@ export default Ember.Service.extend({
title: '', title: '',
version: '', version: '',
message: '', message: '',
allowAnonymousAccess: null, allowAnonymousAccess: false,
boot() { boot() {
let dbhash; let dbhash;
@ -33,8 +33,9 @@ export default Ember.Service.extend({
} }
return this.get('ajax').request('public/meta') return this.get('ajax').request('public/meta')
.then((response) => { .then((response) => {
this.setProperties(response); this.setProperties(response);
}); return response;
});
} }
}); });

View file

@ -17,7 +17,8 @@ import SimpleAuthSession from 'ember-simple-auth/services/session';
const { const {
inject: { service }, inject: { service },
computed: { oneWay } computed: { oneWay, or },
computed
} = Ember; } = Ember;
export default SimpleAuthSession.extend({ export default SimpleAuthSession.extend({
@ -25,34 +26,19 @@ export default SimpleAuthSession.extend({
appMeta: service(), appMeta: service(),
authenticated: oneWay('isAuthenticated'), authenticated: oneWay('isAuthenticated'),
user: oneWay('session.content.authenticated.user'), isAdmin: oneWay('user.admin'),
isEditor: or('user.admin', 'user.editor'),
user: computed('session.content.authenticated.user', function(){
let user = this.get('session.content.authenticated.user');
if (user) {
return models.UserModel.create(user);
}
}),
folderPermissions: null, folderPermissions: null,
currentFolder: null, currentFolder: null,
authenticate() {
return this._super(...arguments)
.then(function({token, user}){
return {
token,
user: models.User.create(user)
};
});
},
isAdmin: function() {
if (this.authenticated && is.not.null(this.user) && this.user.id !== "") {
return this.user.admin;
}
return false;
}.property('user'),
isEditor: function() {
if (this.authenticated && is.not.null(this.user) && this.user.id !== "") {
return this.user.editor || this.user.admin;
}
return false;
}.property('user'),
clearSession: function() { clearSession: function() {
// TODO: clear session properly with ESA // TODO: clear session properly with ESA
localStorage.clear(); localStorage.clear();

View file

@ -31,7 +31,8 @@ module.exports = function(environment) {
}, },
'ember-simple-auth': { 'ember-simple-auth': {
authenticationRoute: 'auth.login', authenticationRoute: 'auth.login',
routeAfterAuthentication: 'folders.folder' routeAfterAuthentication: 'folders.folder',
routeIfAlreadyAuthenticated: 'folders.folder'
}, },
APP: { APP: {
// Allows to disable audit service in tests // Allows to disable audit service in tests