Ghost/ghost/admin/initializers/current-user.js
Manuel Mitasch b1b15afc5e Ember.js: User fixtures + injection + login
* Adding **user fixtures** for signin

* Adds an initializer for the **current logged in user**.
The created singleton object is injected into all controllers + routes.
It can be used inside routes + controllers with this.get('user').
For simple development the object is instanciated with a userFixture.
Once a proper login and api mock is in place, the fixture needs to be removed.

* Added **route 'login'** on url '/ghost/ember/signin'
* Added authenticated route with an error hook that redirects to the login route, if status 401 (unauthorized) is returned from REST API.
* All "secure" routes now extend from authenticated route
* Add /ghost/ember to noAuthNeeded routes in middleware
2014-03-12 19:26:47 +01:00

26 lines
738 B
JavaScript

import userFixtures from 'ghost/fixtures/users';
var currentUser = {
name: 'currentUser',
initialize: function (container) {
var userFixture = userFixtures.findBy("id", 1);
container.register('user:current', Ember.Object.extend(userFixture));
// Todo: remove userFixture
// Todo: use model User instead of Ember.Object once model layer exists
}
};
var injectCurrentUser = {
name: 'injectCurrentUser',
initialize: function (container) {
if (container.lookup('user:current')) {
container.injection('route', 'user', 'user:current');
container.injection('controller', 'user', 'user:current');
}
}
};
export {currentUser, injectCurrentUser};