Readme, quick bootstrapping, login, ember-data check
sdfsdf
This commit is contained in:
parent
978dacb16e
commit
0e16d2b0f4
22 changed files with 189 additions and 9 deletions
47
app/authenticators/custom.js
Normal file
47
app/authenticators/custom.js
Normal 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();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
});
|
Reference in a new issue