Skip to content

Commit

Permalink
feat: reset count
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Nov 8, 2023
1 parent 0222971 commit b1bf9a5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 30 deletions.
11 changes: 10 additions & 1 deletion extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@
namespace SychO\ForcePasswordReset;

use Flarum\Extend;
use Flarum\Frontend\Document;
use Flarum\User\Event\PasswordChanged;
use Flarum\User\User;

return [
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),
->js(__DIR__.'/js/dist/admin.js')
->css(__DIR__.'/less/admin.less'),

new Extend\Locales(__DIR__.'/locale'),

(new Extend\Frontend('admin'))
->content(function (Document $document) {
$document->payload['sycho-force-password-reset.reset-done-count'] = User::query()
->whereNotNull('password_reset_at')
->count();
}),

(new Extend\Model(User::class))
->cast('required_password_reset_at', 'datetime')
->cast('password_reset_at', 'datetime'),
Expand Down
73 changes: 44 additions & 29 deletions js/src/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,48 @@ import Button from 'flarum/common/components/Button';
import extractText from 'flarum/common/utils/extractText';

app.initializers.add('sycho/flarum-force-password-reset', () => {
app.extensionData.for('sycho-force-password-reset').registerSetting(() => (
<div className="Form-group">
<label>{app.translator.trans('sycho-force-password-reset.admin.force_password_reset.title')}</label>
<p className="helpText">{app.translator.trans('sycho-force-password-reset.admin.force_password_reset.description')}</p>
<Button
className="Button"
icon="fas fa-key"
onclick={() => {
if (confirm(extractText(app.translator.trans('sycho-force-password-reset.admin.force_password_reset.reset_all_confirm')))) {
app
.request({
method: 'POST',
url: app.forum.attribute('apiUrl') + '/force-password-reset',
})
.then(() =>
app.alerts.show(
{
type: 'success',
},
app.translator.trans('sycho-force-password-reset.admin.force_password_reset.reset_all_success')
)
);
}
}}
>
{app.translator.trans('sycho-force-password-reset.admin.force_password_reset.button_label')}
</Button>
</div>
));
app.extensionData
.for('sycho-force-password-reset')
.registerSetting(() => (
<div className="Form-group">
<label>{app.translator.trans('sycho-force-password-reset.admin.force_password_reset.title')}</label>
<p className="helpText">{app.translator.trans('sycho-force-password-reset.admin.force_password_reset.description')}</p>
<Button
className="Button"
icon="fas fa-key"
onclick={() => {
if (confirm(extractText(app.translator.trans('sycho-force-password-reset.admin.force_password_reset.reset_all_confirm')))) {
app
.request({
method: 'POST',
url: app.forum.attribute('apiUrl') + '/force-password-reset',
})
.then(() =>
app.alerts.show(
{
type: 'success',
},
app.translator.trans('sycho-force-password-reset.admin.force_password_reset.reset_all_success')
)
);
}
}}
>
{app.translator.trans('sycho-force-password-reset.admin.force_password_reset.button_label')}
</Button>
</div>
))
.registerSetting(() => (
<div className="Form-group ForceResetPassword-resetCount">
<label>{app.translator.trans('sycho-force-password-reset.admin.reset_count.title')}</label>
<p className="helpText">{app.translator.trans('sycho-force-password-reset.admin.reset_count.description')}</p>
<span className="ForceResetPassword-resetCount-value">
{app.translator.trans('sycho-force-password-reset.admin.reset_count.value', {
count: new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).format(
app.data['sycho-force-password-reset.reset-done-count'] as number
),
})}
</span>
</div>
));
});
3 changes: 3 additions & 0 deletions less/admin.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.ForceResetPassword-resetCount-value {
font-family: monospace;
}
Empty file removed less/forum.less
Empty file.
4 changes: 4 additions & 0 deletions locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ sycho-force-password-reset:
button_label: "Force Password Reset"
reset_all_confirm: "Are you sure you want to force all users to reset their password on next login?"
reset_all_success: "All users will be forced to reset their password on next login."
reset_count:
title: "Reset Count"
description: "The number of users who have successfully reset their password since the last time it was force required."
value: "{count} users"

forum:
current_password_label: "Current Password"
Expand Down

0 comments on commit b1bf9a5

Please sign in to comment.