mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
c8e8da4780
closes #2759 closes #3027 - added oauth2orize library for server side oAuth handling - added ember-simple-auth library for admin oAuth handling - added tables for client, accesstoken and refreshtoken - implemented RFC6749 4.3 Ressouce Owner Password Credentials Grant - updated api tests with oAuth - removed session, authentication is now token based Known issues: - Restore spam prevention #3128 - Signin after Signup #3125 - Signin validation #3125 **Attention** - oldClient doesn't work with this PR anymore, session authentication was removed
107 lines
3.7 KiB
JavaScript
107 lines
3.7 KiB
JavaScript
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
|
import mobileUtils from 'ghost/utils/mobile-utils';
|
|
|
|
var ApplicationRoute = Ember.Route.extend(Ember.SimpleAuth.ApplicationRouteMixin, ShortcutsRoute, {
|
|
|
|
shortcuts: {
|
|
'esc': 'closePopups'
|
|
},
|
|
beforeModel: function () {
|
|
var self = this;
|
|
if (this.get('session').isAuthenticated) {
|
|
this.store.find('user', 'me').then(function (user) {
|
|
// Update the user on all routes and controllers
|
|
self.container.unregister('user:current');
|
|
self.container.register('user:current', user, { instantiate: false });
|
|
|
|
self.container.injection('route', 'user', 'user:current');
|
|
self.container.injection('controller', 'user', 'user:current');
|
|
|
|
});
|
|
}
|
|
},
|
|
mobileInteractions: function () {
|
|
var responsiveAction = mobileUtils.responsiveAction;
|
|
|
|
Ember.run.scheduleOnce('afterRender', document, function () {
|
|
// ### Toggle the sidebar menu
|
|
$('[data-off-canvas]').on('click', function (event) {
|
|
responsiveAction(event, '(max-width: 650px)', function () {
|
|
$('body').toggleClass('off-canvas');
|
|
});
|
|
});
|
|
});
|
|
}.on('init'),
|
|
|
|
actions: {
|
|
closePopups: function () {
|
|
this.get('popover').closePopovers();
|
|
this.get('notifications').closeAll();
|
|
|
|
this.send('closeModal');
|
|
},
|
|
|
|
signedIn: function (user) {
|
|
// Update the user on all routes and controllers
|
|
this.container.unregister('user:current');
|
|
this.container.register('user:current', user, { instantiate: false });
|
|
|
|
this.container.injection('route', 'user', 'user:current');
|
|
this.container.injection('controller', 'user', 'user:current');
|
|
|
|
this.set('user', user);
|
|
this.set('controller.user', user);
|
|
},
|
|
|
|
signedOut: function () {
|
|
// Nullify the user on all routes and controllers
|
|
this.container.unregister('user:current');
|
|
this.container.register('user:current', null, { instantiate: false });
|
|
|
|
this.container.injection('route', 'user', 'user:current');
|
|
this.container.injection('controller', 'user', 'user:current');
|
|
|
|
this.set('user', null);
|
|
this.set('controller.user', null);
|
|
},
|
|
|
|
openModal: function (modalName, model, type) {
|
|
modalName = 'modals/' + modalName;
|
|
// We don't always require a modal to have a controller
|
|
// so we're skipping asserting if one exists
|
|
if (this.controllerFor(modalName, true)) {
|
|
this.controllerFor(modalName).set('model', model);
|
|
|
|
if (type) {
|
|
this.controllerFor(modalName).set('imageType', type);
|
|
this.controllerFor(modalName).set('src', model.get(type));
|
|
}
|
|
}
|
|
return this.render(modalName, {
|
|
into: 'application',
|
|
outlet: 'modal'
|
|
});
|
|
},
|
|
|
|
closeModal: function () {
|
|
return this.disconnectOutlet({
|
|
outlet: 'modal',
|
|
parentView: 'application'
|
|
});
|
|
},
|
|
|
|
handleErrors: function (errors) {
|
|
var self = this;
|
|
this.notifications.clear();
|
|
errors.forEach(function (errorObj) {
|
|
self.notifications.showError(errorObj.message || errorObj);
|
|
|
|
if (errorObj.hasOwnProperty('el')) {
|
|
errorObj.el.addClass('input-error');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
export default ApplicationRoute;
|