1000 search results

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 - 24
<input type="hidden" name="_csrf_token"
value="{{ csrf_token('authenticate') }}"
>
// ... lines 28 - 33
</form>
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
92 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 15
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
// ... lines 17 - 22
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 25 - 38
public function authenticate(Request $request): PassportInterface
{
// ... lines 41 - 43
return new Passport(
// ... lines 45 - 55
[
new CsrfTokenBadge(
// ... lines 58 - 59
)
]
);
}
// ... lines 64 - 90
}
See Code Block in Script
92 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 22
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 25 - 38
public function authenticate(Request $request): PassportInterface
{
// ... lines 41 - 43
return new Passport(
// ... lines 45 - 55
[
new CsrfTokenBadge(
'authenticate',
// ... line 59
)
]
);
}
// ... lines 64 - 90
}
See Code Block in Script
92 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 22
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 25 - 38
public function authenticate(Request $request): PassportInterface
{
// ... lines 41 - 43
return new Passport(
// ... lines 45 - 55
[
new CsrfTokenBadge(
'authenticate',
$request->request->get('_csrf_token')
)
]
);
}
// ... lines 64 - 90
}
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
{
$email = $request->request->get('email');
$password = $request->request->get('password');
return new Passport(
new UserBadge($email, function($userIdentifier) {
// optionally pass a callback to load the User manually
$user = $this->userRepository->findOneBy(['email' => $userIdentifier]);
if (!$user) {
throw new UserNotFoundException();
}
return $user;
}),
new PasswordCredentials($password),
[
new CsrfTokenBadge(
'authenticate',
$request->request->get('_csrf_token')
),
(new RememberMeBadge())->enable(),
]
);
}
// ... lines 66 - 81
}
See Code Block in Script
42 lines | src/Security/Voter/AdminUserVoter.php
// ... lines 1 - 4
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
class AdminUserVoter 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\AdminUser;
}
// ... line 18
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
// ... lines 21 - 39
}
}
See Code Block in Script
40 lines | src/Security/Voter/AdminUserVoter.php
// ... lines 1 - 7
use Symfony\Component\Security\Core\User\UserInterface;
// ... line 9
class AdminUserVoter 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, ['ADMIN_USER_EDIT'])
&& $subject instanceof User;
}
// ... lines 19 - 38
}
See Code Block in Script
40 lines | src/Security/Voter/AdminUserVoter.php
// ... lines 1 - 19
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
// ... lines 22 - 26
if (!$subject instanceof User) {
throw new \LogicException('Subject is not an instance of User?');
}
// ... lines 30 - 37
}
// ... lines 39 - 40
See Code Block in Script
40 lines | src/Security/Voter/AdminUserVoter.php
// ... lines 1 - 19
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
// ... lines 22 - 30
// ... (check conditions and return true to grant permission) ...
switch ($attribute) {
case 'ADMIN_USER_EDIT':
return $user === $subject;
}
return false;
}
// ... lines 39 - 40
See Code Block in Script
48 lines | src/Security/Voter/AdminUserVoter.php
// ... lines 1 - 7
use Symfony\Component\Security\Core\Security;
// ... lines 9 - 10
class AdminUserVoter extends Voter
{
private Security $security;
public function __construct(Security $security)
{
$this->security = $security;
}
// ... lines 19 - 27
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
// ... lines 30 - 39
switch ($attribute) {
case 'ADMIN_USER_EDIT':
return $user === $subject || $this->security->isGranted('ROLE_SUPER_ADMIN');;
}
// ... lines 44 - 45
}
}
See Code Block in Script
45 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 11
class LoginFormAuthenticator extends AbstractAuthenticator
{
public function supports(Request $request): ?bool
{
return ($request->getPathInfo() === '/login' && $request->isMethod('POST'));
}
// ... lines 18 - 43
}
See Code Block in Script
45 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 11
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 14 - 18
public function authenticate(Request $request): PassportInterface
{
dd('authenticate!');
}
// ... lines 23 - 43
}
See Code Block in Script
57 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 12
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
// ... lines 14 - 15
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 18 - 22
public function authenticate(Request $request): PassportInterface
{
// ... lines 25 - 27
return new Passport(
// ... lines 29 - 32
);
}
// ... lines 35 - 55
}
See Code Block in Script
57 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 15
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 18 - 22
public function authenticate(Request $request): PassportInterface
{
$email = $request->request->get('email');
$password = $request->request->get('password');
return new Passport(
// ... lines 29 - 32
);
}
// ... lines 35 - 55
}
See Code Block in Script
57 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 10
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
// ... lines 12 - 15
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 18 - 22
public function authenticate(Request $request): PassportInterface
{
$email = $request->request->get('email');
$password = $request->request->get('password');
return new Passport(
new UserBadge($email),
// ... lines 30 - 32
);
}
// ... lines 35 - 55
}
See Code Block in Script
57 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 11
use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\CustomCredentials;
// ... lines 13 - 15
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 18 - 22
public function authenticate(Request $request): PassportInterface
{
// ... lines 25 - 27
return new Passport(
new UserBadge($email),
new CustomCredentials(function($credentials, User $user) {
// ... lines 31 - 32
);
}
// ... lines 35 - 55
}
See Code Block in Script
57 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 15
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 18 - 22
public function authenticate(Request $request): PassportInterface
{
// ... lines 25 - 27
return new Passport(
new UserBadge($email),
new CustomCredentials(function($credentials, User $user) {
dd($credentials, $user);
}, $password)
);
}
// ... lines 35 - 55
}
See Code Block in Script
{% 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