contrib modules updates
This commit is contained in:
@@ -1,44 +1,45 @@
|
||||
Email Registration allows users to register and login with their e-mail address
|
||||
instead of using a separate username in addition to the e-mail address. It will
|
||||
automatically generate a username based on the e-mail address but that behavior
|
||||
INTRODUCTION
|
||||
------------
|
||||
|
||||
Email Registration allows users to register and login with their email address
|
||||
instead of using a separate username in addition to the email address. It will
|
||||
automatically generate a username based on the email address but that behavior
|
||||
can be overridden with a custom hook implementation in a site specific module.
|
||||
|
||||
INSTALLATION
|
||||
============
|
||||
------------
|
||||
|
||||
Required step:
|
||||
|
||||
1. Enable the module as you normally would.
|
||||
Enable the module as you normally would. See:
|
||||
https://www.drupal.org/docs/8/extending-drupal-8/installing-modules
|
||||
|
||||
|
||||
Optional steps:
|
||||
CONFIGURATION
|
||||
-------------
|
||||
|
||||
2. You will probably want to change the welcome e-mail
|
||||
(Administer -> User Management -> User Settings) and replace instances of
|
||||
the token !username with !mailto
|
||||
* You will probably want to change the welcome email (Administration
|
||||
-> Configuration -> People -> Account Settings) and replace instances of the
|
||||
token [user:display-name] with [user:mail].
|
||||
|
||||
3. This automatically generated username is still displayed name for posts,
|
||||
comments, etc. You can allow your users to change their username by
|
||||
going to: (Administer -> User Management -> Access Control) and granting
|
||||
the permission to "change own username"
|
||||
This privilege allows a user to change their username in "My Account".
|
||||
* The automatically generated username is still displayed name for posts,
|
||||
comments, etc. You can allow your users to change their username by granting
|
||||
the permission (Administraion -> People -> Permissions) to "change own
|
||||
username". This privilege allows a user to change their username in "My
|
||||
Account".
|
||||
|
||||
4. If a user enters an invalid email or password they will see a message:
|
||||
"Sorry, unrecognized username or password. Have you forgotten your password?"
|
||||
* If a user enters an invalid email or password they will see a message:
|
||||
"Unrecognized username or password. Forgot your password?"
|
||||
That message is confusing because it mentions username when all other
|
||||
language on the page mentions entering their E-mail. This can be easily
|
||||
language on the page mentions entering their email. This can be easily
|
||||
overridden in your settings.php file with an entry like this:
|
||||
|
||||
$conf['locale_custom_strings_en'][''] = array(
|
||||
'Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>' => 'Sorry, unrecognized e-mail or password. <a href="@password">Have you forgotten your password?</a>',
|
||||
);
|
||||
|
||||
|
||||
|
||||
$settings['locale_custom_strings_en'][''] = [
|
||||
'Unrecognized username or password. <a href=":password">Forgot your password?</a>' => 'Unrecognized e-mail address or password. <a href=":password">Forgot your password?</a>',
|
||||
];
|
||||
|
||||
BUGS, FEATURES, QUESTIONS
|
||||
=========================
|
||||
-------------------------
|
||||
Post any bugs, features or questions to the issue queue:
|
||||
|
||||
http://drupal.org/project/issues/email_registration
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "drupal/email_registration",
|
||||
"type": "drupal-module",
|
||||
"description": "Allows users to register with an email address as their username.",
|
||||
"license": "GPL-2.0+",
|
||||
"homepage": "https://www.drupal.org/project/email_registration",
|
||||
"minimum-stability": "dev",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Greg Knaddison (greggles)",
|
||||
"homepage": "https://www.drupal.org/u/greggles",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Andrey Postnikov (andypost)",
|
||||
"homepage": "https://www.drupal.org/u/andypost",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Chris Herberte",
|
||||
"homepage": "https://www.drupal.org/u/chris-herberte",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Moshe Weitzman (moshe weitzman)",
|
||||
"homepage": "https://www.drupal.org/u/moshe-weitzman",
|
||||
"role": "Maintainer"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "http://drupal.org/project/issues/email_registration",
|
||||
"source": "http://cgit.drupalcode.org/email_registration"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,4 +4,4 @@ email_registration.settings:
|
||||
mapping:
|
||||
login_with_username:
|
||||
type: boolean
|
||||
label: 'Allow users to log in with e-mail or username.'
|
||||
label: 'Allow users to log in with email address or username.'
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
name: Email Registration
|
||||
type: module
|
||||
description: 'Allows users to register with an e-mail address as their username.'
|
||||
description: 'Allows users to register with an email address as their username.'
|
||||
# core: 8.x
|
||||
dependencies:
|
||||
- drupal:user
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-04-04
|
||||
version: '8.x-1.0-rc5'
|
||||
# Information added by Drupal.org packaging script on 2018-12-21
|
||||
version: '8.x-1.0-rc6'
|
||||
core: '8.x'
|
||||
project: 'email_registration'
|
||||
datestamp: 1491318185
|
||||
datestamp: 1545350889
|
||||
|
||||
@@ -9,23 +9,23 @@
|
||||
* Implements hook_requirements().
|
||||
*/
|
||||
function email_registration_requirements() {
|
||||
$requirements = array();
|
||||
$requirements = [];
|
||||
|
||||
// @todo Get rid of variable_get() and check is this conflict still valid.
|
||||
if (\Drupal::moduleHandler()->moduleExists('logintoboggan') && \Drupal::config('logintoboggan.settings')->get('login_with_email')) {
|
||||
$requirements['email_registration'] = array(
|
||||
$requirements['email_registration'] = [
|
||||
'title' => t('Email Registration / LoginToboggan Conflict'),
|
||||
'value' => t('Conflict'),
|
||||
'description' => t('There is a conflict between %email_registration and %logintoboggan. You should disable the "Allow users to login using their e-mail address" option from %logintoboggan.', array('%email_registration' => 'Email registration', '%logintoboggan' => 'Login Toboggan')),
|
||||
'description' => t('There is a conflict between %email_registration and %logintoboggan. You should disable the "Allow users to login using their email address" option from %logintoboggan.', ['%email_registration' => 'Email registration', '%logintoboggan' => 'Login Toboggan']),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an option to log in with the username as well as the e-mail address.
|
||||
* Add an option to log in with the username as well as the email address.
|
||||
*/
|
||||
function email_registration_update_8100() {
|
||||
$config_factory = \Drupal::configFactory();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Allows users to register with an e-mail address as their username.
|
||||
* Allows users to register with an email address as their username.
|
||||
*/
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
@@ -26,7 +26,7 @@ function email_registration_user_insert(UserInterface $account) {
|
||||
// Other modules may implement hook_email_registration_name($edit, $account)
|
||||
// to generate a username (return a string to be used as the username, NULL
|
||||
// to have email_registration generate it).
|
||||
$names = Drupal::moduleHandler()->invokeAll('email_registration_name', array($account));
|
||||
$names = Drupal::moduleHandler()->invokeAll('email_registration_name', [$account]);
|
||||
// Remove any empty entries.
|
||||
$names = array_filter($names);
|
||||
|
||||
@@ -81,7 +81,7 @@ function email_registration_unique_username($name, $uid = 0) {
|
||||
$database = \Drupal::database();
|
||||
do {
|
||||
$new_name = empty($i) ? $name : $name . '_' . $i;
|
||||
$found = $database->queryRange("SELECT uid from {users_field_data} WHERE uid <> :uid AND name = :name", 0, 1, array(':uid' => $uid, ':name' => $new_name))->fetchAssoc();
|
||||
$found = $database->queryRange("SELECT uid from {users_field_data} WHERE uid <> :uid AND name = :name", 0, 1, [':uid' => $uid, ':name' => $new_name])->fetchAssoc();
|
||||
$i++;
|
||||
} while (!empty($found));
|
||||
|
||||
@@ -115,27 +115,31 @@ function email_registration_cleanup_username($name) {
|
||||
$name = ('' === $name) ? t('user') : $name;
|
||||
|
||||
// Truncate to a reasonable size.
|
||||
$name = (Unicode::strlen($name) > (USERNAME_MAX_LENGTH - 10)) ? Unicode::substr($name, 0, USERNAME_MAX_LENGTH - 11) : $name;
|
||||
$name = (Unicode::strlen($name) > (UserInterface::USERNAME_MAX_LENGTH - 10)) ? Unicode::substr($name, 0, UserInterface::USERNAME_MAX_LENGTH - 11) : $name;
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
* Implements hook_form_BASE_FORM_ID_alter().
|
||||
*/
|
||||
function email_registration_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
|
||||
function email_registration_form_user_form_alter(&$form, FormStateInterface $form_state) {
|
||||
$form['account']['name']['#type'] = 'value';
|
||||
$form['account']['name']['#value'] = 'email_registration_' . user_password();
|
||||
$form['account']['mail']['#title'] = t('E-mail');
|
||||
$form['account']['mail']['#title'] = t('Email');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function email_registration_form_user_pass_alter(&$form, FormStateInterface $form_state) {
|
||||
$form['name']['#title'] = t('E-mail');
|
||||
// Allow client side validation of input format.
|
||||
$form['name']['#type'] = 'email';
|
||||
$form['name']['#maxlength'] = Email::EMAIL_MAX_LENGTH;
|
||||
$form['name']['#title'] = t('Email');
|
||||
// Only convert textfields to email fields. This field is a hidden value when
|
||||
// you are already logged in.
|
||||
if ($form['name']['#type'] == 'textfield') {
|
||||
// Allow client side validation of input format.
|
||||
$form['name']['#type'] = 'email';
|
||||
$form['name']['#maxlength'] = Email::EMAIL_MAX_LENGTH;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,10 +148,10 @@ function email_registration_form_user_pass_alter(&$form, FormStateInterface $for
|
||||
function email_registration_form_user_login_form_alter(&$form, FormStateInterface $form_state) {
|
||||
$config = \Drupal::config('email_registration.settings');
|
||||
$login_with_username = $config->get('login_with_username');
|
||||
$form['name']['#title'] = $login_with_username ? t('E-mail or username') : t('E-mail');
|
||||
$form['name']['#description'] = $login_with_username ? t('Enter your e-mail address or username.') : t('Enter your e-mail address.');
|
||||
$form['name']['#title'] = $login_with_username ? t('Email or username') : t('Email');
|
||||
$form['name']['#description'] = $login_with_username ? t('Enter your email address or username.') : t('Enter your email address.');
|
||||
$form['name']['#element_validate'][] = 'email_registration_user_login_validate';
|
||||
$form['pass']['#description'] = t('Enter the password that accompanies your e-mail.');
|
||||
$form['pass']['#description'] = t('Enter the password that accompanies your email address.');
|
||||
// Allow client side validation of input format.
|
||||
$form['name']['#type'] = $login_with_username ? 'textfield' : 'email';
|
||||
$form['name']['#maxlength'] = Email::EMAIL_MAX_LENGTH;
|
||||
@@ -170,18 +174,11 @@ function email_registration_user_login_validate($form, FormStateInterface $form_
|
||||
elseif (!$config->get('login_with_username')) {
|
||||
$user_input = $form_state->getUserInput();
|
||||
$query = isset($user_input['name']) ? ['name' => $user_input['name']] : [];
|
||||
$form_state->setErrorByName('name', t('Unrecognized e-mail address or password. <a href=":password">Forgot your password?</a>', [':password' => Url::fromRoute('user.pass', [], ['query' => $query])->toString()]));
|
||||
$form_state->setErrorByName('name', t('Unrecognized email address or password. <a href=":password">Forgot your password?</a>', [':password' => Url::fromRoute('user.pass', [], ['query' => $query])->toString()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function email_registration_form_user_form_alter(&$form, FormStateInterface $form_state) {
|
||||
$form['account']['name']['#title'] = t('Display name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
@@ -189,8 +186,8 @@ function email_registration_form_user_admin_settings_alter(&$form, FormStateInte
|
||||
$config = \Drupal::config('email_registration.settings');
|
||||
$form['registration_cancellation']['login_with_username'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Allow to log in with e-mail or username.'),
|
||||
'#description' => t('Allow users to log in with either their username or their e-mail address.'),
|
||||
'#title' => t('Allow log in with email address or username.'),
|
||||
'#description' => t('Allow users to log in with either their email address or their username.'),
|
||||
'#default_value' => $config->get('login_with_username'),
|
||||
];
|
||||
$form['#submit'][] = 'email_registration_form_user_admin_settings_submit';
|
||||
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\email_registration\Plugin\Commerce\CheckoutPane;
|
||||
|
||||
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\Login;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Render\Element\Email;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Provides the email registration login pane.
|
||||
*
|
||||
* @CommerceCheckoutPane(
|
||||
* id = "email_registration_login",
|
||||
* label = @Translation("Login with email registration or continue as guest"),
|
||||
* default_step = "_disabled",
|
||||
* )
|
||||
*/
|
||||
class EmailRegistrationLogin extends Login {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
|
||||
$pane_form = parent::buildPaneForm($pane_form, $form_state, $complete_form);
|
||||
|
||||
$config = \Drupal::config('email_registration.settings');
|
||||
$login_with_username = $config->get('login_with_username');
|
||||
$pane_form['returning_customer']['name']['#title'] = $login_with_username ? t('Email address or username') : t('Email address');
|
||||
$pane_form['returning_customer']['name']['#description'] = $login_with_username ? t('Enter your email address or username.') : t('Enter your email address.');
|
||||
$pane_form['returning_customer']['name']['#element_validate'][] = 'email_registration_user_login_validate';
|
||||
$pane_form['returning_customer']['name']['#type'] = $login_with_username ? 'textfield' : 'email';
|
||||
$pane_form['returning_customer']['name']['#maxlength'] = Email::EMAIL_MAX_LENGTH;
|
||||
$pane_form['returning_customer']['password']['#description'] = t('Enter the password that accompanies your email address.');
|
||||
$complete_form['#cache']['tags'][] = 'config:email_registration.settings';
|
||||
|
||||
$pane_form['register']['name']['#type'] = 'value';
|
||||
$pane_form['register']['name']['#value'] = 'email_registration_' . user_password();
|
||||
$pane_form['register']['mail']['#title'] = t('Email');
|
||||
|
||||
return $pane_form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validatePaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
|
||||
$values = $form_state->getValue($pane_form['#parents']);
|
||||
$triggering_element = $form_state->getTriggeringElement();
|
||||
if ($triggering_element['#op'] === 'login') {
|
||||
$mail = $form_state->getValue([
|
||||
'email_registration_login',
|
||||
'returning_customer',
|
||||
'name',
|
||||
]);
|
||||
if (!empty($mail)) {
|
||||
$config = \Drupal::config('email_registration.settings');
|
||||
if ($user = user_load_by_mail($mail)) {
|
||||
$username = $user->getAccountName();
|
||||
$form_state->setValue([
|
||||
'email_registration_login',
|
||||
'returning_customer',
|
||||
'name',
|
||||
], $username);
|
||||
}
|
||||
elseif (!$config->get('login_with_username')) {
|
||||
$user_input = $form_state->getUserInput();
|
||||
$query = isset($user_input['email_registration_login']['returning_customer']['name']) ? ['name' => $user_input['email_registration_login']['returning_customer']['name']] : [];
|
||||
$form_state->setError($pane_form['returning_customer'], t('Unrecognized email address or password. <a href=":password">Forgot your password?</a>', [
|
||||
':password' => Url::fromRoute('user.pass', [], ['query' => $query])
|
||||
->toString(),
|
||||
]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
$name_element = $pane_form['returning_customer']['name'];
|
||||
$password = trim($values['returning_customer']['password']);
|
||||
// Generate the "reset password" url.
|
||||
$query = !empty($username) ? ['name' => $username] : [];
|
||||
$password_url = Url::fromRoute('user.pass', [], ['query' => $query])
|
||||
->toString();
|
||||
|
||||
if (user_is_blocked($username)) {
|
||||
$form_state->setError($name_element, $this->t('The account with email address %mail has not been activated or is blocked.', ['%mail' => $mail]));
|
||||
return;
|
||||
}
|
||||
if (!$this->credentialsCheckFlood->isAllowedHost($this->clientIp)) {
|
||||
$form_state->setErrorByName($name_element, $this->t('Too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or <a href=":url">request a new password</a>.', [':url' => Url::fromRoute('user.pass')]));
|
||||
$this->credentialsCheckFlood->register($this->clientIp, $username);
|
||||
return;
|
||||
}
|
||||
elseif (!$this->credentialsCheckFlood->isAllowedAccount($this->clientIp, $username)) {
|
||||
$form_state->setErrorByName($name_element, $this->t('Too many failed login attempts for this account. It is temporarily blocked. Try again later or <a href=":url">request a new password</a>.', [':url' => Url::fromRoute('user.pass')]));
|
||||
$this->credentialsCheckFlood->register($this->clientIp, $username);
|
||||
return;
|
||||
}
|
||||
|
||||
$uid = $this->userAuth->authenticate($username, $password);
|
||||
if (!$uid) {
|
||||
$this->credentialsCheckFlood->register($this->clientIp, $username);
|
||||
$form_state->setError($name_element, $this->t('Unrecognized email address or password. <a href=":password">Forgot your password?</a>', [':url' => $password_url]));
|
||||
}
|
||||
$form_state->set('logged_in_uid', $uid);
|
||||
}
|
||||
parent::validatePaneForm($pane_form, $form_state, $complete_form);
|
||||
}
|
||||
|
||||
}
|
||||
+17
-17
@@ -16,7 +16,7 @@ class EmailRegistrationTestCase extends BrowserTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('email_registration');
|
||||
public static $modules = ['email_registration'];
|
||||
|
||||
/**
|
||||
* Test various behaviors for anonymous users.
|
||||
@@ -31,18 +31,18 @@ class EmailRegistrationTestCase extends BrowserTestBase {
|
||||
// Try to register a user.
|
||||
$name = $this->randomMachineName();
|
||||
$pass = $this->randomString(10);
|
||||
$register = array(
|
||||
$register = [
|
||||
'mail' => $name . '@example.com',
|
||||
'pass[pass1]' => $pass,
|
||||
'pass[pass2]' => $pass,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('/user/register', $register, t('Create new account'));
|
||||
$this->drupalLogout();
|
||||
|
||||
$login = array(
|
||||
$login = [
|
||||
'name' => $name . '@example.com',
|
||||
'pass' => $pass,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('user/login', $login, t('Log in'));
|
||||
|
||||
// Really basic confirmation that the user was created and logged in.
|
||||
@@ -53,13 +53,13 @@ class EmailRegistrationTestCase extends BrowserTestBase {
|
||||
|
||||
// Try to login with just username, should fail by default.
|
||||
$this->drupalGet('user/login');
|
||||
$this->assertText('Enter your e-mail address.');
|
||||
$this->assertText('E-mail');
|
||||
$this->assertNoText('E-mail or username');
|
||||
$login = array(
|
||||
$this->assertText('Enter your email address.');
|
||||
$this->assertText('Email');
|
||||
$this->assertNoText('Email or username');
|
||||
$login = [
|
||||
'name' => $name,
|
||||
'pass' => $pass,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('user/login', $login, t('Log in'));
|
||||
$error_message = $this->xpath('//div[contains(@class, "error")]');
|
||||
$this->assertTrue(!empty($error_message), t('When login_with_username is false, a user cannot login with just their username.'));
|
||||
@@ -67,8 +67,8 @@ class EmailRegistrationTestCase extends BrowserTestBase {
|
||||
// Set login_with_username to TRUE and try to login with just username.
|
||||
$email_registration_config->set('login_with_username', TRUE)->save();
|
||||
$this->drupalGet('user/login');
|
||||
$this->assertText('Enter your e-mail address or username.');
|
||||
$this->assertText('E-mail or username');
|
||||
$this->assertText('Enter your email address or username.');
|
||||
$this->assertText('Email or username');
|
||||
$this->drupalPostForm('user/login', $login, t('Log in'));
|
||||
$this->assertRaw('<title>' . $name . ' | Drupal</title>', t('When login_with_username is true, a user can login with just their username.'));
|
||||
$this->drupalLogout();
|
||||
@@ -78,11 +78,11 @@ class EmailRegistrationTestCase extends BrowserTestBase {
|
||||
->save();
|
||||
$name = $this->randomMachineName();
|
||||
$pass = $this->randomString(10);
|
||||
$register = array(
|
||||
$register = [
|
||||
'mail' => $name . '@example.com',
|
||||
'pass[pass1]' => $pass,
|
||||
'pass[pass2]' => $pass,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('/user/register', $register, t('Create new account'));
|
||||
$this->assertRaw('Registration successful. You are now logged in.', t('User properly created, immediately logged in.'));
|
||||
|
||||
@@ -95,14 +95,14 @@ class EmailRegistrationTestCase extends BrowserTestBase {
|
||||
$name = $this->randomMachineName(32);
|
||||
$pass = $this->randomString(10);
|
||||
|
||||
$this->createUser(array(), $name);
|
||||
$this->createUser([], $name);
|
||||
$next_unique_name = email_registration_unique_username($name);
|
||||
|
||||
$register = array(
|
||||
$register = [
|
||||
'mail' => $name . '@example2.com',
|
||||
'pass[pass1]' => $pass,
|
||||
'pass[pass2]' => $pass,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('/user/register', $register, t('Create new account'));
|
||||
$account = user_load_by_mail($register['mail']);
|
||||
$this->assertTrue($next_unique_name === $account->getAccountName());
|
||||
|
||||
Reference in New Issue
Block a user