mirror of
https://github.com/flarum/core.git
synced 2025-08-03 15:07:53 +02:00
Improve email changing/confirmation stuff
This commit is contained in:
@@ -5,21 +5,39 @@ export default class ChangeEmailModal extends FormModal {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.success = m.prop(false);
|
||||
this.email = m.prop(app.session.user().email());
|
||||
}
|
||||
|
||||
view() {
|
||||
if (this.success()) {
|
||||
var emailProviderName = this.email().split('@')[1];
|
||||
}
|
||||
var disabled = this.loading();
|
||||
|
||||
return super.view({
|
||||
className: 'modal-sm change-email-modal',
|
||||
title: 'Change Email',
|
||||
body: [
|
||||
m('div.form-group', [
|
||||
m('input.form-control[type=email][name=email][placeholder=Email]', {value: this.email(), onchange: m.withAttr('value', this.email)})
|
||||
]),
|
||||
m('div.form-group', [
|
||||
m('button.btn.btn-primary.btn-block[type=submit]', 'Save Changes')
|
||||
])
|
||||
]
|
||||
body: this.success()
|
||||
? [
|
||||
m('p.help-text', 'We\'ve sent a confirmation email to ', m('strong', this.email()), '. If it doesn\'t arrive soon, check your spam folder.'),
|
||||
m('div.form-group', [
|
||||
m('a.btn.btn-primary.btn-block', {href: 'http://'+emailProviderName}, 'Go to '+emailProviderName)
|
||||
])
|
||||
]
|
||||
: [
|
||||
m('div.form-group', [
|
||||
m('input.form-control[type=email][name=email]', {
|
||||
placeholder: app.session.user().email(),
|
||||
value: this.email(),
|
||||
onchange: m.withAttr('value', this.email),
|
||||
disabled
|
||||
})
|
||||
]),
|
||||
m('div.form-group', [
|
||||
m('button.btn.btn-primary.btn-block[type=submit]', {disabled}, 'Save Changes')
|
||||
])
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,12 +51,13 @@ export default class ChangeEmailModal extends FormModal {
|
||||
|
||||
this.loading(true);
|
||||
app.session.user().save({ email: this.email() }).then(() => {
|
||||
this.hide();
|
||||
this.loading(false);
|
||||
this.success(true);
|
||||
this.alert(null);
|
||||
m.redraw();
|
||||
}, response => {
|
||||
this.loading(false);
|
||||
this.alert = new Alert({ type: 'warning', message: response.errors.map((error, k) => [error.detail, k < response.errors.length - 1 ? m('br') : '']) });
|
||||
m.redraw();
|
||||
this.$('[name='+response.errors[0].path+']').select();
|
||||
this.handleErrors(response.errors);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user