1000 search results

{% extends 'base.html.twig' %}
{% block title %}Two Factor Auth{% endblock %}
{% block body %}
<div class="container">
<div class="row">
<div class="login-form bg-light mt-4 p-4">
<h1 class="h3 mb-3 font-weight-normal">Two Factor Authentication</h1>
<p>
Open your Authenticator app and type in the number.
</p>
FORM TODO
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
62 lines | templates/security/2fa_form.html.twig
// ... lines 1 - 4
{% block body %}
<div class="container">
<div class="row">
<div class="login-form bg-light mt-4 p-4">
<h1 class="h3 mb-3 font-weight-normal">Two Factor Authentication</h1>
<p>
Open your Authenticator app and type in the number.
</p>
{% if authenticationError %}
<p>{{ authenticationError|trans(authenticationErrorData, 'SchebTwoFactorBundle') }}</p>
{% endif %}
{# Let the user select the authentication method #}
<p>{{ "choose_provider"|trans({}, 'SchebTwoFactorBundle') }}:
{% for provider in availableTwoFactorProviders %}
<a href="{{ path("2fa_login", {"preferProvider": provider}) }}">{{ provider }}</a>
{% endfor %}
</p>
{# Display current two-factor provider #}
<p class="label"><label for="_auth_code">{{ "auth_code"|trans({}, 'SchebTwoFactorBundle') }} {{ twoFactorProvider }}:</label></p>
<form class="form" action="{{ checkPathUrl ? checkPathUrl: path(checkPathRoute) }}" method="post">
<p class="widget">
<input
id="_auth_code"
type="text"
name="{{ authCodeParameterName }}"
autocomplete="one-time-code"
autofocus
{#
https://www.twilio.com/blog/html-attributes-two-factor-authentication-autocomplete
If your 2fa methods are using numeric codes only, add these attributes for better user experience:
inputmode="numeric"
pattern="[0-9]*"
#}
/>
</p>
{% 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 %}
<p class="submit"><input type="submit" value="{{ "login"|trans({}, 'SchebTwoFactorBundle') }}" /></p>
</form>
{# The logout link gives the user a way out if they can't complete two-factor authentication #}
<p class="cancel"><a href="{{ logoutPath }}">{{ "cancel"|trans({}, 'SchebTwoFactorBundle') }}</a></p>
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
51 lines | templates/security/2fa_form.html.twig
// ... lines 1 - 4
{% block body %}
<div class="container">
<div class="row">
<div class="login-form bg-light mt-4 p-4">
// ... lines 9 - 14
{% if authenticationError %}
<div class="alert alert-danger">{{ authenticationError|trans(authenticationErrorData, 'SchebTwoFactorBundle') }}</div>
{% endif %}
<form class="form" action="{{ checkPathUrl ? checkPathUrl: path(checkPathRoute) }}" method="post">
<p class="widget">
<input
// ... lines 22 - 25
class="form-control"
// ... lines 27 - 33
/>
</p>
{% 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 %}
<a class="btn btn-link" href="{{ logoutPath }}">{{ "cancel"|trans({}, 'SchebTwoFactorBundle') }}</a>
<button type="submit" class="btn btn-primary">{{ "login"|trans({}, 'SchebTwoFactorBundle') }}</button>
</form>
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
51 lines | templates/security/2fa_form.html.twig
// ... lines 1 - 4
{% block body %}
<div class="container">
<div class="row">
<div class="login-form bg-light mt-4 p-4">
// ... lines 9 - 18
<form class="form" action="{{ checkPathUrl ? checkPathUrl: path(checkPathRoute) }}" method="post">
// ... lines 20 - 43
<button type="submit" class="btn btn-primary">{{ "login"|trans({}, 'SchebTwoFactorBundle') }}</button>
</form>
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
51 lines | templates/security/2fa_form.html.twig
// ... lines 1 - 4
{% block body %}
<div class="container">
<div class="row">
<div class="login-form bg-light mt-4 p-4">
// ... lines 9 - 14
{% if authenticationError %}
<div class="alert alert-danger">{{ authenticationError|trans(authenticationErrorData, 'SchebTwoFactorBundle') }}</div>
{% endif %}
// ... lines 18 - 46
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
42 lines | src/Security/Voter/QuestionVoter.php
// ... lines 1 - 2
namespace App\Security\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
class QuestionVoter extends Voter
{
protected function supports(string $attribute, $subject): bool
{
// replace with your own logic
// https://symfony.com/doc/current/security/voters.html
return in_array($attribute, ['POST_EDIT', 'POST_VIEW'])
&& $subject instanceof \App\Entity\Question;
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
$user = $token->getUser();
// if the user is anonymous, do not grant access
if (!$user instanceof UserInterface) {
return false;
}
// ... (check conditions and return true to grant permission) ...
switch ($attribute) {
case 'POST_EDIT':
// logic to determine if the user can EDIT
// return true or false
break;
case 'POST_VIEW':
// logic to determine if the user can VIEW
// return true or false
break;
}
return false;
}
}
See Code Block in Script
42 lines | src/Security/Voter/QuestionVoter.php
// ... lines 1 - 10
class QuestionVoter extends Voter
{
protected function supports(string $attribute, $subject): bool
{
// https://symfony.com/doc/current/security/voters.html
return in_array($attribute, ['EDIT'])
// ... line 17
}
// ... lines 19 - 40
}
See Code Block in Script
42 lines | src/Security/Voter/QuestionVoter.php
// ... lines 1 - 10
class QuestionVoter extends Voter
{
protected function supports(string $attribute, $subject): bool
{
// https://symfony.com/doc/current/security/voters.html
return in_array($attribute, ['EDIT'])
&& $subject instanceof \App\Entity\Question;
}
// ... lines 19 - 40
}
See Code Block in Script
42 lines | src/Security/Voter/QuestionVoter.php
// ... lines 1 - 10
class QuestionVoter extends Voter
{
// ... lines 13 - 19
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
// ... lines 22 - 39
}
}
See Code Block in Script
42 lines | src/Security/Voter/QuestionVoter.php
// ... lines 1 - 10
class QuestionVoter extends Voter
{
// ... lines 13 - 19
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
// ... line 22
$user = $token->getUser();
// ... lines 24 - 39
}
}
See Code Block in Script
42 lines | src/Security/Voter/QuestionVoter.php
// ... lines 1 - 5
use App\Entity\User;
// ... lines 7 - 10
class QuestionVoter extends Voter
{
// ... lines 13 - 19
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
/** @var User $user */
$user = $token->getUser();
// ... lines 24 - 39
}
}
See Code Block in Script
42 lines | src/Security/Voter/QuestionVoter.php
// ... lines 1 - 8
use Symfony\Component\Security\Core\User\UserInterface;
class QuestionVoter extends Voter
{
// ... lines 13 - 19
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
/** @var User $user */
$user = $token->getUser();
// if the user is anonymous, do not grant access
if (!$user instanceof UserInterface) {
return false;
}
// ... lines 28 - 39
}
}
See Code Block in Script
42 lines | src/Security/Voter/QuestionVoter.php
// ... lines 1 - 4
use App\Entity\Question;
// ... lines 6 - 10
class QuestionVoter extends Voter
{
// ... lines 13 - 19
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
/** @var User $user */
$user = $token->getUser();
// if the user is anonymous, do not grant access
if (!$user instanceof UserInterface) {
return false;
}
if (!$subject instanceof Question) {
throw new \Exception('Wrong type somehow passed');
}
// ... lines 32 - 39
}
}
See Code Block in Script
42 lines | src/Security/Voter/QuestionVoter.php
// ... lines 1 - 10
class QuestionVoter extends Voter
{
// ... lines 13 - 19
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
/** @var User $user */
$user = $token->getUser();
// if the user is anonymous, do not grant access
if (!$user instanceof UserInterface) {
return false;
}
if (!$subject instanceof Question) {
throw new \Exception('Wrong type somehow passed');
}
// ... (check conditions and return true to grant permission) ...
switch ($attribute) {
case 'EDIT':
return $user === $subject->getOwner();
}
return false;
}
}
See Code Block in Script
54 lines | src/Security/Voter/QuestionVoter.php
// ... lines 1 - 8
use Symfony\Component\Security\Core\Security;
// ... lines 10 - 11
class QuestionVoter extends Voter
{
private Security $security;
public function __construct(Security $security)
{
$this->security = $security;
}
// ... lines 20 - 52
}
See Code Block in Script
54 lines | src/Security/Voter/QuestionVoter.php
// ... lines 1 - 8
use Symfony\Component\Security\Core\Security;
// ... lines 10 - 11
class QuestionVoter extends Voter
{
// ... lines 14 - 27
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
// ... lines 30 - 40
if ($this->security->isGranted('ROLE_ADMIN')) {
return true;
}
// ... (check conditions and return true to grant permission) ...
switch ($attribute) {
// ... lines 47 - 48
}
// ... lines 50 - 51
}
}
See Code Block in Script
83 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 26
class LoginFormAuthenticator extends AbstractLoginFormAuthenticator
{
// ... lines 29 - 39
public function authenticate(Request $request): PassportInterface
{
// ... lines 42 - 44
return new Passport(
// ... lines 46 - 56
[
// ... lines 58 - 61
(new RememberMeBadge())->enable(),
]
);
}
// ... lines 66 - 81
}
See Code Block in Script
39 lines | templates/security/login.html.twig
// ... lines 1 - 4
{% block body %}
<div class="container">
<div class="row">
<div class="login-form bg-light mt-4 p-4">
<form method="post" class="row g-3">
// ... lines 10 - 15
<div class="col-12">
// ... line 17
<input type="email" name="email" id="inputEmail" class="form-control" value="{{ last_username }}" required autofocus>
</div>
// ... lines 20 - 33
</form>
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
39 lines | templates/security/login.html.twig
// ... lines 1 - 4
{% block body %}
<div class="container">
<div class="row">
<div class="login-form bg-light mt-4 p-4">
<form method="post" class="row g-3">
// ... lines 10 - 15
<div class="col-12">
// ... line 17
<input type="email" name="email" id="inputEmail" class="form-control" required autofocus>
</div>
<div class="col-12">
// ... line 21
<input type="password" name="password" id="inputPassword" class="form-control" required>
</div>
// ... lines 24 - 34
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
97 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 15
use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator;
// ... lines 17 - 25
class LoginFormAuthenticator extends AbstractLoginFormAuthenticator
{
// ... lines 28 - 95
}
See Code Block in Script