diff options
-rw-r--r-- | engine/lib/users.php | 44 | ||||
-rw-r--r-- | mod/uservalidationbyemail/actions/delete.php | 5 | ||||
-rw-r--r-- | mod/uservalidationbyemail/actions/resend_validation.php | 5 | ||||
-rw-r--r-- | mod/uservalidationbyemail/actions/validate.php | 6 | ||||
-rw-r--r-- | mod/uservalidationbyemail/lib/functions.php | 37 | ||||
-rw-r--r-- | mod/uservalidationbyemail/start.php | 67 |
6 files changed, 67 insertions, 97 deletions
diff --git a/engine/lib/users.php b/engine/lib/users.php index b22e93ca2..62f2bdcc8 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -1226,11 +1226,13 @@ function generate_invite_code($username) { /** * 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 + * @param int $user_guid The user's GUID + * @param bool $status Validated (true) or unvalidated (false) + * @param string $method Optional method to say how a user was validated * @return bool + * @since 1.8.0 */ -function set_user_validation_status($user_guid, $status, $method = '') { +function elgg_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) { @@ -1241,13 +1243,49 @@ function set_user_validation_status($user_guid, $status, $method = '') { } /** + * Gets the validation status of a user. + * + * @param int $user_guid The user's GUID + * @return bool|null Null means status was not set for this user. + * @since 1.8.0 + */ +function elgg_get_user_validation_status($user_guid) { + $md = get_metadata_byname($user_guid, 'validated'); + if ($md == false) { + return; + } + + if ($md->value) { + return true; + } + + 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 + * @deprecated 1.8 + */ +function set_user_validation_status($user_guid, $status, $method = '') { + elgg_deprecated_notice("set_user_validation_status() is deprecated", 1.8); + return elgg_set_user_validation_status($user_guid, $status, $method); +} + +/** * Trigger an event requesting that a user guid be validated somehow - either by email address or some other way. * * This function invalidates any existing validation value. * * @param int $user_guid User's GUID + * @deprecated 1.8 */ function request_user_validation($user_guid) { + elgg_deprecated_notice("request_user_validation() is deprecated. + Plugins should register for the 'register, user' plugin hook", 1.8); $user = get_entity($user_guid); if (($user) && ($user instanceof ElggUser)) { diff --git a/mod/uservalidationbyemail/actions/delete.php b/mod/uservalidationbyemail/actions/delete.php index 14d40e89c..b076d3048 100644 --- a/mod/uservalidationbyemail/actions/delete.php +++ b/mod/uservalidationbyemail/actions/delete.php @@ -25,9 +25,8 @@ foreach ($user_guids as $guid) { } // don't delete validated users - $is_validated = uservalidationbyemail_get_user_validation_status($guid); - - if ($is_validated || !$user->delete()) { + $is_validated = elgg_get_user_validation_status($guid); + if ($is_validated !== FALSE || !$user->delete()) { $error = TRUE; continue; } diff --git a/mod/uservalidationbyemail/actions/resend_validation.php b/mod/uservalidationbyemail/actions/resend_validation.php index 70c2244b9..59a69b0f6 100644 --- a/mod/uservalidationbyemail/actions/resend_validation.php +++ b/mod/uservalidationbyemail/actions/resend_validation.php @@ -25,9 +25,8 @@ foreach ($user_guids as $guid) { } // don't resend emails to validated users - $is_validated = uservalidationbyemail_get_user_validation_status($guid); - - if ($is_validated || !uservalidationbyemail_request_validation($guid)) { + $is_validated = elgg_get_user_validation_status($guid); + if ($is_validated !== FALSE || !uservalidationbyemail_request_validation($guid)) { $error = TRUE; continue; } diff --git a/mod/uservalidationbyemail/actions/validate.php b/mod/uservalidationbyemail/actions/validate.php index cc4554722..d6be9cfe5 100644 --- a/mod/uservalidationbyemail/actions/validate.php +++ b/mod/uservalidationbyemail/actions/validate.php @@ -25,10 +25,10 @@ foreach ($user_guids as $guid) { } // only validate if not validated - $is_validated = uservalidationbyemail_get_user_validation_status($guid); - $validate_success = uservalidationbyemail_set_user_validation_status($guid, TRUE); + $is_validated = elgg_get_user_validation_status($guid); + $validate_success = elgg_set_user_validation_status($guid, TRUE, 'manual'); - if ($is_validated || !($validate_success && $user->enable())) { + if ($is_validated !== FALSE || !($validate_success && $user->enable())) { $error = TRUE; continue; } diff --git a/mod/uservalidationbyemail/lib/functions.php b/mod/uservalidationbyemail/lib/functions.php index ea77c8d61..aadabc927 100644 --- a/mod/uservalidationbyemail/lib/functions.php +++ b/mod/uservalidationbyemail/lib/functions.php @@ -65,43 +65,8 @@ 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. - * - * @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. - * - * @param int $user_guid The user's GUID - * @return bool - */ -function uservalidationbyemail_get_user_validation_status($user_guid) { - $md = get_metadata_byname($user_guid, 'validated'); - - if ($md && $md->value) { - return TRUE; - } - - return FALSE; -} diff --git a/mod/uservalidationbyemail/start.php b/mod/uservalidationbyemail/start.php index 8f5888679..36dccf8bf 100644 --- a/mod/uservalidationbyemail/start.php +++ b/mod/uservalidationbyemail/start.php @@ -7,6 +7,8 @@ * @subpackage UserValidationByEmail */ +elgg_register_event_handler('init', 'system', 'uservalidationbyemail_init'); + function uservalidationbyemail_init() { global $CONFIG; @@ -78,7 +80,7 @@ function uservalidationbyemail_disable_new_user($hook, $type, $value, $params) { $user->disable('uservalidationbyemail_new_user', FALSE); // set user as unvalidated and send out validation email - uservalidationbyemail_set_user_validation_status($user->guid, FALSE); + elgg_set_user_validation_status($user->guid, FALSE); uservalidationbyemail_request_validation($user->guid); elgg_pop_context(); @@ -90,6 +92,11 @@ function uservalidationbyemail_disable_new_user($hook, $type, $value, $params) { /** * Override the canEdit() call for if we're in the context of registering a new user. * + * @param string $hook + * @param string $type + * @param bool $value + * @param array $params + * @return bool|null */ function uservalidationbyemail_allow_new_user_can_edit($hook, $type, $value, $params) { // $params['user'] is the user to check permissions for. @@ -97,7 +104,7 @@ function uservalidationbyemail_allow_new_user_can_edit($hook, $type, $value, $pa $user = elgg_get_array_value('entity', $params); if (!($user instanceof ElggUser)) { - return NULL; + return; } $context = elgg_get_context(); @@ -105,7 +112,7 @@ function uservalidationbyemail_allow_new_user_can_edit($hook, $type, $value, $pa return TRUE; } - return NULL; + return; } /** @@ -180,16 +187,14 @@ function uservalidationbyemail_page_handler($page) { /** * Make sure any admin users are automatically validated * - * @param unknown_type $event - * @param unknown_type $type - * @param unknown_type $object + * @param string $event + * @param string $type + * @param ElggUser $user */ function uservalidationbyemail_validate_new_admin_user($event, $type, $user) { if ($user instanceof ElggUser && !$user->validated) { - uservalidationbyemail_set_user_validation_status($user->guid, TRUE, 'admin_user'); + elgg_set_user_validation_status($user->guid, TRUE, 'admin_user'); } - - return TRUE; } /** @@ -203,9 +208,10 @@ function uservalidationbyemail_public_pages($hook, $type, $return_value, $params /** * Prevent a manual code login with login(). * - * @param unknown_type $event - * @param unknown_type $type - * @param unknown_type $user + * @param string $event + * @param string $type + * @param ElggUser $user + * @return bool */ function uservalidationbyemail_check_manual_login($event, $type, $user) { $access_status = access_get_show_hidden_status(); @@ -218,40 +224,3 @@ function uservalidationbyemail_check_manual_login($event, $type, $user) { return $return; } - -/** - * Deny requests to change password if the account isn't validated. - * - * @todo This is needed because changing the password requires the entity to be enabled. - * - * @param unknown_type $hook - * @param unknown_type $type - * @param unknown_type $value - * @param unknown_type $params - */ -function uservalidationbyemail_check_request_password($hook, $type, $value, $params) { - $username = get_input('username'); - - // see if we need to resolve an email address to a username - if (strpos($username, '@') !== FALSE && ($users = get_user_by_email($username))) { - $username = $users[0]->username; - } - - // See the users exists and isn't validated - $access_status = access_get_show_hidden_status(); - access_show_hidden_entities(TRUE); - - $user = get_user_by_username($username); - - // resend validation instead of resetting password - if ($user && !$user->validated) { - uservalidationbyemail_request_validation($user->guid); - $value = FALSE; - } - - access_show_hidden_entities($access_status); - - return $value; -} - -elgg_register_event_handler('init', 'system', 'uservalidationbyemail_init');
\ No newline at end of file |