-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
319 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# See the configuration reference at https://symfony.com/bundles/SchebTwoFactorBundle/6.x/configuration.html | ||
scheb_two_factor: | ||
security_tokens: | ||
- Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken | ||
- Symfony\Component\Security\Http\Authenticator\Token\PostAuthenticationToken | ||
email: | ||
enabled: true | ||
mailer: App\Service\Mailer\AuthCodeMailer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
2fa_login: | ||
path: /2fa | ||
defaults: | ||
_controller: "scheb_two_factor.form_controller::form" | ||
|
||
2fa_login_check: | ||
path: /2fa_check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20240605094114 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add auth_code column to user table'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE user ADD auth_code VARCHAR(255) DEFAULT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE user DROP auth_code'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Service\Mailer; | ||
|
||
use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface; | ||
use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; | ||
use Symfony\Component\Mailer\MailerInterface; | ||
use Symfony\Component\Mime\Email; | ||
|
||
class AuthCodeMailer implements AuthCodeMailerInterface | ||
{ | ||
private $mailer; | ||
|
||
public function __construct(MailerInterface $mailer) | ||
{ | ||
$this->mailer = $mailer; | ||
} | ||
|
||
public function sendAuthCode(TwoFactorInterface $user): void | ||
{ | ||
$authCode = $user->getEmailAuthCode(); | ||
|
||
$this->mailer->send((new Email()) | ||
->from('ne-pas-repondre@histologe.beta.gouv.fr') | ||
->to($user->getEmailAuthRecipient()) | ||
->subject('Code de vérification') | ||
->text("Votre code de vérification est : $authCode") | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
templates/bundles/SchebTwoFactorBundle/Authentication/form.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{% extends 'base.html.twig' %} | ||
|
||
{% block title %}Authentification à deux facteurs{% endblock %} | ||
|
||
{% block body %} | ||
<main class="fr-container fr-py-5w"> | ||
<section class="fr-grid-row"> | ||
|
||
<div class="fr-col-md-12"> | ||
<h1>Authentification à deux facteurs</h1> | ||
{# Authentication errors #} | ||
{% if authenticationError %} | ||
<div class="fr-alert fr-alert--error fr-alert--sm fr-mb-3w"> | ||
<p>{{ authenticationError|trans(authenticationErrorData, 'SchebTwoFactorBundle') }}</p> | ||
</div> | ||
{% endif %} | ||
|
||
{# Let the user select the authentication method #} | ||
{% if availableTwoFactorProviders|length > 1 %} | ||
<p>{{ "choose_provider"|trans({}, 'SchebTwoFactorBundle') }}: | ||
{% for provider in availableTwoFactorProviders %} | ||
<a href="{{ path("2fa_login", {"preferProvider": provider}) }}">{{ provider }}</a> | ||
{% endfor %} | ||
</p> | ||
{% endif %} | ||
</div> | ||
|
||
<div class="fr-col-md-6"> | ||
{# The form to enter the authentication code #} | ||
<form class="form" action="{{ checkPathUrl ? checkPathUrl: path(checkPathRoute) }}" method="post"> | ||
|
||
<div class="fr-input-group"> | ||
<label class="fr-label" for="_auth_code">{{ "auth_code"|trans({}, 'SchebTwoFactorBundle') }} {{ twoFactorProvider }}</label> | ||
<input class="fr-input" id="_auth_code" type="text" name="{{ authCodeParameterName }}" autocomplete="one-time-code" autofocus inputmode="numeric" pattern="[0-9]*"/> | ||
</div> | ||
|
||
{% if displayTrustedOption %} | ||
<p class="widget"> | ||
<label for="_trusted"><input id="_trusted" type="checkbox" name="{{ trustedParameterName }}"/> | ||
{{ "trusted"|trans({}, 'SchebTwoFactorBundle') }}</label> | ||
</p> | ||
{% endif %} | ||
{% if isCsrfProtectionEnabled %} | ||
<input type="hidden" name="{{ csrfParameterName }}" value="{{ csrf_token(csrfTokenId) }}"> | ||
{% endif %} | ||
<div class="fr-form-group"> | ||
<button type="submit" class="fr-btn fr-icon-checkbox-circle-fill fr-btn--icon-right"> | ||
Connexion | ||
</button> | ||
</div> | ||
{# The logout link gives the user a way out if they can't complete two-factor authentication #} | ||
<div class="fr-form-group fr-mt-5v"> | ||
<a href="{{ logoutPath }}">{{ "cancel"|trans({}, 'SchebTwoFactorBundle') }}</a> | ||
</div> | ||
</form> | ||
|
||
</div> | ||
</section> | ||
</main> | ||
{% endblock %} |
Oops, something went wrong.