1000 search results

16 lines | templates/security/enable2fa.html.twig
{% extends 'base.html.twig' %}
{% block title %}2fa Activation{% 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">Use Authy or Google Authenticator to Scan the QR Code</h1>
// ... lines 10 - 11
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
{% extends 'base.html.twig' %}
{% block title %}2fa Activation{% 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">Use Authy or Google Authenticator to Scan the QR Code</h1>
<img src="{{ path('app_qr_code') }}" alt="2fa QR Code">
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
138 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 26
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
// ... lines 28 - 29
class LoginFormAuthenticator extends AbstractLoginFormAuthenticator
{
// ... lines 32 - 39
public function authenticate(Request $request): Passport
{
// ... lines 42 - 66
}
// ... lines 68 - 136
}
See Code Block in Script
138 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 39
public function authenticate(Request $request): Passport
{
$email = $request->request->get('email');
$password = $request->request->get('password');
return new Passport(
// ... lines 46 - 65
);
}
// ... lines 68 - 138
See Code Block in Script
138 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 39
public function authenticate(Request $request): Passport
{
// ... lines 42 - 44
return new Passport(
new UserBadge($email, function($userIdentifier) {
// optionally pass a callback to load the User manually
$user = $this->entityManager
->getRepository(User::class)
->findOneBy(['email' => $userIdentifier]);
if (!$user) {
throw new UserNotFoundException();
}
return $user;
}),
// ... lines 58 - 65
);
}
// ... lines 68 - 138
See Code Block in Script
138 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 39
public function authenticate(Request $request): Passport
{
// ... lines 42 - 44
return new Passport(
new UserBadge($email, function($userIdentifier) {
// ... lines 47 - 56
}),
new PasswordCredentials($password),
// ... lines 59 - 65
);
}
// ... lines 68 - 138
See Code Block in Script
138 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 39
public function authenticate(Request $request): Passport
{
// ... lines 42 - 44
return new Passport(
// ... lines 46 - 57
new PasswordCredentials($password),
[
new CsrfTokenBadge(
'authenticate',
$request->request->get('_csrf_token')
),
// ... line 64
]
);
}
// ... lines 68 - 138
See Code Block in Script
138 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 39
public function authenticate(Request $request): Passport
{
// ... lines 42 - 44
return new Passport(
// ... lines 46 - 57
new PasswordCredentials($password),
[
// ... lines 60 - 63
(new RememberMeBadge())->enable(),
]
);
}
// ... lines 68 - 138
See Code Block in Script
87 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 28
public function __construct(private SessionInterface $session, private EntityManagerInterface $entityManager, private UrlGeneratorInterface $urlGenerator)
{
}
// ... lines 32 - 87
See Code Block in Script
45 lines | src/Security/Voter/DragonTreasureVoter.php
// ... lines 1 - 8
class DragonTreasureVoter extends Voter
{
// ... lines 11 - 13
protected function supports(string $attribute, mixed $subject): bool
{
// ... lines 16 - 19
}
// ... lines 21 - 43
}
See Code Block in Script
40 lines | src/Security/Voter/DragonTreasureVoter.php
// ... lines 1 - 9
class DragonTreasureVoter extends Voter
{
public const EDIT = 'EDIT';
protected function supports(string $attribute, mixed $subject): bool
{
return in_array($attribute, [self::EDIT])
&& $subject instanceof DragonTreasure;
}
// ... lines 19 - 38
}
See Code Block in Script
40 lines | src/Security/Voter/DragonTreasureVoter.php
// ... lines 1 - 9
class DragonTreasureVoter extends Voter
{
// ... lines 12 - 19
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
return false;
// ... lines 23 - 37
}
}
See Code Block in Script
40 lines | src/Security/Voter/DragonTreasureVoter.php
// ... lines 1 - 9
class DragonTreasureVoter extends Voter
{
// ... lines 12 - 19
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
return false;
$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 self::EDIT:
// logic to determine if the user can EDIT
// return true or false
break;
}
return false;
}
}
See Code Block in Script
43 lines | src/Security/Voter/DragonTreasureVoter.php
// ... lines 1 - 9
class DragonTreasureVoter extends Voter
{
// ... lines 12 - 19
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
$user = $token->getUser();
// if the user is anonymous, do not grant access
if (!$user instanceof UserInterface) {
return false;
}
assert($subject instanceof DragonTreasure);
// ... (check conditions and return true to grant permission) ...
// ... lines 31 - 40
}
}
See Code Block in Script
43 lines | src/Security/Voter/DragonTreasureVoter.php
// ... lines 1 - 9
class DragonTreasureVoter extends Voter
{
// ... lines 12 - 19
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
// ... lines 22 - 29
// ... (check conditions and return true to grant permission) ...
switch ($attribute) {
case self::EDIT:
if ($subject->getOwner() === $user) {
return true;
}
break;
}
return false;
}
}
See Code Block in Script
52 lines | src/Security/Voter/DragonTreasureVoter.php
// ... lines 1 - 5
use Symfony\Bundle\SecurityBundle\Security;
// ... lines 7 - 10
class DragonTreasureVoter extends Voter
{
// ... lines 13 - 14
public function __construct(private Security $security)
{
}
// ... lines 18 - 50
}
See Code Block in Script
52 lines | src/Security/Voter/DragonTreasureVoter.php
// ... lines 1 - 10
class DragonTreasureVoter extends Voter
{
// ... lines 13 - 24
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
// ... lines 27 - 35
switch ($attribute) {
case self::EDIT:
if (!$this->security->isGranted('ROLE_TREASURE_EDIT')) {
return false;
}
if ($subject->getOwner() === $user) {
return true;
}
break;
}
// ... lines 48 - 49
}
}
See Code Block in Script
56 lines | src/Security/Voter/DragonTreasureVoter.php
// ... lines 1 - 10
class DragonTreasureVoter extends Voter
{
// ... lines 13 - 24
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
// ... lines 27 - 32
if ($this->security->isGranted('ROLE_ADMIN')) {
return true;
}
assert($subject instanceof DragonTreasure);
// ... lines 38 - 53
}
}
See Code Block in Script
45 lines | src/Security/Voter/DragonTreasureVoter.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 DragonTreasureVoter extends Voter
{
public const EDIT = 'POST_EDIT';
public const VIEW = 'POST_VIEW';
protected function supports(string $attribute, mixed $subject): bool
{
// replace with your own logic
// https://symfony.com/doc/current/security/voters.html
return in_array($attribute, [self::EDIT, self::VIEW])
&& $subject instanceof \App\Entity\DragonTreasure;
}
protected function voteOnAttribute(string $attribute, mixed $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 self::EDIT:
// logic to determine if the user can EDIT
// return true or false
break;
case self::VIEW:
// logic to determine if the user can VIEW
// return true or false
break;
}
return false;
}
}
See Code Block in Script
15 lines | src/Security/ApiTokenHandler.php
// ... lines 1 - 2
namespace App\Security;
use Symfony\Component\Security\Http\AccessToken\AccessTokenHandlerInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
class ApiTokenHandler implements AccessTokenHandlerInterface
{
public function getUserBadgeFrom(#[\SensitiveParameter] string $accessToken): UserBadge
{
// TODO: Implement getUserBadgeFrom() method.
}
}
See Code Block in Script