Commit be62cfcb authored by Chris Herberte's avatar Chris Herberte

fix profile module $form['account'] array issue

coder review corrections
parent 6255005e
......@@ -7,19 +7,19 @@
*/
function email_registration_user($op, &$edit, &$account, $category = NULL) {
switch($op) {
switch ($op) {
case 'insert':
$namenew = preg_replace('/@.*$/', '', $edit['mail']);
$namenew = preg_replace('/@.*$/', '', $edit['mail']);
// if username generated from email record already exists, append underscore and number eg:(chris_123)
if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $account->uid, $namenew)) > 0) {
if (db_result(db_query("SELECT count(*) FROM {users} WHERE uid <> %d AND LOWER(name) = LOWER('%s')", $account->uid, $namenew)) > 0) {
// find the next number available to append to the name
$sql = "SELECT SUBSTRING_INDEX(name,'_',-1) FROM {users} WHERE name REGEXP '^%s_[0-9]+$' ORDER BY CAST(SUBSTRING_INDEX(name,'_',-1) AS UNSIGNED) DESC LIMIT 1";
$nameidx = db_result(db_query($sql, $namenew));
$namenew .= '_' . ($nameidx + 1);
$namenew .= '_'. ($nameidx + 1);
}
// replace with generated username
db_query("UPDATE {users} SET name = '%s' WHERE uid = '%s'", $namenew, $account->uid);
break;
break;
}
return;
}
......@@ -29,39 +29,45 @@ function email_registration_user($op, &$edit, &$account, $category = NULL) {
*
*/
function email_registration_form_alter($form_id, &$form) {
function email_registration_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'user_register':
$form['name']['#type'] = 'hidden';
$form['name']['#value'] = user_password();
$form['mail']['#title'] = t('E-mail');
if (module_exists('profile') && is_array($form['account'])) {
$form['account']['name']['#type'] = 'hidden';
$form['account']['name']['#value'] = user_password();
$form['account']['mail']['#title'] = t('E-mail');
}
else {
$form['name']['#type'] = 'hidden';
$form['name']['#value'] = user_password();
$form['mail']['#title'] = t('E-mail');
}
break;
case 'user_pass':
$form['name']['#title'] = t('E-mail');
$form['name']['#description'] = t('Enter your e-mail address. You\'ll be sent a new password immediately.');
$form['name']['#description'] = t('Enter your e-mail address. You\'ll be sent a new password immediately.');
break;
case 'user_login':
$form['name']['#title'] = t('E-mail');
$form['name']['#description'] = 'Enter your e-mail address.';
$form['name']['#description'] = 'Enter your e-mail address.';
$form['pass']['#description'] = 'Enter the password that accompanies your e-mail.';
$form['#validate'] = array('email_registration_user_login_validate' => array()) + $form['#validate'];
$form['#validate'] = array('email_registration_user_login_validate' => array()) + $form['#validate'];
break;
case 'user_login_block':
$form['name']['#title'] = t('E-mail');
$form['#validate'] = array('email_registration_user_login_validate' => array()) + $form['#validate'];
$form['#validate'] = array('email_registration_user_login_validate' => array()) + $form['#validate'];
break;
}
}
/* function email_registration_settings() {
return system_settings_form($form);
}
*/
/**
* function email_registration_settings() {
* return system_settings_form($form);
* }
*/
......@@ -71,10 +77,10 @@ function email_registration_form_alter($form_id, &$form) {
*
*/
function email_registration_user_login_validate($form_id, $form_values, $form) {
if (isset($form_values['name'])) {
if ($name = db_result(db_query("SELECT name FROM {users} WHERE LOWER(mail) = LOWER('%s')", $form_values['name']))) {
form_set_value($form['name'], $name);
function email_registration_user_login_validate($form, &$form_state) {
if (isset($form_state['values']['name'])) {
if ($name = db_result(db_query("SELECT name FROM {users} WHERE LOWER(mail) = LOWER('%s')", $form_state['values']['name']))) {
form_set_value($form_state['name'], $name, $form_state);
}
}
}
\ No newline at end of file
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