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
description = "For registration process using first initial and last name as username."
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
/**
* @file
* Install, update and uninstall functions for the realname_registration module.
......
<?php
/**
* @file
* For using real names during registration/
......@@ -8,6 +7,15 @@
* 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().
*/
......@@ -67,9 +75,17 @@ function realname_registration_user_presave(&$edit, $account, $category) {
if(isset($edit['name'])) {
if ($edit['name'] == 'unset_username') {
// Generate the username based on first name and last name fields.
if((variable_get('realname_registration_format')) == 0) {
$username = $edit['firstname']." ".$edit['lastname'];
}
if((variable_get('realname_registration_format')) == 1) {
$first_init = drupal_substr($edit['firstname'], 0, 1);
$lastname = $edit['lastname'];
$username = strtolower($first_init . $lastname);
$username = $first_init.$lastname;
}
if(variable_get('realname_registration_tolower')) {
$username = strtolower($username);
}
// Check if the username already exists in the database.
$result = db_query("SELECT name FROM {users} WHERE name = :username", array(':username' => $username));
......@@ -86,14 +102,13 @@ function realname_registration_user_presave(&$edit, $account, $category) {
}
}
/**
* Form validation handler for user_register_form().
*
* @see user_register_form()
* @see user_register_submit()
*/
function realname_registration_validate($form, &$form_state) {
// A first name must be letters only.
if (!preg_match("/^[A-ZÀ-ÖØ-öø-ÿ]+$/i", $form_state['values']['firstname'])) {
......@@ -104,3 +119,23 @@ function realname_registration_validate($form, &$form_state) {
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