aboutsummaryrefslogtreecommitdiff
path: root/mod/uservalidationbyemail/lib
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-09-30 19:56:49 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-09-30 19:56:49 +0000
commitfad92747bec989fd6728eb7349c9ede4674764ff (patch)
tree6f1c6ca613dff0af2a769c6b13aa97d00cb432a9 /mod/uservalidationbyemail/lib
parent9af90ffc9a20033ca9fdd9182122c01600a0867b (diff)
downloadelgg-fad92747bec989fd6728eb7349c9ede4674764ff.tar.gz
elgg-fad92747bec989fd6728eb7349c9ede4674764ff.tar.bz2
Fixes #617, #2271 User validation removed from core to UserValidationByEmail plugin. Without a validation plugin, users can login immediately.
Fixes #2243 Removed "You have validated your email" email. Users are logged in immediately after registration or validating email. Refs #2409 Added register, user plugin hook that is called only on self registration. Can be used to halt registration. git-svn-id: http://code.elgg.org/elgg/trunk@6983 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/uservalidationbyemail/lib')
-rw-r--r--mod/uservalidationbyemail/lib/functions.php107
1 files changed, 107 insertions, 0 deletions
diff --git a/mod/uservalidationbyemail/lib/functions.php b/mod/uservalidationbyemail/lib/functions.php
new file mode 100644
index 000000000..ed66b40d4
--- /dev/null
+++ b/mod/uservalidationbyemail/lib/functions.php
@@ -0,0 +1,107 @@
+<?php
+/**
+ * Helper functions
+ *
+ * @package Elgg.Core.Plugin
+ * @subpackage UserValidationByEmail
+ */
+
+/**
+ * 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;
+
+ // Note I bind to site URL, this is important on multisite!
+ return md5($user_guid . $email_address . $CONFIG->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
+ * @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
+ $code = uservalidationbyemail_generate_code($user_guid, $user->email);
+ $link = "{$CONFIG->site->url}pg/uservalidationbyemail/confirm?u=$user_guid&c=$code";
+ $site = $CONFIG->site;
+
+ // Send validation email
+ $subject = sprintf(elgg_echo('email:validate:subject'), $user->name, $site->name);
+ $body = sprintf(elgg_echo('email:validate:body'), $user->name, $site->name, $link, $site->name, $site->url);
+ $result = notify_user($user->guid, $CONFIG->site->guid, $subject, $body, NULL, 'email');
+
+ if ($result) {
+ system_message(elgg_echo('uservalidationbyemail:registerok'));
+ }
+
+ return $result;
+ }
+
+ 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);
+
+ if ($code == uservalidationbyemail_generate_code($user_guid, $user->email)) {
+ return uservalidationbyemail_set_user_validation_status($user_guid, true, 'email');
+ }
+
+ return false;
+}
+
+/**
+ * Set the validation status for a user.
+ *
+ * @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 = '') {
+ if (!$status) {
+ $method = '';
+ }
+
+ if ($status) {
+ if (
+ (create_metadata($user_guid, 'validated', $status,'', 0, ACCESS_PUBLIC)) &&
+ (create_metadata($user_guid, 'validated_method', $method,'', 0, ACCESS_PUBLIC))
+ ) {
+ return TRUE;
+ }
+ } else {
+ $validated = get_metadata_byname($user_guid, 'validated');
+ $validated_method = get_metadata_byname($user_guid, 'validated_method');
+
+ if (
+ ($validated) &&
+ ($validated_method) &&
+ (delete_metadata($validated->id)) &&
+ (delete_metadata($validated_method->id))
+ )
+ return TRUE;
+ }
+
+ return FALSE;
+} \ No newline at end of file