Skip to content

Instantly share code, notes, and snippets.

@ultimatemonty
Last active August 29, 2015 14:15
Show Gist options
  • Save ultimatemonty/372b1d405a65dd871735 to your computer and use it in GitHub Desktop.
Save ultimatemonty/372b1d405a65dd871735 to your computer and use it in GitHub Desktop.
currentUser into routes and controllers via Session
App.AppSession = SimpleAuth.Session.extend({
currentUser: Ember.computed('userId', function () {
var userId = this.get('userId');
if (!Ember.isEmpty(userId)) {
return this.container.lookup('store:main').find('user', userId);
}
})
});
App.ApplicationRoute = Ember.Route.extend({
currentUser: Ember.computed.alias(this.get('session.currentUser'));
});
/*
* Ember Simple Auth ServiceStack CredentialsProvider Authenticator and Authorizer
*/
Ember.Application.initializer({
name: 'simple-auth-servicestack',
before: 'simple-auth',
initialize: function(container, application) {
container.register('session:custom', App.AppSession);
container.register('authorizer:servicestack', App.SimpleAuthServiceStackCredentialAuthorizer);
container.register('authenticator:servicestack', App.SimpleAuthServiceStackCredentialAuthenticator);
// Init the ENV var
window.ENV = window.ENV || {};
// Simple Auth config
window.ENV['simple-auth'] = {
session: 'session:custom',
authenticationRoute: 'login',
routeAfterAuthentication: 'application.home',
routeIfAlreadyAuthenticated: 'application.home',
store: 'simple-auth-session-store:cookie',
authorizer: 'authorizer:servicestack'
};
}
});
App.User = DS.Model.extend({
uniqueId: string,
userName: string,
password: string,
firstName: string,
lastName: string,
emailAddress: string,
employeeNumber: string,
department: string,
jobPosition: string,
isActive: bool,
clearActivation: bool,
activationId: string,
activationExpires: string,
profilePictureUrl: string,
passwordResetId: string,
passwordReset: bool,
clearPasswordReset: bool,
lastPasswordResetBy: DS.belongsTo('user', { async: true, inverse: null }),
lastPasswordResetDate: string,
createdBy: DS.belongsTo('user', { async: true, inverse: null }),
createdDate: string,
modifiedBy: DS.belongsTo('user', { async: true, inverse: null }),
modifiedDate: string,
// soft delete
isDeletedFromApplication: bool,
deletedBy: DS.belongsTo('user', { async: true, inverse: null }),
deletedDate: string
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment