diff options
Diffstat (limited to 'mod/uservalidationbyemail/lib/functions.php')
| -rw-r--r-- | mod/uservalidationbyemail/lib/functions.php | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/mod/uservalidationbyemail/lib/functions.php b/mod/uservalidationbyemail/lib/functions.php index ea77c8d61..f3091f94d 100644 --- a/mod/uservalidationbyemail/lib/functions.php +++ b/mod/uservalidationbyemail/lib/functions.php @@ -14,21 +14,24 @@ * @return string */ function uservalidationbyemail_generate_code($user_guid, $email_address) { - global $CONFIG; + + $site_url = elgg_get_site_url(); // Note I bind to site URL, this is important on multisite! - return md5($user_guid . $email_address . $CONFIG->site->url . get_site_secret()); + return md5($user_guid . $email_address . $site_url . get_site_secret()); } /** * Request user validation email. * Send email out to the address and request a confirmation. * - * @param int $user_guid The user's GUID + * @param int $user_guid The user's GUID + * @param bool $admin_requested Was it requested by admin * @return mixed */ -function uservalidationbyemail_request_validation($user_guid) { - global $CONFIG; +function uservalidationbyemail_request_validation($user_guid, $admin_requested = FALSE) { + + $site = elgg_get_site_entity(); $user_guid = (int)$user_guid; $user = get_entity($user_guid); @@ -36,15 +39,15 @@ function uservalidationbyemail_request_validation($user_guid) { if (($user) && ($user instanceof ElggUser)) { // Work out validate link $code = uservalidationbyemail_generate_code($user_guid, $user->email); - $link = "{$CONFIG->site->url}pg/uservalidationbyemail/confirm?u=$user_guid&c=$code"; - $site = $CONFIG->site; + $link = "{$site->url}uservalidationbyemail/confirm?u=$user_guid&c=$code"; + // 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, $CONFIG->site->guid, $subject, $body, NULL, 'email'); + $result = notify_user($user->guid, $site->guid, $subject, $body, NULL, 'email'); - if ($result) { + if ($result && !$admin_requested) { system_message(elgg_echo('uservalidationbyemail:registerok')); } @@ -65,43 +68,41 @@ function uservalidationbyemail_validate_email($user_guid, $code) { $user = get_entity($user_guid); if ($code == uservalidationbyemail_generate_code($user_guid, $user->email)) { - return uservalidationbyemail_set_user_validation_status($user_guid, true, 'email'); + return elgg_set_user_validation_status($user_guid, true, 'email'); } return false; } /** - * Set the validation status for a user. + * Return a where clause to get entities * - * @param int $user_guid The user's GUID - * @param bool $status Validated (true) or false - * @param string $method Optional method to say how a user was validated - * @return bool - */ -function uservalidationbyemail_set_user_validation_status($user_guid, $status, $method = '') { - - $result1 = create_metadata($user_guid, 'validated', $status, '', 0, ACCESS_PUBLIC, false); - $result2 = create_metadata($user_guid, 'validated_method', $method, '', 0, ACCESS_PUBLIC, false); - if ($result1 && $result2) { - return true; - } else { - return false; - } -} - -/** - * Returns the validation status of a user. + * "Unvalidated" means metadata of validated is not set or not truthy. + * We can't use elgg_get_entities_from_metadata() because you can't say + * "where the entity has metadata set OR it's not equal to 1". * - * @param int $user_guid The user's GUID - * @return bool + * @return array */ -function uservalidationbyemail_get_user_validation_status($user_guid) { - $md = get_metadata_byname($user_guid, 'validated'); +function uservalidationbyemail_get_unvalidated_users_sql_where() { + global $CONFIG; - if ($md && $md->value) { - return TRUE; + $validated_id = get_metastring_id('validated'); + if ($validated_id === false) { + $validated_id = add_metastring('validated'); + } + $one_id = get_metastring_id('1'); + if ($one_id === false) { + $one_id = add_metastring('1'); } - return FALSE; -} + // thanks to daveb@freenode for the SQL tips! + $wheres = array(); + $wheres[] = "e.enabled='no'"; + $wheres[] = "NOT EXISTS ( + SELECT 1 FROM {$CONFIG->dbprefix}metadata md + WHERE md.entity_guid = e.guid + AND md.name_id = $validated_id + AND md.value_id = $one_id)"; + + return $wheres; +}
\ No newline at end of file |
