Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <h2>Welcome back, {{session.user}}</h2>
  2.  
  3. authenticate: function(credentials) {
  4. var _this = this;
  5. return new Ember.RSVP.Promise(function(resolve, reject) {
  6. Ember.$.ajax({
  7. url: _this.tokenEndpoint,
  8. type: 'POST',
  9. data: JSON.stringify({username: credentials.identification, password: credentials.password }),
  10. contentType: 'application/json'
  11. }).then(function(response) {
  12. Ember.run(function() {
  13. resolve({
  14. token: response.token,
  15. username: credentials.identification
  16. });
  17. });
  18. }, function(xhr, status, error) {
  19. var response = JSON.parse(xhr.responseText);
  20. Ember.run(function() {
  21. reject(response.error);
  22. });
  23. });
  24. });
  25. },
  26.  
  27. Ember.Application.initializer({
  28. name: 'authentication',
  29. before: 'simple-auth',
  30. initialize: function(container, application) {
  31. // register the custom authenticator and authorizer so Ember Simple Auth can find them
  32. container.register('authenticator:custom', App.CustomAuthenticator);
  33. container.register('authorizer:custom', App.CustomAuthorizer);
  34. SimpleAuth.Session.reopen({
  35. user: function() {
  36. var username = this.get('username');
  37. if (!Ember.isEmpty(username)) {
  38. return container.lookup('store:main').find('user', {username: username});
  39. }
  40. }.property('username')
  41. });
  42. }
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement