1000 search results

86 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 20
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 23 - 65
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
{
$request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception);
return new RedirectResponse(
$this->router->generate('app_login')
);
}
// ... lines 74 - 84
}
See Code Block in Script
35 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">
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
{% if error %}
<div class="alert alert-danger">{{ error.messageKey }}</div>
{% endif %}
// ... lines 15 - 29
</form>
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
75 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 5
use App\Repository\UserRepository;
// ... lines 7 - 17
class LoginFormAuthenticator extends AbstractAuthenticator
{
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
// ... lines 26 - 73
}
See Code Block in Script
75 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 17
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 20 - 31
public function authenticate(Request $request): PassportInterface
{
// ... lines 34 - 36
return new Passport(
new UserBadge($email, function($userIdentifier) {
// ... lines 39 - 46
}),
// ... lines 48 - 50
);
}
// ... lines 53 - 73
}
See Code Block in Script
75 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 17
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 20 - 31
public function authenticate(Request $request): PassportInterface
{
// ... lines 34 - 36
return new Passport(
new UserBadge($email, function($userIdentifier) {
// optionally pass a callback to load the User manually
$user = $this->userRepository->findOneBy(['email' => $userIdentifier]);
// ... lines 41 - 46
}),
// ... lines 48 - 50
);
}
// ... lines 53 - 73
}
See Code Block in Script
75 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 17
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 20 - 31
public function authenticate(Request $request): PassportInterface
{
// ... lines 34 - 36
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;
}),
// ... lines 48 - 50
);
}
// ... lines 53 - 73
}
See Code Block in Script
75 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 17
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 20 - 31
public function authenticate(Request $request): PassportInterface
{
// ... lines 34 - 36
return new Passport(
// ... lines 38 - 47
new CustomCredentials(function($credentials, User $user) {
// ... line 49
}, $password)
);
}
// ... lines 53 - 73
}
See Code Block in Script
75 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 17
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 20 - 31
public function authenticate(Request $request): PassportInterface
{
// ... lines 34 - 36
return new Passport(
// ... lines 38 - 47
new CustomCredentials(function($credentials, User $user) {
return $credentials === 'tada';
}, $password)
);
}
// ... lines 53 - 73
}
See Code Block in Script
75 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 17
class LoginFormAuthenticator extends AbstractAuthenticator
{
// ... lines 20 - 53
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
{
dd('success');
}
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
{
dd('failure');
}
// ... lines 63 - 73
}
See Code Block in Script
{% extends 'base.html.twig' %}
{% block title %}Hello SecurityController!{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper">
<h1>Hello {{ controller_name }}! ✅</h1>
This friendly message is coming from:
<ul>
<li>Your controller at <code><a href="{{ '/Users/weaverryan/Sites/knp/knpu-repos/symfony5/src/Controller/SecurityController.php'|file_link(0) }}">src/Controller/SecurityController.php</a></code></li>
<li>Your template at <code><a href="{{ '/Users/weaverryan/Sites/knp/knpu-repos/symfony5/templates/security/index.html.twig'|file_link(0) }}">templates/security/index.html.twig</a></code></li>
</ul>
</div>
{% endblock %}
See Code Block in Script
{% extends 'base.html.twig' %}
{% block title %}Log In!{% endblock %}
{% 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">
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
<div class="col-12">
<label for="inputEmail">Email</label>
<input type="email" name="email" id="inputEmail" class="form-control" required autofocus>
</div>
<div class="col-12">
<label for="inputPassword">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" required>
</div>
<div class="col-12">
<button class="btn btn-lg btn-primary float-end" type="submit">
Sign in
</button>
</div>
</form>
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
55 lines | src/Security/Voter/CheeseListingVoter.php
// ... lines 1 - 10
class CheeseListingVoter extends Voter
{
// ... lines 13 - 19
protected function supports($attribute, $subject)
{
// replace with your own logic
// https://symfony.com/doc/current/security/voters.html
return in_array($attribute, ['EDIT'])
&& $subject instanceof CheeseListing;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$user = $token->getUser();
// if the user is anonymous, do not grant access
if (!$user instanceof UserInterface) {
return false;
}
/** @var CheeseListing $subject */
// ... (check conditions and return true to grant permission) ...
switch ($attribute) {
case 'EDIT':
if ($subject->getOwner() === $user) {
return true;
}
if ($this->security->isGranted('ROLE_ADMIN')) {
return true;
}
return false;
}
throw new \Exception(sprintf('Unhandled attribute "%s"', $attribute));
}
}
See Code Block in Script
95 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 17
use Symfony\Component\Security\Guard\PasswordAuthenticatedInterface;
// ... lines 19 - 20
class LoginFormAuthenticator extends AbstractFormLoginAuthenticator implements PasswordAuthenticatedInterface
{
// ... lines 23 - 93
}
See Code Block in Script
95 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 20
class LoginFormAuthenticator extends AbstractFormLoginAuthenticator implements PasswordAuthenticatedInterface
{
// ... lines 23 - 75
public function getPassword($credentials): ?string
{
// ... line 78
}
// ... lines 80 - 93
}
See Code Block in Script
95 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 20
class LoginFormAuthenticator extends AbstractFormLoginAuthenticator implements PasswordAuthenticatedInterface
{
// ... lines 23 - 44
public function getCredentials(Request $request)
{
$credentials = [
'email' => $request->request->get('email'),
'password' => $request->request->get('password'),
'csrf_token' => $request->request->get('_csrf_token'),
];
$request->getSession()->set(
Security::LAST_USERNAME,
$credentials['email']
);
return $credentials;
}
// ... lines 60 - 93
}
See Code Block in Script
95 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 20
class LoginFormAuthenticator extends AbstractFormLoginAuthenticator implements PasswordAuthenticatedInterface
{
// ... lines 23 - 75
public function getPassword($credentials): ?string
{
return $credentials['password'];
}
// ... lines 80 - 93
}
See Code Block in Script
{% extends 'base.html.twig' %}
{% block title %}Login!{% endblock %}
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('css/login.css') }}">
{% endblock %}
{% block body %}
<div class="container">
<div class="row">
<div class="col-sm-12">
<form class="form-signin" method="post">
{% if error %}
<div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" value="{{ last_username }}" name="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
<input type="hidden" name="_csrf_token"
value="{{ csrf_token('authenticate') }}"
>
<div class="checkbox mb-3">
<label>
<input type="checkbox" name="_remember_me"> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">
Sign in
</button>
</form>
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
36 lines | templates/security/register.html.twig
// ... lines 1 - 2
{% block title %}Register!{% endblock %}
// ... lines 4 - 10
{% block body %}
<div class="container">
<div class="row">
<div class="col-sm-12">
{# todo - replace with a Symfony form! #}
<form class="form-signin" method="post">
// ... lines 17 - 30
</form>
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
36 lines | templates/security/register.html.twig
// ... lines 1 - 2
{% block title %}Register!{% endblock %}
// ... lines 4 - 10
{% block body %}
<div class="container">
<div class="row">
<div class="col-sm-12">
{# todo - replace with a Symfony form! #}
<form class="form-signin" method="post">
<h1 class="h3 mb-3 font-weight-normal">Register</h1>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
// ... lines 22 - 30
</form>
</div>
</div>
</div>
{% endblock %}
See Code Block in Script
36 lines | templates/security/register.html.twig
// ... lines 1 - 2
{% block title %}Register!{% endblock %}
// ... lines 4 - 10
{% block body %}
<div class="container">
<div class="row">
<div class="col-sm-12">
{# todo - replace with a Symfony form! #}
<form class="form-signin" method="post">
<h1 class="h3 mb-3 font-weight-normal">Register</h1>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
<div class="checkbox mb-3">
<label>
<input type="checkbox" name="_remember_me" required> Agree to terms I for sure read
</label>
</div>
// ... lines 28 - 30
</form>
</div>
</div>
</div>
{% endblock %}
See Code Block in Script