non security modules update
This commit is contained in:
@@ -34,11 +34,8 @@ $conf['locale_custom_strings_en'][''] = array(
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
BUGS, FEATURES, QUESTIONS
|
||||
=========================
|
||||
Post any bugs, features or questions to the issue queue:
|
||||
|
||||
http://drupal.org/project/issues/email_registration
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Documentation for email_registration API.
|
||||
* Documentation for email_registration module API.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -17,16 +17,19 @@
|
||||
* to generate a username (return a string to be used as the username, NULL
|
||||
* to have email_registration generate it).
|
||||
*
|
||||
* @param $edit
|
||||
* @param array $edit
|
||||
* The array of form values submitted by the user.
|
||||
* @param $account
|
||||
* @param object $account
|
||||
* The user object on which the operation is being performed.
|
||||
*
|
||||
* @return
|
||||
* @return string
|
||||
* A string defining a generated username.
|
||||
*/
|
||||
function hook_email_registration_name($edit, $account) {
|
||||
return 'u' . $account->uid;
|
||||
// Your hook implementation should ensure that the resulting string
|
||||
// works as a username. You can use email_registration_cleanup_username($name)
|
||||
// to clean up the name.
|
||||
return email_registration_cleanup_username('u' . $account->uid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -3,9 +3,9 @@ description = Allows users to register with an e-mail address as their username.
|
||||
files[] = email_registration.test
|
||||
core = 7.x
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-01-19
|
||||
version = "7.x-1.1"
|
||||
; Information added by Drupal.org packaging script on 2014-04-23
|
||||
version = "7.x-1.2"
|
||||
core = "7.x"
|
||||
project = "email_registration"
|
||||
datestamp = "1358554303"
|
||||
datestamp = "1398265775"
|
||||
|
||||
|
@@ -24,6 +24,8 @@ function email_registration_user_insert(&$edit, &$account, $category = NULL) {
|
||||
if (empty($names)) {
|
||||
// Strip off everything after the @ sign.
|
||||
$new_name = preg_replace('/@.*$/', '', $edit['mail']);
|
||||
// Clean up the username.
|
||||
$new_name = email_registration_cleanup_username($new_name, $account->uid);
|
||||
}
|
||||
else {
|
||||
// One would expect a single implementation of the hook, but if there
|
||||
@@ -42,46 +44,30 @@ function email_registration_user_insert(&$edit, &$account, $category = NULL) {
|
||||
|
||||
$edit['name'] = $new_name;
|
||||
$account->name = $new_name;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a starting point for a Drupal username (e.g. the name portion of an
|
||||
* email address) return a legal, unique Drupal username. This function is
|
||||
* designed to work on the results of the /user/register or /admin/people/create
|
||||
* forms which have already called user_validate_name, valid_email_address
|
||||
* or a similar function. If your custom code is creating users, you should
|
||||
* ensure that the email/name is already validated using something like that.
|
||||
* Given a starting point returns a legal, unique Drupal username.
|
||||
*
|
||||
* @param $name
|
||||
* A name from which to base the final user name. May contain illegal characters; these will be stripped.
|
||||
* This function is designed to work on the results of the /user/register or
|
||||
* /admin/people/create forms which have already called user_validate_name,
|
||||
* valid_email_address or a similar function. If your custom code is creating
|
||||
* users, you should ensure that the email/name is already validated using
|
||||
* something like that.
|
||||
*
|
||||
* @param $uid
|
||||
* (optional) Uid to ignore when searching for unique user (e.g. if we update the username after the
|
||||
* {users} row is inserted)
|
||||
* @param string $name
|
||||
* A name from which to base the final user name. May contain illegal
|
||||
* characters; these will be stripped.
|
||||
* @param int $uid
|
||||
* (optional) Uid to ignore when searching for unique user
|
||||
* (e.g. if we update the username after the {users} row is inserted)
|
||||
*
|
||||
* @return
|
||||
* @return string
|
||||
* A unique user name based on $name.
|
||||
*
|
||||
* @see user_validate_name().
|
||||
*
|
||||
* @see user_validate_name()
|
||||
*/
|
||||
function email_registration_unique_username($name, $uid = 0) {
|
||||
// Strip illegal characters.
|
||||
$name = preg_replace('/[^\x{80}-\x{F7} a-zA-Z0-9@_.\'-]/', '', $name);
|
||||
|
||||
// Strip leading and trailing spaces.
|
||||
$name = trim($name);
|
||||
|
||||
// Convert any other series of spaces to a single underscore.
|
||||
$name = preg_replace('/ +/', '_', $name);
|
||||
|
||||
// If there's nothing left use a default.
|
||||
$name = ('' === $name) ? t('user') : $name;
|
||||
|
||||
// Truncate to reasonable size.
|
||||
$name = (drupal_strlen($name) > (USERNAME_MAX_LENGTH - 10)) ? drupal_substr($name, 0, USERNAME_MAX_LENGTH - 11) : $name;
|
||||
|
||||
function email_registration_unique_username($name, $uid) {
|
||||
// Iterate until we find a unique name.
|
||||
$i = 0;
|
||||
do {
|
||||
@@ -93,12 +79,47 @@ function email_registration_unique_username($name, $uid = 0) {
|
||||
return $new_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to clean up username.
|
||||
*
|
||||
* e.g.
|
||||
* Replace two or more spaces with a single underscore
|
||||
* Strip illegal characters.
|
||||
*
|
||||
* @param string $name
|
||||
* The username to be cleaned up.
|
||||
*
|
||||
* @return string
|
||||
* Cleaned up username.
|
||||
*/
|
||||
function email_registration_cleanup_username($name, $uid = NULL) {
|
||||
// Strip illegal characters.
|
||||
$name = preg_replace('/[^\x{80}-\x{F7} a-zA-Z0-9@_.\'-]/', '', $name);
|
||||
|
||||
// Strip leading and trailing spaces.
|
||||
$name = trim($name);
|
||||
|
||||
// Convert any other series of spaces to a single underscore.
|
||||
$name = preg_replace('/ +/', '_', $name);
|
||||
|
||||
// If there's nothing left use a default.
|
||||
$name = ('' === $name) ? t('user') : $name;
|
||||
|
||||
if (!empty($uid)) {
|
||||
// Put uid on the end of the name.
|
||||
$name = $name . '_' . $uid;
|
||||
}
|
||||
|
||||
// Truncate to a reasonable size.
|
||||
$name = (drupal_strlen($name) > (USERNAME_MAX_LENGTH - 10)) ? drupal_substr($name, 0, USERNAME_MAX_LENGTH - 11) : $name;
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function email_registration_form_user_register_form_alter(&$form, &$form_state) {
|
||||
$form['account']['name']['#type'] = 'value';
|
||||
$form['account']['name']['#type'] = 'hidden';
|
||||
$form['account']['name']['#value'] = 'email_registration_' . user_password();
|
||||
$form['account']['mail']['#title'] = t('E-mail');
|
||||
}
|
||||
@@ -108,7 +129,6 @@ function email_registration_form_user_register_form_alter(&$form, &$form_state)
|
||||
*/
|
||||
function email_registration_form_user_pass_alter(&$form, &$form_state) {
|
||||
$form['name']['#title'] = t('E-mail');
|
||||
$form['name']['#description'] = t('A password reset message will be sent to your e-mail address.');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,11 +151,12 @@ function email_registration_form_user_login_block_alter(&$form, &$form_state) {
|
||||
|
||||
/**
|
||||
* Form element validation handler for the user login form.
|
||||
*
|
||||
* Allows users to authenticate by email, which is our preferred method.
|
||||
*/
|
||||
function email_registration_user_login_validate($form, &$form_state) {
|
||||
if (isset($form_state['values']['name'])) {
|
||||
// Keep the email value in form state for furher validation.
|
||||
// Keep the email value in form state for further validation.
|
||||
$form_state['values']['email'] = $form_state['values']['name'];
|
||||
if ($name = db_query('SELECT name FROM {users} WHERE LOWER(mail) = LOWER(:name)', array(':name' => $form_state['values']['name']))->fetchField()) {
|
||||
$form_state['values']['name'] = $name;
|
||||
@@ -146,6 +167,6 @@ function email_registration_user_login_validate($form, &$form_state) {
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function email_registration_form_user_profile_form_alter($form, &$form_state) {
|
||||
function email_registration_form_user_profile_form_alter(&$form, &$form_state) {
|
||||
$form['account']['name']['#title'] = t('Display name');
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* email registration simpletest
|
||||
* Contains EmailRegistrationTestCase.
|
||||
*/
|
||||
|
||||
class EmailRegistrationTestCase extends DrupalWebTestCase {
|
||||
@@ -20,7 +20,7 @@ class EmailRegistrationTestCase extends DrupalWebTestCase {
|
||||
/**
|
||||
* Implementation of setUp().
|
||||
*/
|
||||
function setUp() {
|
||||
public function setUp() {
|
||||
parent::setUp('email_registration');
|
||||
|
||||
// Configure to allow set password.
|
||||
@@ -30,7 +30,7 @@ class EmailRegistrationTestCase extends DrupalWebTestCase {
|
||||
/**
|
||||
* Test various behaviors for anonymous users.
|
||||
*/
|
||||
function testRegistration() {
|
||||
public function testRegistration() {
|
||||
variable_set('user_register', USER_REGISTER_VISITORS);
|
||||
// Try to register a user.
|
||||
$name = $this->randomName();
|
||||
@@ -49,8 +49,12 @@ class EmailRegistrationTestCase extends DrupalWebTestCase {
|
||||
);
|
||||
$this->drupalPost('user/login', $login, t('Log in'));
|
||||
|
||||
// Really basic confirmation that the user was created and logged in.
|
||||
$this->assertRaw('<title>' . $name . ' | Drupal</title>', t('User properly created, logged in.'));
|
||||
// Get the uid.
|
||||
$accounts = user_load_multiple(array(), array('mail' => $name . '@example.com'));
|
||||
$new_user = reset($accounts);
|
||||
|
||||
// Confirm the user was created and logged in with expected username.
|
||||
$this->assertRaw('<title>' . $name . '_' . $new_user->uid . ' | Drupal</title>', t('User properly created, logged in.'));
|
||||
|
||||
// Now try the immediate login.
|
||||
$this->drupalLogout();
|
||||
@@ -64,6 +68,6 @@ class EmailRegistrationTestCase extends DrupalWebTestCase {
|
||||
);
|
||||
$this->drupalPost('/user/register', $register, t('Create new account'));
|
||||
$this->assertRaw('Registration successful. You are now logged in.', t('User properly created, immediately logged in.'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user