class AuthDecorator in Mail Login 8.2
Validates user authentication credentials.
Hierarchy
- class \Drupal\mail_login\AuthDecorator implements UserAuthInterface uses DependencySerializationTrait
Expanded class hierarchy of AuthDecorator
1 string reference to 'AuthDecorator'
1 service uses AuthDecorator
File
- src/
AuthDecorator.php, line 12
Namespace
Drupal\mail_loginView source
class AuthDecorator implements UserAuthInterface {
use DependencySerializationTrait;
/**
* The original user authentication service.
*
* @var \Drupal\user\UserAuthInterface
*/
protected $userAuth;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a UserAuth object.
*
* @param \Drupal\user\UserAuthInterface $user_auth
* The original user authentication service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_managerk
* The entity type manager.
*/
public function __construct(UserAuthInterface $user_auth, EntityTypeManagerInterface $entity_type_manager) {
$this->userAuth = $user_auth;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public function authenticate($username, $password) {
$config_factory = \Drupal::configFactory();
$config = $config_factory
->get('mail_login.settings');
// If we have an email lookup the username by email.
if ($config
->get('mail_login_enabled') && !empty($username)) {
if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
$account_search = $this->entityTypeManager
->getStorage('user')
->loadByProperties([
'mail' => $username,
]);
if ($account = reset($account_search)) {
$username = $account
->getAccountName();
}
}
else {
if ($config
->get('mail_login_email_only')) {
// Display a custom login error message.
\Drupal::messenger()
->addError(t('Login by username has been disabled, please use email address instead.'));
return NULL;
}
}
}
return $this->userAuth
->authenticate($username, $password);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AuthDecorator:: |
protected | property | The entity type manager. | |
AuthDecorator:: |
protected | property | The original user authentication service. | |
AuthDecorator:: |
public | function |
Validates user authentication credentials. Overrides UserAuthInterface:: |
|
AuthDecorator:: |
public | function | Constructs a UserAuth object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 |