MagicUrl.php in Open Social 8.5
File
modules/custom/social_magic_login/src/Service/MagicUrl.php
View source
<?php
namespace Drupal\social_magic_login\Service;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\Core\Url;
use Drupal\user\UserInterface;
class MagicUrl implements MagicUrlInterface {
protected $pathValidator;
public function __construct(PathValidatorInterface $pathValidator) {
$this->pathValidator = $pathValidator;
}
public function create(UserInterface $account, string $destination, array $options) : ?Url {
if (!isset($account, $destination)) {
return NULL;
}
if (!$this->pathValidator
->getUrlIfValidWithoutAccessCheck($destination)) {
return NULL;
}
$timestamp = \Drupal::time()
->getRequestTime();
$lang_code = isset($options['langcode']) ? $options['langcode'] : $account
->getPreferredLangcode();
$url_options = [
'absolute' => TRUE,
'language' => \Drupal::languageManager()
->getLanguage($lang_code),
];
return Url::fromRoute('social_magic_login.login', [
'uid' => $account
->id(),
'timestamp' => $timestamp,
'hash' => user_pass_rehash($account, $timestamp),
'destination' => base64_encode($destination),
], $url_options);
}
}
Classes
Name |
Description |
MagicUrl |
Service to generate one-time login links (a.k.a 'magic' #lama's). |