aboutsummaryrefslogtreecommitdiff
path: root/mod/uservalidationbyemail/start.php
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-10-03 16:11:13 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-10-03 16:11:13 +0000
commit5366cd6a4ca12203147407be01a80817fa37ea3a (patch)
tree690afeb8cfd3d4ca1cb41700b40fe2454b29b10d /mod/uservalidationbyemail/start.php
parent8dd1515697fcef1968d062c18222eb21d520f5e2 (diff)
downloadelgg-5366cd6a4ca12203147407be01a80817fa37ea3a.tar.gz
elgg-5366cd6a4ca12203147407be01a80817fa37ea3a.tar.bz2
Fixes #311, closes #345: Validation now called via event 'user', 'validate'. Email validation now a plugin.
git-svn-id: https://code.elgg.org/elgg/trunk@2177 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/uservalidationbyemail/start.php')
-rw-r--r--mod/uservalidationbyemail/start.php75
1 files changed, 74 insertions, 1 deletions
diff --git a/mod/uservalidationbyemail/start.php b/mod/uservalidationbyemail/start.php
index f02b2cf68..2479d3b98 100644
--- a/mod/uservalidationbyemail/start.php
+++ b/mod/uservalidationbyemail/start.php
@@ -12,12 +12,85 @@
function uservalidationbyemail_init()
{
+ global $CONFIG;
+
// Register actions
+ register_action("email/confirm",true, $CONFIG->pluginspath . "uservalidationbyemail/actions/email/confirm.php");
// Register hook listening to new users.
+ register_elgg_event_handler('user', 'validate', 'uservalidationbyemail_email_validation');
}
- // create - if not admin & if not admin logged in then request email validation
+ /**
+ * Request email validation.
+ */
+ function uservalidationbyemail_email_validation($event, $object_type, $object)
+ {
+ error_log('EMAIL : '.$event." $object_type");
+ if (($object) && ($object instanceof ElggUser))
+ {
+ uservalidationbyemail_request_validation($object->guid);
+ }
+ }
+
+ /**
+ * Generate an email activation code.
+ *
+ * @param int $user_guid The guid of the user
+ * @param string $email_address Email address
+ * @return string
+ */
+ function uservalidationbyemail_generate_code($user_guid, $email_address)
+ {
+ global $CONFIG;
+
+ return md5($user_guid . $email_address . $CONFIG->site->url); // Note I bind to site URL, this is important on multisite!
+ }
+
+ /**
+ * Request user validation email.
+ * Send email out to the address and request a confirmation.
+ *
+ * @param int $user_guid The user
+ * @return mixed
+ */
+ function uservalidationbyemail_request_validation($user_guid)
+ {
+ global $CONFIG;
+
+ $user_guid = (int)$user_guid;
+ $user = get_entity($user_guid);
+
+ if (($user) && ($user instanceof ElggUser))
+ {
+ // Work out validate link
+ $link = $CONFIG->site->url . "action/email/confirm?u=$user_guid&c=" . uservalidationbyemail_generate_code($user_guid, $user->email);
+
+ // Send validation email
+ return notify_user($user->guid, $CONFIG->site->guid, sprintf(elgg_echo('email:validate:subject'), $user->username), sprintf(elgg_echo('email:validate:body'), $user->name, $link), NULL, 'email');
+
+ }
+
+ return false;
+ }
+
+ /**
+ * Validate a user
+ *
+ * @param unknown_type $user_guid
+ * @param unknown_type $code
+ * @return unknown
+ */
+ function uservalidationbyemail_validate_email($user_guid, $code)
+ {
+ $user = get_entity($user_guid);
+
+ $valid = ($code == uservalidationbyemail_generate_code($user_guid, $user->email));
+ if ($valid)
+ set_user_validation_status($user_guid, true, 'email');
+
+ return $valid;
+ }
// Initialise
register_elgg_event_handler('init','system','uservalidationbyemail_init');