1000 search results

55 lines | src/Security/Voter/ArticleVoter.php
// ... lines 1 - 7
use Symfony\Component\Security\Core\Security;
// ... lines 9 - 10
class ArticleVoter extends Voter
{
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
// ... lines 19 - 53
}
See Code Block in Script
55 lines | src/Security/Voter/ArticleVoter.php
// ... lines 1 - 10
class ArticleVoter extends Voter
{
// ... lines 13 - 27
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
// ... lines 30 - 36
// ... (check conditions and return true to grant permission) ...
switch ($attribute) {
case 'MANAGE':
// this is the author!
if ($subject->getAuthor() == $user) {
return true;
}
if ($this->security->isGranted('ROLE_ADMIN_ARTICLE')) {
return true;
}
return false;
}
return false;
}
}
See Code Block in Script
59 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 11
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
public function supports(Request $request)
{
// look for header "Authorization: Bearer <token>"
return $request->headers->has('Authorization')
&& 0 === strpos($request->headers->get('Authorization'), 'Bearer ');
}
// ... lines 20 - 57
}
See Code Block in Script
59 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 11
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 14 - 20
public function getCredentials(Request $request)
{
$authorizationHeader = $request->headers->get('Authorization');
// ... lines 24 - 26
}
// ... lines 28 - 57
}
See Code Block in Script
59 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 11
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 14 - 20
public function getCredentials(Request $request)
{
$authorizationHeader = $request->headers->get('Authorization');
// skip beyond "Bearer "
return substr($authorizationHeader, 7);
}
// ... lines 28 - 57
}
See Code Block in Script
59 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 11
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 14 - 28
public function getUser($credentials, UserProviderInterface $userProvider)
{
dump($credentials);die;
}
// ... lines 33 - 57
}
See Code Block in Script
89 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 19
class LoginFormAuthenticator extends AbstractFormLoginAuthenticator
{
// ... lines 22 - 43
public function getCredentials(Request $request)
{
$credentials = [
'email' => $request->request->get('email'),
'password' => $request->request->get('password'),
'csrf_token' => $request->request->get('_csrf_token'),
];
// ... lines 51 - 56
return $credentials;
}
// ... lines 59 - 87
}
See Code Block in Script
75 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 4
use App\Repository\ApiTokenRepository;
// ... lines 6 - 12
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
private $apiTokenRepo;
public function __construct(ApiTokenRepository $apiTokenRepo)
{
$this->apiTokenRepo = $apiTokenRepo;
}
// ... lines 21 - 73
}
See Code Block in Script
75 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 12
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 15 - 36
public function getUser($credentials, UserProviderInterface $userProvider)
{
$token = $this->apiTokenRepo->findOneBy([
'token' => $credentials
]);
// ... lines 42 - 47
}
// ... lines 49 - 73
}
See Code Block in Script
75 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 12
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 15 - 36
public function getUser($credentials, UserProviderInterface $userProvider)
{
$token = $this->apiTokenRepo->findOneBy([
'token' => $credentials
]);
if (!$token) {
return;
}
return $token->getUser();
}
// ... lines 49 - 73
}
See Code Block in Script
75 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 12
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 15 - 49
public function checkCredentials($credentials, UserInterface $user)
{
dd('checking credentials');
}
// ... lines 54 - 73
}
See Code Block in Script
89 lines | src/Security/LoginFormAuthenticator.php
// ... lines 1 - 19
class LoginFormAuthenticator extends AbstractFormLoginAuthenticator
{
// ... lines 22 - 74
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
if ($targetPath = $this->getTargetPath($request->getSession(), $providerKey)) {
return new RedirectResponse($targetPath);
}
return new RedirectResponse($this->router->generate('app_homepage'));
}
// ... lines 83 - 87
}
See Code Block in Script
75 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 12
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 15 - 54
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
// todo
}
// ... lines 59 - 73
}
See Code Block in Script
75 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 12
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 15 - 54
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
// ... line 57
}
// ... lines 59 - 73
}
See Code Block in Script
78 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 5
use Symfony\Component\HttpFoundation\JsonResponse;
// ... lines 7 - 13
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 16 - 55
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
return new JsonResponse([
'message' => $exception->getMessageKey()
], 401);
}
// ... lines 62 - 76
}
See Code Block in Script
37 lines | templates/security/login.html.twig
// ... lines 1 - 10
{% block body %}
<form class="form-signin" method="post">
{% if error %}
<div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
// ... lines 16 - 34
</form>
{% endblock %}
See Code Block in Script
"Username could not be found.": "Oh no! It doesn't look like that email exists!"
See Code Block in Script
81 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 9
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
// ... lines 11 - 14
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 17 - 38
public function getUser($credentials, UserProviderInterface $userProvider)
{
// ... lines 41 - 44
if (!$token) {
throw new CustomUserMessageAuthenticationException(
'Invalid API Token'
);
}
// ... lines 50 - 51
}
// ... lines 53 - 79
}
See Code Block in Script
87 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 9
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
// ... lines 11 - 14
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 17 - 38
public function getUser($credentials, UserProviderInterface $userProvider)
{
// ... lines 41 - 44
if (!$token) {
throw new CustomUserMessageAuthenticationException(
'Invalid API Token'
);
}
if ($token->isExpired()) {
throw new CustomUserMessageAuthenticationException(
'Token expired'
);
}
// ... lines 56 - 57
}
// ... lines 59 - 85
}
See Code Block in Script
87 lines | src/Security/ApiTokenAuthenticator.php
// ... lines 1 - 14
class ApiTokenAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 17 - 59
public function checkCredentials($credentials, UserInterface $user)
{
return true;
}
// ... lines 64 - 85
}
See Code Block in Script