Skip to content

Commit

Permalink
Adding ability for site admin to switch 2fa on or off site-wide
Browse files Browse the repository at this point in the history
  • Loading branch information
kbwhizz committed Oct 11, 2024
1 parent aee54b0 commit c9fe937
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/Http/RequestHandlers/AccountEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Services\MessageService;
use Fisharebest\Webtrees\Services\ModuleService;
use Fisharebest\Webtrees\Site;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\Validator;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -83,6 +84,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
});

$show_delete_option = $user->getPreference(UserInterface::PREF_IS_ADMINISTRATOR) !== '1';
$show_2fa = Site::getPreference('SHOW_2FA_OPTION') === '1';
$timezone_ids = DateTimeZone::listIdentifiers();
$timezones = array_combine($timezone_ids, $timezone_ids);
$title = I18N::translate('My account');
Expand All @@ -93,6 +95,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
'languages' => $languages->all(),
'my_individual_record' => $my_individual_record,
'show_delete_option' => $show_delete_option,
'show_2fa' => $show_2fa,
'timezones' => $timezones,
'title' => $title,
'tree' => $tree,
Expand Down
2 changes: 2 additions & 0 deletions app/Http/RequestHandlers/SiteRegistrationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$text = Validator::parsedBody($request)->string('WELCOME_TEXT_AUTH_MODE_4');
$allow_registration = Validator::parsedBody($request)->boolean('USE_REGISTRATION_MODULE');
$show_caution = Validator::parsedBody($request)->boolean('SHOW_REGISTER_CAUTION');
$show_2fa = Validator::parsedBody($request)->boolean('SHOW_2FA_OPTION');

Site::setPreference('WELCOME_TEXT_AUTH_MODE', $mode);
Site::setPreference('WELCOME_TEXT_AUTH_MODE_' . I18N::languageTag(), $text);
Site::setPreference('USE_REGISTRATION_MODULE', (string) $allow_registration);
Site::setPreference('SHOW_REGISTER_CAUTION', (string) $show_caution);
Site::setPreference('SHOW_2FA_OPTION', (string) $show_2fa);

FlashMessages::addMessage(I18N::translate('The website preferences have been updated.'), 'success');

Expand Down
13 changes: 13 additions & 0 deletions resources/views/admin/site-registration.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ use Fisharebest\Webtrees\Site;
</div>
</fieldset>

<!-- ALLOW USERS TO SET UP 2FA -->
<fieldset class="row mb-3">
<legend class="col-form-label col-sm-3">
<?= /* I18N: A configuration setting */ I18N::translate('Allow user
to turn on or off two-factor authentication from My Account page') ?>
</legend>
<div class="col-sm-9">
<?= view('components/radios-inline', ['name' => 'SHOW_2FA_OPTION', 'options' => [I18N::translate('no'), I18N::translate('yes')], 'selected' => (int) Site::getPreference('SHOW_2FA_OPTION')]) ?>
<div class="form-text">
</div>
</div>
</fieldset>

<div class="row mb-3">
<div class="offset-sm-3 col-sm-9">
<button type="submit" class="btn btn-primary">
Expand Down
3 changes: 3 additions & 0 deletions resources/views/edit-account-page.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use Fisharebest\Webtrees\Tree;
* @var array<string,string> $languages
* @var Individual|null $my_individual_record
* @var bool $show_delete_option
* @var bool $show_2fa
* @var array<string,string> $timezones
* @var string $title
* @var Tree|null $tree
Expand Down Expand Up @@ -153,6 +154,7 @@ use Fisharebest\Webtrees\Tree;
</div>
</div>
</fieldset>
<?php if ($show_2fa) : ?>
<fieldset class="row">
<legend class="col-sm-3 col-form-label wt-page-options-label">
<?= I18N::translate('2FA status') ?>
Expand All @@ -164,6 +166,7 @@ use Fisharebest\Webtrees\Tree;
</div>
</div>
</fieldset>
<?php endif ?>
<div class="row" id="qrcode">
<?php $qrc = $user->genQRcode(); ?>
<input type="hidden" name="secret" id="secret" value="">
Expand Down

0 comments on commit c9fe937

Please sign in to comment.