Skip to content

Commit

Permalink
feature(uservalidationbyemail): forwarding to an info page after regi…
Browse files Browse the repository at this point in the history
…stration

Replaced system message by an informative page.
Removed system message when users try to log in, there is already another
message explaining why they can't log in.

Fixes #6247
  • Loading branch information
Sem committed Feb 21, 2014
1 parent 442d9e4 commit 6fbb8c9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
4 changes: 2 additions & 2 deletions mod/uservalidationbyemail/actions/resend_validation.php
Expand Up @@ -26,7 +26,7 @@

// don't resend emails to validated users
$is_validated = elgg_get_user_validation_status($guid);
if ($is_validated !== FALSE || !uservalidationbyemail_request_validation($guid, true)) {
if ($is_validated !== FALSE || !uservalidationbyemail_request_validation($guid)) {
$error = TRUE;
continue;
}
Expand All @@ -48,4 +48,4 @@
system_message($message_txt);
}

forward(REFERRER);
forward(REFERRER);
1 change: 1 addition & 0 deletions mod/uservalidationbyemail/languages/en.php
Expand Up @@ -26,6 +26,7 @@
'email:confirm:success' => "You have confirmed your email address!",
'email:confirm:fail' => "Your email address could not be verified...",

'uservalidationbyemail:emailsent' => "Email sent to <em>%s</em>",
'uservalidationbyemail:registerok' => "To activate your account, please confirm your email address by clicking on the link we just sent you.",
'uservalidationbyemail:login:fail' => "Your account is not validated so the log in attempt failed. Another validation email has been sent.",

Expand Down
14 changes: 8 additions & 6 deletions mod/uservalidationbyemail/lib/functions.php
Expand Up @@ -29,7 +29,11 @@ function uservalidationbyemail_generate_code($user_guid, $email_address) {
* @param bool $admin_requested Was it requested by admin
* @return mixed
*/
function uservalidationbyemail_request_validation($user_guid, $admin_requested = FALSE) {
function uservalidationbyemail_request_validation($user_guid, $admin_requested = 'deprecated') {

if ($admin_requested != 'deprecated') {
elgg_deprecatednotice('Second param $admin_requested no more used in uservalidationbyemail_request_validation function', 1.9);
}

$site = elgg_get_site_entity();

Expand All @@ -41,16 +45,14 @@ function uservalidationbyemail_request_validation($user_guid, $admin_requested =
$code = uservalidationbyemail_generate_code($user_guid, $user->email);
$link = "{$site->url}uservalidationbyemail/confirm?u=$user_guid&c=$code";

// Get email to show in the next page
$_SESSION['emailsent'] = $user->email;

// Send validation email
$subject = elgg_echo('email:validate:subject', array($user->name, $site->name));
$body = elgg_echo('email:validate:body', array($user->name, $site->name, $link, $site->name, $site->url));
$result = notify_user($user->guid, $site->guid, $subject, $body, array(), 'email');

if ($result && !$admin_requested) {
system_message(elgg_echo('uservalidationbyemail:registerok'));
}

return $result;
}

Expand Down Expand Up @@ -99,4 +101,4 @@ function uservalidationbyemail_get_unvalidated_users_sql_where() {
AND md.value_id = $one_id)";

return $wheres;
}
}
30 changes: 29 additions & 1 deletion mod/uservalidationbyemail/start.php
Expand Up @@ -20,6 +20,9 @@ function uservalidationbyemail_init() {
// mark users as unvalidated and disable when they register
elgg_register_plugin_hook_handler('register', 'user', 'uservalidationbyemail_disable_new_user');

// forward to uservalidationbyemail/emailsent page after register
elgg_register_plugin_hook_handler('forward', 'system', 'uservalidationbyemail_after_registration_url');

// canEdit override to allow not logged in code to disable a user
elgg_register_plugin_hook_handler('permissions_check', 'user', 'uservalidationbyemail_allow_new_user_can_edit');

Expand Down Expand Up @@ -102,6 +105,22 @@ function uservalidationbyemail_disable_new_user($hook, $type, $value, $params) {
return $value;
}

/**
* Override the URL to be forwarded after registration
*
* @param string $hook
* @param string $type
* @param bool $value
* @param array $params
* @return string
*/
function uservalidationbyemail_after_registration_url($hook, $type, $value, $params) {
$url = elgg_extract('current_url', $params);
if ($url == elgg_get_site_url() . 'action/register') {
return elgg_get_site_url() . 'uservalidationbyemail/emailsent';
}
}

/**
* Override the canEdit() call for if we're in the context of registering a new user.
*
Expand Down Expand Up @@ -173,7 +192,16 @@ function uservalidationbyemail_check_auth_attempt($credentials) {
*/
function uservalidationbyemail_page_handler($page) {

if (isset($page[0]) && $page[0] == 'confirm') {
if (isset($page[0]) && $page[0] == 'emailsent') {
$email = $_SESSION['emailsent'];
$title = elgg_echo('uservalidationbyemail:emailsent', array($email));
$body = elgg_view_layout('one_column', array(
'title' => $title,
'content' => elgg_echo('uservalidationbyemail:registerok'),
));
echo elgg_view_page(strip_tags($title), $body);
return true;
} elseif (isset($page[0]) && $page[0] == 'confirm') {
$code = sanitise_string(get_input('c', FALSE));
$user_guid = get_input('u', FALSE);

Expand Down

0 comments on commit 6fbb8c9

Please sign in to comment.