From 3cd59e12f575ff21ed0de32a2fd677e953ddcfe4 Mon Sep 17 00:00:00 2001 From: renyuneyun Date: Fri, 3 Feb 2017 20:13:32 +0000 Subject: [PATCH] Allow to manually activate users (#1093) * Allow to manually activate users * Use resources instead of hard-coded strings --- js/forum/src/components/EditUserModal.js | 39 +++++++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/js/forum/src/components/EditUserModal.js b/js/forum/src/components/EditUserModal.js index 1d9697932..a7251b9d4 100644 --- a/js/forum/src/components/EditUserModal.js +++ b/js/forum/src/components/EditUserModal.js @@ -15,6 +15,7 @@ export default class EditUserModal extends Modal { this.username = m.prop(user.username() || ''); this.email = m.prop(user.email() || ''); + this.isActivated = m.prop(user.isActivated() || false); this.setPassword = m.prop(false); this.password = m.prop(user.password() || ''); this.groups = {}; @@ -37,22 +38,32 @@ export default class EditUserModal extends Modal {
- +
{app.session.user !== this.props.user ? [
- +
+ {!this.isActivated() ? ( +
+ {Button.component({ + className: 'Button Button--block', + children: app.translator.trans('core.forum.edit_user.activate_button'), + loading: this.loading, + onclick: this.activate.bind(this) + })} +
+ ) : ''}
,
- +
{this.setPassword() ? ( - +
{Object.keys(this.groups) .map(id => app.store.getById('groups', id)) @@ -100,6 +111,24 @@ export default class EditUserModal extends Modal { ); } + activate() { + this.loading = true; + const data = { + username: this.username(), + isActivated: true, + }; + this.props.user.save(data, {errorHandler: this.onerror.bind(this)}) + .then(() => { + this.isActivated(true); + this.loading = false; + m.redraw(); + }) + .catch(() => { + this.loading = false; + m.redraw(); + }); + } + data() { const groups = Object.keys(this.groups) .filter(id => this.groups[id]())