Advertisement
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')
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement