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:
parent
cbac8d2d59
commit
1e22c7cbe7
6 changed files with 63 additions and 82 deletions
|
@ -5,7 +5,8 @@ import netUtil from '../utils/net';
|
|||
import models from '../utils/model';
|
||||
|
||||
const {
|
||||
isPresent
|
||||
isPresent,
|
||||
RSVP: { resolve, reject }
|
||||
} = Ember;
|
||||
|
||||
export default Base.extend({
|
||||
|
@ -13,6 +14,13 @@ export default Base.extend({
|
|||
|
||||
ajax: Ember.inject.service(),
|
||||
|
||||
restore(data) {
|
||||
if (data) {
|
||||
return resolve(data)
|
||||
}
|
||||
return reject();
|
||||
},
|
||||
|
||||
authenticate({password, email}) {
|
||||
let domain = netUtil.getSubdomain();
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
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'),
|
||||
folder: {},
|
||||
|
||||
|
|
|
@ -9,66 +9,50 @@
|
|||
//
|
||||
// https://documize.com
|
||||
|
||||
|
||||
import Ember from 'ember';
|
||||
import netUtil from '../utils/net';
|
||||
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
|
||||
|
||||
const {
|
||||
inject: { service }
|
||||
inject: { service }
|
||||
} = Ember;
|
||||
|
||||
export default Ember.Route.extend(ApplicationRouteMixin, {
|
||||
userService: service('user'),
|
||||
session: service('session'),
|
||||
appMeta: service(),
|
||||
|
||||
transitioning: false,
|
||||
|
||||
beforeModel: function(transition) {
|
||||
let self = this;
|
||||
let session = this.get('session');
|
||||
let appMeta = this.get('appMeta');
|
||||
|
||||
// Session ready?
|
||||
return this.get('appMeta').boot().then(function() {
|
||||
// Need to authenticate?
|
||||
if (!appMeta.get("allowAnonymousAccess") && !session.get("isAuthenticated") &&
|
||||
is.not.startWith(transition.targetName, 'auth.')) {
|
||||
if (!self.transitioning) {
|
||||
session.set('previousTransition', transition);
|
||||
self.set('transitioning', true);
|
||||
}
|
||||
|
||||
transition.abort();
|
||||
self.transitionTo('auth.login');
|
||||
}
|
||||
});
|
||||
appMeta: service(),
|
||||
session: service(),
|
||||
beforeModel() {
|
||||
return this.get('appMeta').boot().then( data => {
|
||||
if ( data.allowAnonymousAccess ) {
|
||||
return this.get('session').authenticate('authenticator:anonymous', data);
|
||||
}
|
||||
return;
|
||||
});
|
||||
},
|
||||
|
||||
actions: {
|
||||
willTransition: function( /*transition*/ ) {
|
||||
$("#zone-sidebar").css('height', 'auto');
|
||||
Mousetrap.reset();
|
||||
},
|
||||
|
||||
actions: {
|
||||
willTransition: function( /*transition*/ ) {
|
||||
$("#zone-sidebar").css('height', 'auto');
|
||||
Mousetrap.reset();
|
||||
},
|
||||
didTransition() {
|
||||
Ember.run.schedule("afterRender",this,function() {
|
||||
$("#zone-sidebar").css('height', $(document).height() - $("#zone-navigation").height() - $("#zone-header").height() - 35);
|
||||
});
|
||||
|
||||
didTransition() {
|
||||
Ember.run.schedule("afterRender",this,function() {
|
||||
$("#zone-sidebar").css('height', $(document).height() - $("#zone-navigation").height() - $("#zone-header").height() - 35);
|
||||
});
|
||||
return true;
|
||||
},
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
error(error, transition) { // jshint ignore: line
|
||||
if (error) {
|
||||
if (netUtil.isAjaxAccessError(error)) {
|
||||
localStorage.clear();
|
||||
return this.transitionTo('auth.login');
|
||||
}
|
||||
}
|
||||
|
||||
// Return true to bubble this event to any parent route.
|
||||
return true;
|
||||
error(error, transition) { // jshint ignore: line
|
||||
if (error) {
|
||||
if (netUtil.isAjaxAccessError(error)) {
|
||||
localStorage.clear();
|
||||
return this.transitionTo('auth.login');
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// Return true to bubble this event to any parent route.
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@ export default Ember.Service.extend({
|
|||
title: '',
|
||||
version: '',
|
||||
message: '',
|
||||
allowAnonymousAccess: null,
|
||||
allowAnonymousAccess: false,
|
||||
|
||||
boot() {
|
||||
let dbhash;
|
||||
|
@ -33,8 +33,9 @@ export default Ember.Service.extend({
|
|||
}
|
||||
|
||||
return this.get('ajax').request('public/meta')
|
||||
.then((response) => {
|
||||
.then((response) => {
|
||||
this.setProperties(response);
|
||||
});
|
||||
return response;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -17,7 +17,8 @@ import SimpleAuthSession from 'ember-simple-auth/services/session';
|
|||
|
||||
const {
|
||||
inject: { service },
|
||||
computed: { oneWay }
|
||||
computed: { oneWay, or },
|
||||
computed
|
||||
} = Ember;
|
||||
|
||||
export default SimpleAuthSession.extend({
|
||||
|
@ -25,34 +26,19 @@ export default SimpleAuthSession.extend({
|
|||
appMeta: service(),
|
||||
|
||||
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,
|
||||
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() {
|
||||
// TODO: clear session properly with ESA
|
||||
localStorage.clear();
|
||||
|
|
|
@ -31,7 +31,8 @@ module.exports = function(environment) {
|
|||
},
|
||||
'ember-simple-auth': {
|
||||
authenticationRoute: 'auth.login',
|
||||
routeAfterAuthentication: 'folders.folder'
|
||||
routeAfterAuthentication: 'folders.folder',
|
||||
routeIfAlreadyAuthenticated: 'folders.folder'
|
||||
},
|
||||
APP: {
|
||||
// Allows to disable audit service in tests
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue