mirror of
https://github.com/flarum/framework.git
synced 2024-12-04 08:13:39 +08:00
Tweak user email confirmation alert
- Make sure is_activated is serialized to a bool (otherwise "0" will evaluate to true) - Remove "error" class from message so it's more friendly - Make the alert more prominent by mounting it into a new div at the top of the page - Add loading UX to the resend button
This commit is contained in:
parent
41cb9ea32e
commit
07f38afc4d
55
framework/core/js/forum/dist/app.js
vendored
55
framework/core/js/forum/dist/app.js
vendored
|
@ -28386,32 +28386,67 @@ System.register('flarum/helpers/userOnline', ['flarum/helpers/icon'], function (
|
||||||
});;
|
});;
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
System.register('flarum/initializers/alertEmailConfirmation', ['flarum/components/Alert', 'flarum/components/Button'], function (_export, _context) {
|
System.register('flarum/initializers/alertEmailConfirmation', ['flarum/components/Alert', 'flarum/components/Button', 'flarum/helpers/icon'], function (_export, _context) {
|
||||||
var Alert, Button;
|
var Alert, Button, icon;
|
||||||
function alertEmailConfirmation(app) {
|
function alertEmailConfirmation(app) {
|
||||||
var user = app.session.user;
|
var user = app.session.user;
|
||||||
|
|
||||||
if (!user || user.isActivated()) return;
|
if (!user || user.isActivated()) return;
|
||||||
|
|
||||||
var alert = void 0;
|
|
||||||
|
|
||||||
var resendButton = Button.component({
|
var resendButton = Button.component({
|
||||||
className: 'Button Button--link',
|
className: 'Button Button--link',
|
||||||
children: app.translator.trans('core.forum.user_confirmation.resend_button'),
|
children: app.translator.trans('core.forum.user_email_confirmation.resend_button'),
|
||||||
onclick: function onclick() {
|
onclick: function onclick() {
|
||||||
|
resendButton.props.loading = true;
|
||||||
|
m.redraw();
|
||||||
|
|
||||||
app.request({
|
app.request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: app.forum.attribute('apiUrl') + '/users/' + user.id() + '/send-confirmation'
|
url: app.forum.attribute('apiUrl') + '/users/' + user.id() + '/send-confirmation'
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
return app.alerts.dismiss(alert);
|
resendButton.props.loading = false;
|
||||||
|
resendButton.props.children = [icon('check'), ' ', app.translator.trans('core.forum.user_email_confirmation.sent_message')];
|
||||||
|
resendButton.props.disabled = true;
|
||||||
|
m.redraw();
|
||||||
|
}).catch(function () {
|
||||||
|
resendButton.props.loading = false;
|
||||||
|
m.redraw();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.alerts.show(alert = new Alert({
|
var ContainedAlert = function (_Alert) {
|
||||||
type: 'error',
|
babelHelpers.inherits(ContainedAlert, _Alert);
|
||||||
|
|
||||||
|
function ContainedAlert() {
|
||||||
|
babelHelpers.classCallCheck(this, ContainedAlert);
|
||||||
|
return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(ContainedAlert).apply(this, arguments));
|
||||||
|
}
|
||||||
|
|
||||||
|
babelHelpers.createClass(ContainedAlert, [{
|
||||||
|
key: 'view',
|
||||||
|
value: function view() {
|
||||||
|
var vdom = babelHelpers.get(Object.getPrototypeOf(ContainedAlert.prototype), 'view', this).call(this);
|
||||||
|
|
||||||
|
vdom.children = [m(
|
||||||
|
'div',
|
||||||
|
{ className: 'container' },
|
||||||
|
vdom.children
|
||||||
|
)];
|
||||||
|
|
||||||
|
return vdom;
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
return ContainedAlert;
|
||||||
|
}(Alert);
|
||||||
|
|
||||||
|
m.mount($('<div/>').insertBefore('#content')[0], ContainedAlert.component({
|
||||||
dismissible: false,
|
dismissible: false,
|
||||||
children: app.translator.trans('core.forum.user_confirmation.alert_message'),
|
children: app.translator.trans('core.forum.user_email_confirmation.alert_message', { email: m(
|
||||||
|
'strong',
|
||||||
|
null,
|
||||||
|
user.email()
|
||||||
|
) }),
|
||||||
controls: [resendButton]
|
controls: [resendButton]
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -28423,6 +28458,8 @@ System.register('flarum/initializers/alertEmailConfirmation', ['flarum/component
|
||||||
Alert = _flarumComponentsAlert.default;
|
Alert = _flarumComponentsAlert.default;
|
||||||
}, function (_flarumComponentsButton) {
|
}, function (_flarumComponentsButton) {
|
||||||
Button = _flarumComponentsButton.default;
|
Button = _flarumComponentsButton.default;
|
||||||
|
}, function (_flarumHelpersIcon) {
|
||||||
|
icon = _flarumHelpersIcon.default;
|
||||||
}],
|
}],
|
||||||
execute: function () {}
|
execute: function () {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import Alert from 'flarum/components/Alert';
|
import Alert from 'flarum/components/Alert';
|
||||||
import Button from 'flarum/components/Button';
|
import Button from 'flarum/components/Button';
|
||||||
|
import icon from 'flarum/helpers/icon';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `alertEmailConfirmation` initializer shows an Alert if loggend in
|
* Shows an alert if the user has not yet confirmed their email address.
|
||||||
* user's email is not confirmed
|
|
||||||
*
|
*
|
||||||
* @param {ForumApp} app
|
* @param {ForumApp} app
|
||||||
*/
|
*/
|
||||||
|
@ -12,24 +12,43 @@ export default function alertEmailConfirmation(app) {
|
||||||
|
|
||||||
if (!user || user.isActivated()) return;
|
if (!user || user.isActivated()) return;
|
||||||
|
|
||||||
let alert;
|
|
||||||
|
|
||||||
const resendButton = Button.component({
|
const resendButton = Button.component({
|
||||||
className: 'Button Button--link',
|
className: 'Button Button--link',
|
||||||
children: app.translator.trans('core.forum.user_confirmation.resend_button'),
|
children: app.translator.trans('core.forum.user_email_confirmation.resend_button'),
|
||||||
onclick: () => {
|
onclick: function() {
|
||||||
|
resendButton.props.loading = true;
|
||||||
|
m.redraw();
|
||||||
|
|
||||||
app.request({
|
app.request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: app.forum.attribute('apiUrl') + '/users/' + user.id() + '/send-confirmation',
|
url: app.forum.attribute('apiUrl') + '/users/' + user.id() + '/send-confirmation',
|
||||||
}).then(() => app.alerts.dismiss(alert));
|
}).then(() => {
|
||||||
|
resendButton.props.loading = false;
|
||||||
|
resendButton.props.children = [icon('check'), ' ', app.translator.trans('core.forum.user_email_confirmation.sent_message')];
|
||||||
|
resendButton.props.disabled = true;
|
||||||
|
m.redraw();
|
||||||
|
}).catch(() => {
|
||||||
|
resendButton.props.loading = false;
|
||||||
|
m.redraw();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.alerts.show(
|
class ContainedAlert extends Alert {
|
||||||
alert = new Alert({
|
view() {
|
||||||
type: 'error',
|
const vdom = super.view();
|
||||||
|
|
||||||
|
vdom.children = [<div className="container">{vdom.children}</div>];
|
||||||
|
|
||||||
|
return vdom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.mount(
|
||||||
|
$('<div/>').insertBefore('#content')[0],
|
||||||
|
ContainedAlert.component({
|
||||||
dismissible: false,
|
dismissible: false,
|
||||||
children: app.translator.trans('core.forum.user_confirmation.alert_message'),
|
children: app.translator.trans('core.forum.user_email_confirmation.alert_message', {email: <strong>{user.email()}</strong>}),
|
||||||
controls: [resendButton]
|
controls: [resendButton]
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -20,7 +20,7 @@ class CurrentUserSerializer extends UserSerializer
|
||||||
$attributes = parent::getDefaultAttributes($user);
|
$attributes = parent::getDefaultAttributes($user);
|
||||||
|
|
||||||
$attributes += [
|
$attributes += [
|
||||||
'isActivated' => $user->is_activated,
|
'isActivated' => (bool) $user->is_activated,
|
||||||
'email' => $user->email,
|
'email' => $user->email,
|
||||||
'readTime' => $this->formatDate($user->read_time),
|
'readTime' => $this->formatDate($user->read_time),
|
||||||
'unreadNotificationsCount' => (int) $user->getUnreadNotificationsCount(),
|
'unreadNotificationsCount' => (int) $user->getUnreadNotificationsCount(),
|
||||||
|
|
|
@ -55,7 +55,7 @@ class UserSerializer extends UserBasicSerializer
|
||||||
|
|
||||||
if ($canEdit || $this->actor->id === $user->id) {
|
if ($canEdit || $this->actor->id === $user->id) {
|
||||||
$attributes += [
|
$attributes += [
|
||||||
'isActivated' => $user->is_activated,
|
'isActivated' => (bool) $user->is_activated,
|
||||||
'email' => $user->email
|
'email' => $user->email
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user