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';
|
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();
|
||||||
|
|
||||||
|
|
|
@ -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: {},
|
||||||
|
|
||||||
|
|
|
@ -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 => {
|
||||||
|
if ( data.allowAnonymousAccess ) {
|
||||||
|
return this.get('session').authenticate('authenticator:anonymous', data);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
transitioning: false,
|
actions: {
|
||||||
|
willTransition: function( /*transition*/ ) {
|
||||||
beforeModel: function(transition) {
|
$("#zone-sidebar").css('height', 'auto');
|
||||||
let self = this;
|
Mousetrap.reset();
|
||||||
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');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue