Readme, quick bootstrapping, login, ember-data check

sdfsdf
This commit is contained in:
Matthew Dillon 2015-01-12 16:41:36 -09:00
parent 978dacb16e
commit 0e16d2b0f4
22 changed files with 189 additions and 9 deletions

View file

@ -0,0 +1,47 @@
import Ember from 'ember';
import Base from 'simple-auth/authenticators/base';
export default Base.extend({
tokenEndpoint: '/api/authenticate',
restore: function(data) {
return new Ember.RSVP.Promise(function(resolve, reject) {
if (!Ember.isEmpty(data.token)) {
resolve(data);
} else {
reject();
}
});
},
authenticate: function(credentials) {
var _this = this;
return new Ember.RSVP.Promise(function(resolve, reject) {
Ember.$.ajax({
url: _this.tokenEndpoint,
type: 'POST',
data: {username: credentials.identification, password: credentials.password},
contentType: 'application/x-www-form-urlencoded'
}).then(function(response) {
Ember.run(function() {
resolve({ token: response.token });
});
}, function(xhr, status, error) {
var response = JSON.parse(xhr.responseText);
Ember.run(function() {
reject(response.error);
});
});
});
},
invalidate: function(data) {
var _this = this;
return new Ember.RSVP.Promise(function(resolve) {
Ember.$.ajax({ url: _this.tokenEndpoint, type: 'DELETE' }).always(function() {
resolve();
});
});
},
});