Migrate Login modal to use components

This commit is contained in:
Robin Ward 2016-11-15 16:18:33 -05:00
parent 684b3805fd
commit bf49c38faf
4 changed files with 88 additions and 92 deletions

View File

@ -0,0 +1,26 @@
export default Ember.Component.extend({
didInsertElement() {
this._super();
const prefillUsername = $('#hidden-login-form input[name=username]').val();
if (prefillUsername) {
this.set('loginName', prefillUsername);
this.set('loginPassword', $('#hidden-login-form input[name=password]').val());
} else if ($.cookie('email')) {
this.set('loginName', $.cookie('email'));
}
Ember.run.schedule('afterRender', function() {
$('#login-account-password, #login-account-name').keydown(e => {
if (e.keyCode === 13) {
this.sendAction();
}
});
});
},
mouseMove(e) {
this.set('screenX', e.screenX);
this.set('screenY', e.screenY);
}
});

View File

@ -51,8 +51,9 @@ export default Ember.Controller.extend(ModalFunctionality, {
}.property('loggingIn', 'authenticate'),
actions: {
login: function() {
login() {
const self = this;
if (this.get('loginDisabled')) { return; }
if(Ember.isEmpty(this.get('loginName')) || Ember.isEmpty(this.get('loginPassword'))){
self.flash(I18n.t('login.blank_username_or_password'), 'error');

View File

@ -1,4 +1,5 @@
<div class="modal-body">
{{#login-modal screenX=lastX screenY=lastY loginName=loginName loginPassword=loginPassword action="login"}}
{{#d-modal-body title="login.title" class="login-modal"}}
{{login-buttons action="externalLogin"}}
{{#if canLoginLocal}}
<form id='login-form' method='post'>
@ -35,7 +36,8 @@
{{/if}}
{{authMessage}}
<div id='login-alert' class={{alertClass}}>{{alert}}</div>
</div>
{{/d-modal-body}}
<div class="modal-footer">
{{#if canLoginLocal}}
<button class="btn btn-large btn-primary"
@ -58,3 +60,4 @@
{{conditional-loading-spinner condition=showSpinner size="small"}}
</div>
{{/login-modal}}

View File

@ -1,34 +0,0 @@
import ModalBodyView from "discourse/views/modal-body";
export default ModalBodyView.extend({
templateName: 'modal/login',
title: I18n.t('login.title'),
classNames: ['login-modal'],
mouseMove: function(e) {
this.set('controller.lastX', e.screenX);
this.set('controller.lastY', e.screenY);
},
_setup: function() {
const loginController = this.get('controller');
// Get username and password from the browser's password manager,
// if it filled the hidden static login form:
var prefillUsername = $('#hidden-login-form input[name=username]').val();
if (prefillUsername) {
loginController.set('loginName', prefillUsername);
loginController.set('loginPassword', $('#hidden-login-form input[name=password]').val());
} else if ($.cookie('email')) {
loginController.set('loginName', $.cookie('email'));
}
Em.run.schedule('afterRender', function() {
$('#login-account-password, #login-account-name').keydown(function(e) {
if (e.keyCode === 13 && !loginController.get('loginDisabled')) {
loginController.send('login');
}
});
});
}.on('didInsertElement')
});