mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Added an button generate a new set of backup codes.
This commit is contained in:
parent
604ebe420d
commit
47fa8b04e5
2 changed files with 21 additions and 1 deletions
|
@ -33,7 +33,7 @@ use App\Services\EntityImporter;
|
|||
use App\Services\StructuralElementRecursionHelper;
|
||||
use App\Services\TFA\BackupCodeManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Util\Exception;
|
||||
use \Exception;
|
||||
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticator;
|
||||
use Symfony\Component\Asset\Packages;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
|
@ -291,6 +291,19 @@ class UserController extends AdminPages\BaseAdminController
|
|||
}
|
||||
}
|
||||
|
||||
$backup_form = $this->get('form.factory')->createNamedBuilder('backup_codes')->add('reset_codes', SubmitType::class,[
|
||||
'label' => 'tfa_backup.regenerate_codes',
|
||||
'attr' => ['class' => 'btn-danger'],
|
||||
'disabled' => empty($user->getBackupCodes())
|
||||
])->getForm();
|
||||
|
||||
$backup_form->handleRequest($request);
|
||||
if ($backup_form->isSubmitted() && $backup_form->isValid()) {
|
||||
$backupCodeManager->regenerateBackupCodes($user);
|
||||
$em->flush();
|
||||
$this->addFlash('success', 'user.settings.2fa.backup_codes.regenerated');
|
||||
}
|
||||
|
||||
|
||||
/******************************
|
||||
* Output both forms
|
||||
|
@ -303,6 +316,7 @@ class UserController extends AdminPages\BaseAdminController
|
|||
'page_need_reload' => $page_need_reload,
|
||||
|
||||
'google_form' => $google_form->createView(),
|
||||
'backup_form' => $backup_form->createView(),
|
||||
'tfa_google' => [
|
||||
'enabled' => $google_enabled,
|
||||
'qrContent' => $googleAuthenticator->getQRContent($user),
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
<span>{% trans %}tfa_backup.explanation{% endtrans %}</span>
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form_start(backup_form) }}
|
||||
<div class="offset-3">
|
||||
<h6>{% trans %}tfa_backup.enabled{% endtrans %}</h6>
|
||||
<span>{% trans %}tfa_backup.explanation{% endtrans %}</span>
|
||||
|
@ -82,6 +83,11 @@
|
|||
<a href="{{ url('show_backup_codes') }}" target="_blank" data-no-ajax class="btn btn-primary">{% trans %}tfa_backup.show_codes{% endtrans %}</a>
|
||||
</div>
|
||||
|
||||
<div class="offset-3 mt-2">
|
||||
{{ form_widget(backup_form.reset_codes) }}
|
||||
</div>
|
||||
{{ form_end(backup_form) }}
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue