Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h2>Welcome back, {{session.user}}</h2>
- authenticate: function(credentials) {
- var _this = this;
- return new Ember.RSVP.Promise(function(resolve, reject) {
- Ember.$.ajax({
- url: _this.tokenEndpoint,
- type: 'POST',
- data: JSON.stringify({username: credentials.identification, password: credentials.password }),
- contentType: 'application/json'
- }).then(function(response) {
- Ember.run(function() {
- resolve({
- token: response.token,
- username: credentials.identification
- });
- });
- }, function(xhr, status, error) {
- var response = JSON.parse(xhr.responseText);
- Ember.run(function() {
- reject(response.error);
- });
- });
- });
- },
- Ember.Application.initializer({
- name: 'authentication',
- before: 'simple-auth',
- initialize: function(container, application) {
- // register the custom authenticator and authorizer so Ember Simple Auth can find them
- container.register('authenticator:custom', App.CustomAuthenticator);
- container.register('authorizer:custom', App.CustomAuthorizer);
- SimpleAuth.Session.reopen({
- user: function() {
- var username = this.get('username');
- if (!Ember.isEmpty(username)) {
- return container.lookup('store:main').find('user', {username: username});
- }
- }.property('username')
- });
- }
- });
- App.CustomSession = SimpleAuth.Session.extend({
- account: function() {
- var accountId = this.get('account_id');
- if (!Ember.isEmpty(accountId)) {
- return this.container.lookup('store:main').find('account', accountId);
- }
- }.property('account_id')
- });
- …
- container.register('session:custom', App.CustomSession);
- …
- window.ENV['simple-auth'] = {
- session: 'session:custom',
- }
- window.ENV['simple-auth'] = {
- authorizer: 'simple-auth-authorizer:devise',
- session: 'session:withCurrentUser'
- };
- import Session from 'simple-auth/session';
- var SessionWithCurrentUser = Session.extend({
- currentUser: function() {
- var userId = this.get('user_id');
- if (!Ember.isEmpty(userId)) {
- return this.container.lookup('store:main').find('user', userId);
- }
- }.property('user_id')
- });
- export default {
- name: 'customize-session',
- initialize: function(container) {
- container.register('session:withCurrentUser', SessionWithCurrentUser);
- }
- };
Add Comment
Please, Sign In to add comment