Replace Ember app with Mithril app

This commit is contained in:
Toby Zerner
2015-04-25 22:28:39 +09:30
parent 6f67b8c247
commit b68a4711dc
377 changed files with 5641 additions and 7330 deletions

41
js/lib/session.js Normal file
View File

@ -0,0 +1,41 @@
import mixin from 'flarum/utils/mixin';
import evented from 'flarum/utils/evented';
export default class Session extends mixin(class {}, evented) {
constructor() {
super();
this.user = m.prop();
this.token = m.prop();
}
login(identification, password) {
var deferred = m.deferred();
var self = this;
m.request({
method: 'POST',
url: app.config.baseURL+'/login',
data: {identification, password},
background: true
}).then(function(response) {
self.token(response.token);
m.startComputation();
app.store.find('users', response.userId).then(function(user) {
self.user(user);
deferred.resolve(user);
self.trigger('loggedIn', user);
m.endComputation();
});
}, function(response) {
deferred.reject(response);
});
return deferred.promise;
}
logout() {
window.location = app.config.baseURL+'/logout';
}
authorize(xhr) {
xhr.setRequestHeader('Authorization', 'Token '+this.token());
}
}