Skip to content
Snippets Groups Projects
Commit 929c4fa9 authored by Mohammad AlQanneh's avatar Mohammad AlQanneh Committed by Mohammad AlQanneh
Browse files

Issue #3342236 by himanshu_jhaloya, mqanneh, Sonal Gyanani, apaderno: Fix the...

Issue #3342236 by himanshu_jhaloya, mqanneh, Sonal Gyanani, apaderno: Fix the issues reported by phpcs
parent 41583c11
No related branches found
No related tags found
No related merge requests found
......@@ -45,7 +45,8 @@ Go to "/admin/config/people/accounts/mail-login" for the configuration screen,
* Login form username title: Override the username field title.
* Login form username description: Override the username field description.
* Password reset form username title: Override the username field title.
* Password reset form username description: Override the username field description.
* Password reset form username description: Override the
username field description.
## Maintainers
......
......@@ -3,4 +3,4 @@ services:
class: Drupal\mail_login\AuthDecorator
decorates: user.auth
public: false
arguments: ['@mail_login.auth.inner', '@entity_type.manager', '@database']
arguments: ['@mail_login.auth.inner', '@entity_type.manager', '@database', '@config.factory', '@messenger']
......@@ -2,9 +2,12 @@
namespace Drupal\mail_login;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\user\UserAuthInterface;
/**
......@@ -12,6 +15,7 @@ use Drupal\user\UserAuthInterface;
*/
class AuthDecorator implements UserAuthInterface {
use DependencySerializationTrait;
use StringTranslationTrait;
/**
* The original user authentication service.
......@@ -34,27 +38,53 @@ class AuthDecorator implements UserAuthInterface {
*/
protected $connection;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The messenger.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Constructs a UserAuth object.
*
* @param \Drupal\user\UserAuthInterface $user_auth
* The original user authentication service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_managerk
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct(UserAuthInterface $user_auth, EntityTypeManagerInterface $entity_type_manager, Connection $connection) {
public function __construct(
UserAuthInterface $user_auth,
EntityTypeManagerInterface $entity_type_manager,
Connection $connection,
ConfigFactoryInterface $config_factory,
MessengerInterface $messenger) {
$this->userAuth = $user_auth;
$this->entityTypeManager = $entity_type_manager;
$this->connection = $connection;
$this->configFactory = $config_factory;
$this->messenger = $messenger;
}
/**
* {@inheritdoc}
*/
public function authenticate($username, $password) {
$config_factory = \Drupal::configFactory();
$config_factory = $this->configFactory;
$config = $config_factory->get('mail_login.settings');
// If we have an email lookup the username by email.
......@@ -67,7 +97,7 @@ class AuthDecorator implements UserAuthInterface {
// there is only a single match (as case-sensitive email addresses are
// permitted by RFC 5321).
$db = $this->connection;
$user_ids = \Drupal::entityQuery('user')
$user_ids = $this->entityTypeManager->getStorage('user')->getQuery()
->accessCheck(FALSE)
->condition('mail', $db->escapeLike($username), 'LIKE')
->execute();
......@@ -77,17 +107,17 @@ class AuthDecorator implements UserAuthInterface {
}
if ($account = reset($account_search)) {
$username = $account->getAccountName();
if($account->isBlocked()) {
\Drupal::messenger()->addError(t('The user has not been activated yet or is blocked.'));
if ($account->isBlocked()) {
$this->messenger->addError($this->t('The user has not been activated yet or is blocked.'));
return FALSE;
}
}
}
// Check if login by email only option is enabled.
else if ($config->get('mail_login_email_only')) {
elseif ($config->get('mail_login_email_only')) {
// Display a custom login error message.
\Drupal::messenger()->addError(
t('Login by username has been disabled. Use your email address instead.')
$this->messenger->addError(
$this->t('Login by username has been disabled. Use your email address instead.')
);
return FALSE;
}
......
......@@ -2,8 +2,10 @@
namespace Drupal\mail_login\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Configure Mail Login settings.
......@@ -24,11 +26,36 @@ class MailLoginAdminSettingsForm extends ConfigFormBase {
return ['mail_login.settings'];
}
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* MailLoginAdminSettingsForm constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
*/
public function __construct(ConfigFactoryInterface $configFactory) {
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory')
);
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = \Drupal::service('config.factory')->getEditable('mail_login.settings');
$config = $this->configFactory->getEditable('mail_login.settings');
$form['general'] = [
'#type' => 'fieldset',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment