-
Notifications
You must be signed in to change notification settings - Fork 13
/
pretzel-local.js
50 lines (46 loc) · 1.27 KB
/
pretzel-local.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import Ember from 'ember';
import Base from 'ember-simple-auth/authenticators/base';
export default Base.extend({
restore: function(data) {
return new Ember.RSVP.Promise(function(resolve, reject){
if(!Ember.isEmpty(data.token)) {
resolve(data);
} else {
reject();
}
});
},
authenticate: function(identification, password) {
let config = Ember.getOwner(this).resolveRegistration('config:environment')
let endpoint = config.apiHost + '/api/Clients/login'
return new Ember.RSVP.Promise((resolve, reject) => {
Ember.$.ajax({
url: endpoint,
type: 'POST',
crossDomain: true,
data: JSON.stringify({
email: identification,
password: password
}),
accept: 'application/json',
contentType: 'application/json'
}).then(function(response){
// console.log(response)
Ember.run(function(){
resolve({
token: response.id,
clientId: response.userId
});
});
}, function(xhr, status, error) {
var response = xhr.responseText;
Ember.run(function(){
reject(response);
});
});
});
},
invalidate: function() {
return Ember.RSVP.resolve();
}
});