aboutsummaryrefslogtreecommitdiff
path: root/mod/uservalidationbyemail/lib/functions.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-20 04:42:49 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-20 04:42:49 +0000
commitcc873980abb9d1d9206f333bd465ecd6a55b609b (patch)
tree6233f4b76b9c763d60dddb70a6ecc7558d9183e1 /mod/uservalidationbyemail/lib/functions.php
parent7fbd66bc3aeda393a0117883b70a3212dae57e51 (diff)
downloadelgg-cc873980abb9d1d9206f333bd465ecd6a55b609b.tar.gz
elgg-cc873980abb9d1d9206f333bd465ecd6a55b609b.tar.bz2
Fixes #2658. Merged uservalidationbyemail changes from 1.7 to 1.8. This plugin needs cleanup.
git-svn-id: http://code.elgg.org/elgg/trunk@8357 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/uservalidationbyemail/lib/functions.php')
-rw-r--r--mod/uservalidationbyemail/lib/functions.php40
1 files changed, 34 insertions, 6 deletions
diff --git a/mod/uservalidationbyemail/lib/functions.php b/mod/uservalidationbyemail/lib/functions.php
index b28e4a127..8a97c40b5 100644
--- a/mod/uservalidationbyemail/lib/functions.php
+++ b/mod/uservalidationbyemail/lib/functions.php
@@ -25,12 +25,13 @@ function uservalidationbyemail_generate_code($user_guid, $email_address) {
* 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) {
+function uservalidationbyemail_request_validation($user_guid, $admin_requested = FALSE) {
- $site_url = elgg_get_site_url();
+ $site = elgg_get_site_entity();
$user_guid = (int)$user_guid;
$user = get_entity($user_guid);
@@ -38,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 = "{$site_url}pg/uservalidationbyemail/confirm?u=$user_guid&c=$code";
- $site = elgg_get_site_entity();
+ $link = "{$site->url}pg/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, $site->guid, $subject, $body, NULL, 'email');
- if ($result) {
+ if ($result && !$admin_requested) {
system_message(elgg_echo('uservalidationbyemail:registerok'));
}
@@ -72,3 +73,30 @@ function uservalidationbyemail_validate_email($user_guid, $code) {
return false;
}
+
+/**
+ * Return a where clause to get entities
+ *
+ * "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".
+ *
+ * @return array
+ */
+function uservalidationbyemail_get_unvalidated_users_sql_where() {
+ global $CONFIG;
+
+ $validated_id = get_metastring_id('validated');
+ $one_id = get_metastring_id(1);
+
+ // 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