Subida del módulo y tema de PrestaShop

This commit is contained in:
Kaloyan
2026-04-09 18:31:51 +02:00
parent 12c253296f
commit 16b3ff9424
39262 changed files with 7418797 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Http\LoginLink\Exception;
use Symfony\Component\Security\Core\Signature\Exception\ExpiredSignatureException;
/**
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
class ExpiredLoginLinkException extends ExpiredSignatureException implements InvalidLoginLinkExceptionInterface
{
}

View File

@@ -0,0 +1,27 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Http\LoginLink\Exception;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
/**
* Thrown when a login link is invalid.
*
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
class InvalidLoginLinkAuthenticationException extends AuthenticationException
{
public function getMessageKey(): string
{
return 'Invalid or expired login link.';
}
}

View File

@@ -0,0 +1,19 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Http\LoginLink\Exception;
/**
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
class InvalidLoginLinkException extends \RuntimeException implements InvalidLoginLinkExceptionInterface
{
}

View File

@@ -0,0 +1,19 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Http\LoginLink\Exception;
/**
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
interface InvalidLoginLinkExceptionInterface extends \Throwable
{
}

View File

@@ -0,0 +1,42 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Http\LoginLink;
/**
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
class LoginLinkDetails
{
private string $url;
private \DateTimeImmutable $expiresAt;
public function __construct(string $url, \DateTimeImmutable $expiresAt)
{
$this->url = $url;
$this->expiresAt = $expiresAt;
}
public function getUrl(): string
{
return $this->url;
}
public function getExpiresAt(): \DateTimeImmutable
{
return $this->expiresAt;
}
public function __toString(): string
{
return $this->url;
}
}

View File

@@ -0,0 +1,116 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Http\LoginLink;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
use Symfony\Component\Security\Core\Signature\Exception\ExpiredSignatureException;
use Symfony\Component\Security\Core\Signature\Exception\InvalidSignatureException;
use Symfony\Component\Security\Core\Signature\SignatureHasher;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Http\LoginLink\Exception\ExpiredLoginLinkException;
use Symfony\Component\Security\Http\LoginLink\Exception\InvalidLoginLinkException;
/**
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
final class LoginLinkHandler implements LoginLinkHandlerInterface
{
private UrlGeneratorInterface $urlGenerator;
private UserProviderInterface $userProvider;
private array $options;
private SignatureHasher $signatureHasher;
public function __construct(UrlGeneratorInterface $urlGenerator, UserProviderInterface $userProvider, SignatureHasher $signatureHasher, array $options)
{
$this->urlGenerator = $urlGenerator;
$this->userProvider = $userProvider;
$this->signatureHasher = $signatureHasher;
$this->options = array_merge([
'route_name' => null,
'lifetime' => 600,
], $options);
}
public function createLoginLink(UserInterface $user, ?Request $request = null, ?int $lifetime = null): LoginLinkDetails
{
$expires = time() + ($lifetime ?: $this->options['lifetime']);
$expiresAt = new \DateTimeImmutable('@'.$expires);
$parameters = [
'user' => $user->getUserIdentifier(),
'expires' => $expires,
'hash' => $this->signatureHasher->computeSignatureHash($user, $expires),
];
if ($request) {
$currentRequestContext = $this->urlGenerator->getContext();
$this->urlGenerator->setContext(
(new RequestContext())
->fromRequest($request)
->setParameter('_locale', $request->getLocale())
);
}
try {
$url = $this->urlGenerator->generate(
$this->options['route_name'],
$parameters,
UrlGeneratorInterface::ABSOLUTE_URL
);
} finally {
if ($request) {
$this->urlGenerator->setContext($currentRequestContext);
}
}
return new LoginLinkDetails($url, $expiresAt);
}
public function consumeLoginLink(Request $request): UserInterface
{
$userIdentifier = $request->get('user');
if (!$hash = $request->get('hash')) {
throw new InvalidLoginLinkException('Missing "hash" parameter.');
}
if (!\is_string($hash)) {
throw new InvalidLoginLinkException('Invalid "hash" parameter.');
}
if (!$expires = $request->get('expires')) {
throw new InvalidLoginLinkException('Missing "expires" parameter.');
}
if (!preg_match('/^\d+$/', $expires)) {
throw new InvalidLoginLinkException('Invalid "expires" parameter.');
}
try {
$this->signatureHasher->acceptSignatureHash($userIdentifier, $expires, $hash);
$user = $this->userProvider->loadUserByIdentifier($userIdentifier);
$this->signatureHasher->verifySignatureHash($user, $expires, $hash);
} catch (UserNotFoundException $e) {
throw new InvalidLoginLinkException('User not found.', 0, $e);
} catch (ExpiredSignatureException $e) {
throw new ExpiredLoginLinkException(ucfirst(str_ireplace('signature', 'login link', $e->getMessage())), 0, $e);
} catch (InvalidSignatureException $e) {
throw new InvalidLoginLinkException(ucfirst(str_ireplace('signature', 'login link', $e->getMessage())), 0, $e);
}
return $user;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Http\LoginLink;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* A class that is able to create and handle "magic" login links.
*
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
interface LoginLinkHandlerInterface
{
/**
* Generate a link that can be used to authenticate as the given user.
*
* @param int|null $lifetime When not null, the argument overrides any default lifetime previously set
*/
public function createLoginLink(UserInterface $user, ?Request $request = null /* , int $lifetime = null */): LoginLinkDetails;
/**
* Validates if this request contains a login link and returns the associated User.
*
* Throw InvalidLoginLinkExceptionInterface if the link is invalid.
*/
public function consumeLoginLink(Request $request): UserInterface;
}

View File

@@ -0,0 +1,71 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Http\LoginLink;
use Symfony\Bridge\Twig\Mime\NotificationEmail;
use Symfony\Component\Notifier\Message\EmailMessage;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Notification\EmailNotificationInterface;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\Notification\SmsNotificationInterface;
use Symfony\Component\Notifier\Recipient\EmailRecipientInterface;
use Symfony\Component\Notifier\Recipient\SmsRecipientInterface;
/**
* Use this notification to ease sending login link
* emails/SMS using the Notifier component.
*
* @author Wouter de Jong <wouter@wouterj.nl>
*/
class LoginLinkNotification extends Notification implements EmailNotificationInterface, SmsNotificationInterface
{
private LoginLinkDetails $loginLinkDetails;
public function __construct(LoginLinkDetails $loginLinkDetails, string $subject, array $channels = [])
{
parent::__construct($subject, $channels);
$this->loginLinkDetails = $loginLinkDetails;
}
public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): ?EmailMessage
{
if (!class_exists(NotificationEmail::class)) {
throw new \LogicException(\sprintf('The "%s" method requires "symfony/twig-bridge:>4.4".', __METHOD__));
}
$email = NotificationEmail::asPublicEmail()
->to($recipient->getEmail())
->subject($this->getSubject())
->content($this->getContent() ?: $this->getDefaultContent('button below'))
->action('Sign in', $this->loginLinkDetails->getUrl())
;
return new EmailMessage($email);
}
public function asSmsMessage(SmsRecipientInterface $recipient, ?string $transport = null): ?SmsMessage
{
return new SmsMessage($recipient->getPhone(), $this->getDefaultContent('link').' '.$this->loginLinkDetails->getUrl());
}
private function getDefaultContent(string $target): string
{
$duration = $this->loginLinkDetails->getExpiresAt()->getTimestamp() - time();
$durationString = floor($duration / 60).' minute'.($duration > 60 ? 's' : '');
if (($hours = $duration / 3600) >= 1) {
$durationString = floor($hours).' hour'.($hours >= 2 ? 's' : '');
}
return \sprintf('Click on the %s to confirm you want to sign in. This link will expire in %s.', $target, $durationString);
}
}