diff --git a/ember/app/controllers/login.js b/ember/app/controllers/login.js index dff3d2af0..7292fb853 100644 --- a/ember/app/controllers/login.js +++ b/ember/app/controllers/login.js @@ -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); }); } } -}); \ No newline at end of file +}); diff --git a/ember/app/controllers/signup.js b/ember/app/controllers/signup.js new file mode 100644 index 000000000..41b63f596 --- /dev/null +++ b/ember/app/controllers/signup.js @@ -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); + }); + } + } + +}); diff --git a/ember/app/mixins/modal-controller.js b/ember/app/mixins/modal-controller.js new file mode 100644 index 000000000..a63c75e3d --- /dev/null +++ b/ember/app/mixins/modal-controller.js @@ -0,0 +1,9 @@ +import Ember from 'ember'; + +export default Ember.Mixin.create(Ember.Evented, { + actions: { + focus: function() { + this.trigger('focus'); + } + } +}); diff --git a/ember/app/mixins/modal-view.js b/ember/app/mixins/modal-view.js new file mode 100644 index 000000000..5a390a01d --- /dev/null +++ b/ember/app/mixins/modal-view.js @@ -0,0 +1,16 @@ +import Ember from 'ember'; + +export default Ember.Mixin.create({ + focusEventOn: function() { + this.get('controller').on('focus', this, this.focus); + }.on('didInsertElement'), + + focusEventOff: function() { + this.get('controller').off('focus', this, this.focus); + }.on('willDestroyElement'), + + focus: function() { + this.$('input:first:visible:enabled').focus(); + console.log('focus first') + }.on('didInsertElement') +}); diff --git a/ember/app/models/user.js b/ember/app/models/user.js index c029005b6..5c5df3e73 100644 --- a/ember/app/models/user.js +++ b/ember/app/models/user.js @@ -14,6 +14,9 @@ export default DS.Model.extend({ groups: DS.hasMany('group'), + email: DS.attr('string'), + password: DS.attr('string'), + avatarNumber: function() { return Math.random() > 0.3 ? Math.floor(Math.random() * 19) + 1 : null; }.property() diff --git a/ember/app/routes/application.js b/ember/app/routes/application.js index 287e3c19f..0f993b3dd 100644 --- a/ember/app/routes/application.js +++ b/ember/app/routes/application.js @@ -6,22 +6,35 @@ export default Ember.Route.extend(ApplicationRouteMixin, { actions: { login: function() { this.controllerFor('login').set('error', null); - this.render('login', { + this.send('showModal', 'login'); + }, + + signup: function() { + this.controllerFor('signup').set('error', null); + this.send('showModal', 'signup'); + }, + + showModal: function(name) { + this.render(name, { into: 'application', outlet: 'modal' }); + this.controllerFor('application').set('modalController', this.controllerFor(name)); }, closeModal: function() { + this.controllerFor('application').set('modalController', null); + }, + + destroyModal: function() { this.disconnectOutlet({ outlet: 'modal', parentView: 'application' }); }, - sessionChanged: function() { + sessionChanged: function() { this.refresh(); - } + } } - -}); \ No newline at end of file +}); diff --git a/ember/app/styles/flarum/components.less b/ember/app/styles/flarum/components.less index e42af637a..921f2a12d 100644 --- a/ember/app/styles/flarum/components.less +++ b/ember/app/styles/flarum/components.less @@ -85,6 +85,9 @@ // ------------------------------------ // Form Controls +.form-group { + margin-bottom: 12px; +} .form-control { .box-shadow(none); &:focus, @@ -232,4 +235,4 @@ border-radius: 100%; vertical-align: top; } -} \ No newline at end of file +} diff --git a/ember/app/styles/flarum/login.less b/ember/app/styles/flarum/login.less index aae0c760c..e69de29bb 100644 --- a/ember/app/styles/flarum/login.less +++ b/ember/app/styles/flarum/login.less @@ -1,5 +0,0 @@ -.modal-login { - & .form-group { - margin-bottom: 12px; - } -} \ No newline at end of file diff --git a/ember/app/templates/login.hbs b/ember/app/templates/login.hbs index 6d444d85b..7649e459a 100644 --- a/ember/app/templates/login.hbs +++ b/ember/app/templates/login.hbs @@ -1,33 +1,31 @@ -