Commit 4dc1e79a authored by sgerbino's avatar sgerbino

Initial development commit in response to feature request

http://drupal.org/node/1070688
parent d3875ca1
<?php
/**
* @file
* Admin page callbacks for the Realname registration module.
*
*/
/**
* Form builder;
*
* @ingroup forms
* @see system_settings_form()
*/
function realname_registration_settings_form() {
$form = array();
$form['realname_registration_format'] = array(
'#type' => 'radios',
'#title' => t('Username format'),
'#description' => t('Select the format in which Realname registration will create new usernames.'),
'#default_value' => variable_get('realname_registration_format', 'Firstname and lastname separated by a space'),
'#options' => array(t('Firstname and lastname separated by a space'), t('First initial and lastname')),
'#required' => TRUE,
);
$form['realname_registration_tolower'] = array(
'#type' => 'checkbox',
'#title' => t('Force lowercase'),
'#default_value' => variable_get('realname_registration_tolower'),
'#description' => t("Usernames will be created using only lowercase characters."),
);
return system_settings_form($form);
}
name = Realname Registration name = Realname Registration
description = "For registration process using first initial and last name as username." description = "For registration process using first initial and last name as username."
core = 7.x core = 7.x
files[] = realname_registration.module
files[] = realname_registration.install
files[] = realname_registration.admin.inc
configure = admin/config/people/realname_registration
\ No newline at end of file
<?php <?php
/** /**
* @file * @file
* Install, update and uninstall functions for the realname_registration module. * Install, update and uninstall functions for the realname_registration module.
......
<?php <?php
/** /**
* @file * @file
* For using real names during registration/ * For using real names during registration/
...@@ -8,6 +7,15 @@ ...@@ -8,6 +7,15 @@
* required first name and last name CCK fields on the registration form. * required first name and last name CCK fields on the registration form.
*/ */
/**
* Implement hook_help().
*/
function realname_registration_help($path, $arg) {
if ($path == 'admin/help#realname_registration') {
return t('Force usernames based on firstname and lastname fields on the registration page.');
}
}
/** /**
* Implementation of hook_form_alter(). * Implementation of hook_form_alter().
*/ */
...@@ -67,9 +75,17 @@ function realname_registration_user_presave(&$edit, $account, $category) { ...@@ -67,9 +75,17 @@ function realname_registration_user_presave(&$edit, $account, $category) {
if(isset($edit['name'])) { if(isset($edit['name'])) {
if ($edit['name'] == 'unset_username') { if ($edit['name'] == 'unset_username') {
// Generate the username based on first name and last name fields. // Generate the username based on first name and last name fields.
$first_init = drupal_substr($edit['firstname'], 0, 1); if((variable_get('realname_registration_format')) == 0) {
$lastname = $edit['lastname']; $username = $edit['firstname']." ".$edit['lastname'];
$username = strtolower($first_init . $lastname); }
if((variable_get('realname_registration_format')) == 1) {
$first_init = drupal_substr($edit['firstname'], 0, 1);
$lastname = $edit['lastname'];
$username = $first_init.$lastname;
}
if(variable_get('realname_registration_tolower')) {
$username = strtolower($username);
}
// Check if the username already exists in the database. // Check if the username already exists in the database.
$result = db_query("SELECT name FROM {users} WHERE name = :username", array(':username' => $username)); $result = db_query("SELECT name FROM {users} WHERE name = :username", array(':username' => $username));
...@@ -85,6 +101,7 @@ function realname_registration_user_presave(&$edit, $account, $category) { ...@@ -85,6 +101,7 @@ function realname_registration_user_presave(&$edit, $account, $category) {
} }
} }
} }
/** /**
* Form validation handler for user_register_form(). * Form validation handler for user_register_form().
...@@ -92,8 +109,6 @@ function realname_registration_user_presave(&$edit, $account, $category) { ...@@ -92,8 +109,6 @@ function realname_registration_user_presave(&$edit, $account, $category) {
* @see user_register_form() * @see user_register_form()
* @see user_register_submit() * @see user_register_submit()
*/ */
function realname_registration_validate($form, &$form_state) { function realname_registration_validate($form, &$form_state) {
// A first name must be letters only. // A first name must be letters only.
if (!preg_match("/^[A-ZÀ-ÖØ-öø-ÿ]+$/i", $form_state['values']['firstname'])) { if (!preg_match("/^[A-ZÀ-ÖØ-öø-ÿ]+$/i", $form_state['values']['firstname'])) {
...@@ -104,3 +119,23 @@ function realname_registration_validate($form, &$form_state) { ...@@ -104,3 +119,23 @@ function realname_registration_validate($form, &$form_state) {
form_set_error('lastname', t('Last name must only contain letters')); form_set_error('lastname', t('Last name must only contain letters'));
} }
} }
/**
* Implementation of hook_menu().
*/
function realname_registration_menu() {
$items = array();
$items['admin/config/people/realname_registration'] = array(
'title' => 'Realname registration',
'description' => 'Realname registration username settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('realname_registration_settings_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'file' => 'realname_registration.admin.inc',
);
return $items;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment