1
0
mirror of https://github.com/flarum/core.git synced 2025-07-24 18:21:33 +02:00

Signup + modal refactoring

This commit is contained in:
Toby Zerner
2015-02-08 15:59:39 +10:30
parent 6c3debc79b
commit d45f2fd1ac
14 changed files with 193 additions and 69 deletions

View File

@@ -1,10 +1,12 @@
import Ember from 'ember';
import AuthenticationControllerMixin from 'simple-auth/mixins/authentication-controller-mixin';
import ModalControllerMixin from '../mixins/modal-controller';
export default Ember.Controller.extend(AuthenticationControllerMixin, {
export default Ember.Controller.extend(ModalControllerMixin, AuthenticationControllerMixin, {
authenticator: 'authenticator:flarum',
loading: false,
actions: {
authenticate: function() {
@@ -14,7 +16,8 @@ export default Ember.Controller.extend(AuthenticationControllerMixin, {
this.set('loading', true);
return this._super(data).then(function() {
controller.send("sessionChanged");
}).catch(function(errors) {
controller.send("closeModal");
}, function(errors) {
switch(errors[0].code) {
case 'invalidLogin':
controller.set('error', 'Your login details are incorrect.');
@@ -23,10 +26,11 @@ export default Ember.Controller.extend(AuthenticationControllerMixin, {
default:
controller.set('error', 'Something went wrong. (Error code: '+errors[0].code+')');
}
controller.trigger('refocus');
}).finally(function() {
controller.set('loading', false);
});
}
}
});
});

View File

@@ -0,0 +1,33 @@
import Ember from 'ember';
import AuthenticationControllerMixin from 'simple-auth/mixins/authentication-controller-mixin';
import ModalControllerMixin from '../mixins/modal-controller';
export default Ember.Controller.extend(ModalControllerMixin, AuthenticationControllerMixin, {
authenticator: 'authenticator:flarum',
actions: {
submit: function() {
var data = this.getProperties('username', 'email', 'password');
var controller = this;
this.set('error', null);
this.set('loading', true);
var user = this.store.createRecord('user', data);
return user.save().then(function() {
controller.get('session').authenticate('authenticator:flarum', {
identification: data.email,
password: data.password
}).then(function() {
controller.send('closeModal');
controller.send('sessionChanged');
controller.set('loading', false);
});
}, function(reason) {
controller.set('loading', false);
});
}
}
});