| 1 |
<?php |
<?php |
| 2 |
// $Id: logintoboggan.module,v 1.168 2009/10/20 15:10:03 thehunmonkgroup Exp $ |
// $Id: logintoboggan.module,v 1.169 2009/10/20 22:10:04 thehunmonkgroup Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 185 |
'#weight' => -10, |
'#weight' => -10, |
| 186 |
); |
); |
| 187 |
$form['revalidate']['revalidate_link'] = array( |
$form['revalidate']['revalidate_link'] = array( |
| 188 |
'#value' => l(t('re-send validation e-mail'), 'toboggan/revalidate/'. $account->uid), |
'#markup' => l(t('re-send validation e-mail'), 'toboggan/revalidate/'. $account->uid), |
| 189 |
); |
); |
| 190 |
} |
} |
| 191 |
} |
} |
| 197 |
if (user_access('administer users') && isset($form['account']['roles']) && $id != DRUPAL_AUTHENTICATED_RID) { |
if (user_access('administer users') && isset($form['account']['roles']) && $id != DRUPAL_AUTHENTICATED_RID) { |
| 198 |
// User is still in the pre-auth role, so let the admin know. |
// User is still in the pre-auth role, so let the admin know. |
| 199 |
if ($in_pre_auth_role) { |
if ($in_pre_auth_role) { |
| 200 |
|
// This form element is necessary as a placeholder for the user's |
| 201 |
|
// pre-auth setting on form load. It's used to compare against the |
| 202 |
|
// submitted form values to see if the pre-auth role has been unchecked. |
| 203 |
|
$form['logintoboggan_pre_auth_check'] = array( |
| 204 |
|
'#type' => 'hidden', |
| 205 |
|
'#value' => '1', |
| 206 |
|
); |
| 207 |
if ((variable_get('user_register', 1) == 2)) { |
if ((variable_get('user_register', 1) == 2)) { |
| 208 |
$form['account']['status']['#description'] = t('If this user was created using the "Immediate Login" feature of LoginToboggan, and they are also awaiting adminstrator approval on their account, you must remove them from the site\'s pre-authorized role in the "Roles" section below, or they will not receive authenticated user permissions!'); |
$form['account']['status']['#description'] = t('If this user was created using the "Immediate Login" feature of LoginToboggan, and they are also awaiting adminstrator approval on their account, you must remove them from the site\'s pre-authorized role in the "Roles" section below, or they will not receive authenticated user permissions!'); |
| 209 |
} |
} |
| 249 |
|
|
| 250 |
//Display a confirm e-mail address box if option is enabled. |
//Display a confirm e-mail address box if option is enabled. |
| 251 |
if ($mail) { |
if ($mail) { |
|
// Make sure user help is at the top of the form. |
|
|
$form['user_registration_help']['#weight'] = -100; |
|
| 252 |
|
|
| 253 |
$form['conf_mail'] = array('#type' => 'textfield', |
$form['conf_mail'] = array('#type' => 'textfield', |
| 254 |
'#title' => t('Confirm e-mail address'), |
'#title' => t('Confirm e-mail address'), |
| 275 |
if ($pass) { |
if ($pass) { |
| 276 |
$min_pass = variable_get('logintoboggan_minimum_password_length', 0); |
$min_pass = variable_get('logintoboggan_minimum_password_length', 0); |
| 277 |
$length = $min_pass ? t('between !min and', array('!min' => $min_pass)) : t('no more than'); |
$length = $min_pass ? t('between !min and', array('!min' => $min_pass)) : t('no more than'); |
| 278 |
$form['pass']['#description'] = t('Please choose a password for your account; it must be !length 30 characters.', array('!length' => $length)); |
$pass_description = t('Please choose a password for your account; it must be !length 30 characters.', array('!length' => $length)); |
| 279 |
|
if (isset($form['account'])) { |
| 280 |
|
$form['account']['pass']['#description'] = $pass_description; |
| 281 |
|
} |
| 282 |
|
else { |
| 283 |
|
$form['pass']['#description'] = $pass_description; |
| 284 |
|
} |
| 285 |
} |
} |
| 286 |
} |
} |
| 287 |
} |
} |
| 550 |
$message = t('A validation e-mail has been sent to your e-mail address. In order to gain full access to the site, you will need to follow the instructions in that message.'); |
$message = t('A validation e-mail has been sent to your e-mail address. In order to gain full access to the site, you will need to follow the instructions in that message.'); |
| 551 |
} |
} |
| 552 |
else { |
else { |
| 553 |
$message = ''; |
$message = t('Further instructions have been sent to your e-mail address.'); |
| 554 |
} |
} |
| 555 |
} else { |
} else { |
| 556 |
$message = t('Your password and further instructions have been sent to your e-mail address.'); |
$message = t('Your password and further instructions have been sent to your e-mail address.'); |
| 594 |
*/ |
*/ |
| 595 |
function logintoboggan_user_login_validate($form, &$form_state) { |
function logintoboggan_user_login_validate($form, &$form_state) { |
| 596 |
if (isset($form_state['values']['name']) && $form_state['values']['name']) { |
if (isset($form_state['values']['name']) && $form_state['values']['name']) { |
| 597 |
if ($name = db_query("SELECT name FROM {users} WHERE LOWER(mail) = LOWER(':name')", array( |
if ($name = db_query("SELECT name FROM {users} WHERE LOWER(mail) = LOWER(:name)", array( |
| 598 |
':name' => $form_state['values']['name'], |
':name' => $form_state['values']['name'], |
| 599 |
))->fetchField()) { |
))->fetchField()) { |
| 600 |
form_set_value($form['name'], $name, $form_state); |
form_set_value($form['name'], $name, $form_state); |
| 638 |
if (variable_get('logintoboggan_login_with_email', 0)) { |
if (variable_get('logintoboggan_login_with_email', 0)) { |
| 639 |
$uid = isset($account->uid) ? $account->uid : 0; |
$uid = isset($account->uid) ? $account->uid : 0; |
| 640 |
// Check that no user is using this name for their email address. |
// Check that no user is using this name for their email address. |
| 641 |
if (isset($edit['name']) && db_query("SELECT uid FROM {users} WHERE LOWER(mail) = LOWER(':mail') AND uid <> :uid", array( |
if (isset($edit['name']) && db_query("SELECT uid FROM {users} WHERE LOWER(mail) = LOWER(:mail) AND uid <> :uid", array( |
| 642 |
':mail' => $edit['name'], |
':mail' => $edit['name'], |
| 643 |
':uid' => $uid, |
':uid' => $uid, |
| 644 |
))->fetchField()) { |
))->fetchField()) { |
| 645 |
form_set_error('name', t('This name has already been taken by another user.')); |
form_set_error('name', t('This name has already been taken by another user.')); |
| 646 |
} |
} |
| 647 |
// Check that no user is using this email address for their name. |
// Check that no user is using this email address for their name. |
| 648 |
if (isset($edit['mail']) && db_query("SELECT uid FROM {users} WHERE LOWER(name) = LOWER(':name') AND uid <> :uid", array( |
if (isset($edit['mail']) && db_query("SELECT uid FROM {users} WHERE LOWER(name) = LOWER(:name) AND uid <> :uid", array( |
| 649 |
':name' => $edit['mail'], |
':name' => $edit['mail'], |
| 650 |
':uid' => $uid, |
':uid' => $uid, |
| 651 |
))->fetchField()) { |
))->fetchField()) { |
| 1094 |
// - the hashed password is correct. |
// - the hashed password is correct. |
| 1095 |
if (((variable_get('user_email_verification', TRUE) && empty($account->login)) || array_key_exists(logintoboggan_validating_id(), $account->roles)) && $hashed_pass == logintoboggan_eml_rehash($account->pass, $timestamp, $account->mail)) { |
if (((variable_get('user_email_verification', TRUE) && empty($account->login)) || array_key_exists(logintoboggan_validating_id(), $account->roles)) && $hashed_pass == logintoboggan_eml_rehash($account->pass, $timestamp, $account->mail)) { |
| 1096 |
watchdog('user', 'E-mail validation URL used for %name with timestamp @timestamp.', array('%name' => $account->name, '@timestamp' => $timestamp)); |
watchdog('user', 'E-mail validation URL used for %name with timestamp @timestamp.', array('%name' => $account->name, '@timestamp' => $timestamp)); |
|
// Update the user table noting user has logged in. |
|
|
// And this also makes this hashed password a one-time-only login. |
|
|
db_update('users') |
|
|
->fields(array('login' => REQUEST_TIME)) |
|
|
->condition('uid', $account->uid) |
|
|
->execute(); |
|
| 1097 |
|
|
| 1098 |
// Test here for a valid pre-auth -- if the pre-auth is set to the auth user, we |
// Test here for a valid pre-auth -- if the pre-auth is set to the auth user, we |
| 1099 |
// handle things a bit differently. |
// handle things a bit differently. |
| 1120 |
else { |
else { |
| 1121 |
$edit = array(); |
$edit = array(); |
| 1122 |
$redirect = logintoboggan_process_login($account, $edit, $redirect); |
$redirect = logintoboggan_process_login($account, $edit, $redirect); |
| 1123 |
drupal_goto($redirect['path'], array('query' => $redirect['query'], 'fragment' => $redirect['fragment'])); |
call_user_func_array('drupal_goto', $redirect); |
| 1124 |
} |
} |
| 1125 |
break; |
break; |
| 1126 |
// Admin validation. |
// Admin validation. |
| 1127 |
case 'admin': |
case 'admin': |
| 1128 |
|
// TODO: is this still necessary? |
| 1129 |
// user has new permissions, so we clear their menu cache |
// user has new permissions, so we clear their menu cache |
| 1130 |
cache_clear_all($account->uid .':', 'cache_menu', TRUE); |
cache_clear_all($account->uid .':', 'cache_menu', TRUE); |
| 1131 |
|
|
| 1139 |
break; |
break; |
| 1140 |
// Catch all. |
// Catch all. |
| 1141 |
default: |
default: |
| 1142 |
|
// TODO: is this still necessary? |
| 1143 |
// user has new permissions, so we clear their menu cache |
// user has new permissions, so we clear their menu cache |
| 1144 |
cache_clear_all($account->uid .':', 'cache_menu', TRUE); |
cache_clear_all($account->uid .':', 'cache_menu', TRUE); |
| 1145 |
|
|
| 1222 |
return array( |
return array( |
| 1223 |
'user/'. $user->uid, |
'user/'. $user->uid, |
| 1224 |
array( |
array( |
| 1225 |
'query' => NULL, |
'query' => array(), |
| 1226 |
'fragment' => NULL, |
'fragment' => '', |
| 1227 |
), |
), |
| 1228 |
); |
); |
| 1229 |
} |
} |
| 1260 |
* Implement hook_user_update(). |
* Implement hook_user_update(). |
| 1261 |
*/ |
*/ |
| 1262 |
function logintoboggan_user_update(&$edit, $account, $category) { |
function logintoboggan_user_update(&$edit, $account, $category) { |
| 1263 |
// Only perform this check if: |
// Only perform this check if an admin is editing the account. |
| 1264 |
// 1. An admin is editing the account. |
if (user_access('administer users')&& isset($edit['roles'])) { |
| 1265 |
// 2. Admin approval is required for new user accounts. |
// Check to see if roles present, and the pre-auth role was present when |
| 1266 |
if (user_access('administer users') && variable_get('user_register', 1) == 2) { |
// the form was initially displayed. |
| 1267 |
// Test here for a valid pre-auth -- if the pre-auth is set to the auth |
if (isset($edit['logintoboggan_pre_auth_check'])) { |
| 1268 |
// user, then no further checking is necessary. |
// If the pre-auth is set to the auth user, then no further checking is |
| 1269 |
$validating_id = logintoboggan_validating_id(); |
// necessary. |
| 1270 |
$pre_auth = !variable_get('user_email_verification', TRUE) && $validating_id != DRUPAL_AUTHENTICATED_RID; |
$validating_id = logintoboggan_validating_id(); |
| 1271 |
if ($pre_auth) { |
$pre_auth = !variable_get('user_email_verification', TRUE) && $validating_id != DRUPAL_AUTHENTICATED_RID; |
| 1272 |
|
if ($pre_auth) { |
| 1273 |
// Check to see if an admin has manually removed the pre-auth role from |
// Check to see if an admin has manually removed the pre-auth role from |
| 1274 |
// the user. If so, send the account activation email. |
// the user. If so, send the account activation email. |
| 1275 |
// The logic here is a bit funky, but necessary because we have no way |
if (!isset($edit['roles'][$validating_id]) || !$edit['roles'][$validating_id]) { |
| 1276 |
// of knowing if a missing $edit['roles'][$validating_id] is because |
// Mail the user, letting them know their account now has auth user perms. |
| 1277 |
// the pre-auth role was disabled on this page save or a previous save. |
_user_mail_notify('status_activated', $account); |
| 1278 |
// So, we calculate a removal of the pre-auth role manually as follows: |
} |
|
// 1. The pre-auth role exists in the user's current roles. |
|
|
// 2. There's an available $edit['roles'] array to examine. |
|
|
// 3. The pre-auth role is not in the array. |
|
|
if (array_key_exists($validating_id, $account->roles) && isset($edit['roles']) && (!isset($edit['roles'][$validating_id]) || !$edit['roles'][$validating_id])) { |
|
|
// Mail the user, letting them know their account now has auth user perms. |
|
|
_user_mail_notify('status_activated', $account); |
|
| 1279 |
} |
} |
| 1280 |
|
unset($edit['logintoboggan_pre_auth_check']); |
| 1281 |
} |
} |
| 1282 |
} |
} |
| 1283 |
} |
} |
| 1286 |
* Re-sends validation e-mail to user specified by $uid. |
* Re-sends validation e-mail to user specified by $uid. |
| 1287 |
*/ |
*/ |
| 1288 |
function logintoboggan_resend_validation($uid) { |
function logintoboggan_resend_validation($uid) { |
|
global $language; |
|
| 1289 |
|
|
| 1290 |
$account = user_load($uid); |
$account = user_load($uid); |
| 1291 |
$account->password = t('If required, you may reset your password from: !url', array('!url' => url('user/password', array('absolute' => TRUE)))); |
$account->password = t('If required, you may reset your password from: !url', array('!url' => url('user/password', array('absolute' => TRUE)))); |
| 1292 |
|
|
| 1293 |
$params['account'] = $account; |
_user_mail_notify('register_no_approval_required', $account); |
|
$params['login_url'] = logintoboggan_eml_validate_url($account); |
|
|
|
|
|
// Prepare and send e-mail. |
|
|
drupal_mail('logintoboggan', 'logintoboggan_resend_validation', $account->mail, $language, $params); |
|
| 1294 |
|
|
| 1295 |
// Notify admin or user that e-mail was sent and return to user edit form. |
// Notify admin or user that e-mail was sent and return to user edit form. |
| 1296 |
if (user_access('administer users')) { |
if (user_access('administer users')) { |
| 1357 |
* Implementation of hook_mail_alter(). |
* Implementation of hook_mail_alter(). |
| 1358 |
*/ |
*/ |
| 1359 |
function logintoboggan_mail_alter(&$message) { |
function logintoboggan_mail_alter(&$message) { |
| 1360 |
if ($message['id'] == 'register_pending_approval_admin') { |
if ($message['id'] == 'user_register_pending_approval_admin') { |
| 1361 |
$reg_pass_set = !variable_get('user_email_verification', TRUE); |
$reg_pass_set = !variable_get('user_email_verification', TRUE); |
| 1362 |
if ($reg_pass_set) { |
if ($reg_pass_set) { |
| 1363 |
|
$account = $message['params']['account']; |
| 1364 |
|
$url_options = array('absolute' => TRUE); |
| 1365 |
$language = $message['language']; |
$language = $message['language']; |
| 1366 |
$langcode = isset($language) ? $language->language : NULL; |
$langcode = isset($language) ? $language->language : NULL; |
| 1367 |
$message['body'][] = t("\n\nThe user has automatically received the permissions of the LoginToboggan validating role. To give the user full site permissions, click the link below:\n\n[logintoboggan-validation:url]/admin\n\nAlternatively, you may visit their user account listed above and remove them from the validating role.", array(), array('langcode' => $langcode)); |
$message['body'][] = t("\n\nThe user has automatically received the permissions of the LoginToboggan validating role. To give the user full site permissions, click the link below:\n\n!validation_url/admin\n\nAlternatively, you may visit their user account listed above and remove them from the validating role.", array('!validation_url' => logintoboggan_eml_validate_url($account, $url_options)), array('langcode' => $langcode)); |
| 1368 |
} |
} |
| 1369 |
} |
} |
| 1370 |
} |
} |