mirror of
https://github.com/flarum/core.git
synced 2025-07-31 13:40:20 +02:00
Add ember-simple-auth, setup login
- Allow dropdown-buttons to render a partial
This commit is contained in:
37
ember/app/authenticators/flarum.js
Normal file
37
ember/app/authenticators/flarum.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import Base from 'simple-auth/authenticators/base';
|
||||
import config from '../config/environment';
|
||||
|
||||
export default Base.extend({
|
||||
|
||||
restore: function(data) {
|
||||
var container = this.container;
|
||||
return new Ember.RSVP.Promise(function(resolve, reject) {
|
||||
Ember.run.next(function() {
|
||||
container.lookup('store:main').find('user', data.userId).then(function(user) {
|
||||
resolve( { token: data.token, userId: data.userId, user: user } );
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
authenticate: function(credentials) {
|
||||
var container = this.container;
|
||||
return new Ember.RSVP.Promise(function(resolve, reject) {
|
||||
Ember.$.ajax({
|
||||
url: config.apiURL+'/auth/login',
|
||||
type: 'POST',
|
||||
data: { identification: credentials.identification, password: credentials.password }
|
||||
}).then(function(response) {
|
||||
container.lookup('store:main').find('user', response.userId).then(function(user) {
|
||||
resolve({ token: response.token, userId: response.userId, user: user });
|
||||
});
|
||||
}, function(xhr, status, error) {
|
||||
reject(xhr.responseJSON.errors);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// invalidate: function(data) {
|
||||
// return new Ember.RSVP.Promise();
|
||||
// }
|
||||
});
|
Reference in New Issue
Block a user