Hi,
I am working in a site that requires both the user to validate the email and the admin to approve the user. So far I hack my way to it, but I wonder if there is a better way to do my task.
My setup:
1. I created an small custom module that will be use as the redirection page after the account is created. Once the user land in there a confirmation message it shown and in the background the user get logout and block. See code below:
/**
* Implementation of the hook_menu()
*/
function custom_menu() {
$items = array();
$items['registration_complete'] = array(
'title' => variable_get('registration_complete_title', 'Registration Complete'),
'page callback' => 'registration_complete_show',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function registration_complete_show() {
/* Kick new user out start */
global $user;
if (in_array('pending', array_values($user->roles))) {
// Block the user
db_query("UPDATE {users} SET status = '0' WHERE uid = %d", $user->uid);
// Destroy the current session:
session_destroy();
// Only variables can be passed by reference workaround.
$null = NULL;
user_module_invoke('logout', $null, $user);
// Load the anonymous user
$user = drupal_anonymous_user();
}
/* Kick new user out end */
$empty = t('Your registration requires approval and email confirmation. Please follow the confirmation steps sent to you in e-mail. Once approved you will be sent an acceptance notice to the e-mail address you entered. When you receive approval then you will be able to login.');
return variable_get('registration_complete_message', $empty);
}
Now I am ok there. My only concern is the fact that in order to include the validate email link I have to hack the code LT code of the function logintoboggan_user_register_submit
$login_url = variable_get('user_register', 1) == 1 ? logintoboggan_eml_validate_url($account) : NULL;
to
$login_url = logintoboggan_eml_validate_url($account);
and worse yet I have to ax the function logintoboggan_validate_email from:
// Only show the validated message if there's a valid pre-auth role.
if ($pre_auth) {
drupal_set_message(t('You have successfully validated your e-mail address.'));
}
if (!$account->status) {
drupal_set_message(t('Your account is currently blocked -- login cancelled.'), 'error');
drupal_goto('');
}
to
// Only show the validated message if there's a valid pre-auth role.
if ($pre_auth) {
//drupal_set_message(t('You have successfully validated your e-mail address.'));
}
if (!$account->status) {
//drupal_set_message(t('Your account is currently blocked -- login cancelled.'), 'error');
drupal_goto('email_validation');
}
Note: drupal_goto('email_validation'); go to a page in the site call email_validation (another custom module in my case) where the user can clearly see the confirmation of his/her email validated. Since I use a custom module for the email validation page I also notify the admin that the user has a valid email address.
Is there a better way to do this?
Thank you.
Comments
Comment #1
stevecowie commentedNot entirely sure I get what the problem is here. I think your problem is that you want to handle cases where a user register on the site and then logs in before having responded to the email confirmation. Can you confirm if that's correct?
Comment #2
stevecowie commentedVersion no longer supported