diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-10-01 21:01:39 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-10-01 21:01:39 +0000 |
commit | b04f30ecf2347104131b8dccf7bb349b5ec72762 (patch) | |
tree | e01ce61019547a4e8ccfcd66ea6cbf9247b15639 /mod | |
parent | b38d8fc9291ae3c9c6d64b2d950fb0b309699f22 (diff) | |
download | elgg-b04f30ecf2347104131b8dccf7bb349b5ec72762.tar.gz elgg-b04f30ecf2347104131b8dccf7bb349b5ec72762.tar.bz2 |
Added admin page to validate, resend validation requests, or delete unvalidated users.
git-svn-id: http://code.elgg.org/elgg/trunk@6997 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod')
-rw-r--r-- | mod/uservalidationbyemail/actions/bulk_action.php | 18 | ||||
-rw-r--r-- | mod/uservalidationbyemail/actions/delete.php | 52 | ||||
-rw-r--r-- | mod/uservalidationbyemail/actions/resend_validation.php | 52 | ||||
-rw-r--r-- | mod/uservalidationbyemail/actions/validate.php | 53 | ||||
-rw-r--r-- | mod/uservalidationbyemail/languages/en.php | 29 | ||||
-rw-r--r-- | mod/uservalidationbyemail/lib/functions.php | 41 | ||||
-rw-r--r-- | mod/uservalidationbyemail/start.php | 10 | ||||
-rw-r--r-- | mod/uservalidationbyemail/views/default/admin/users/unvalidated.php | 35 | ||||
-rw-r--r-- | mod/uservalidationbyemail/views/default/uservalidationbyemail/unvalidated_user.php | 53 |
9 files changed, 342 insertions, 1 deletions
diff --git a/mod/uservalidationbyemail/actions/bulk_action.php b/mod/uservalidationbyemail/actions/bulk_action.php new file mode 100644 index 000000000..fbbcc1c93 --- /dev/null +++ b/mod/uservalidationbyemail/actions/bulk_action.php @@ -0,0 +1,18 @@ +<?php +/** + * Dispatches a bulk action to real action. + * + * @package Elgg.Core.Plugin + * @subpackage UserValidationByEmail + */ + +$action_type = get_input('action_type'); +$valid_actions = array('delete', 'resend_validation', 'validate'); + +if (!in_array($action_type, $valid_actions)) { + forward(REFERRER); +} + +$action_name = "uservalidationbyemail/$action_type"; + +action($action_name);
\ No newline at end of file diff --git a/mod/uservalidationbyemail/actions/delete.php b/mod/uservalidationbyemail/actions/delete.php new file mode 100644 index 000000000..14d40e89c --- /dev/null +++ b/mod/uservalidationbyemail/actions/delete.php @@ -0,0 +1,52 @@ +<?php +/** + * Delete a user or users by guid + * + * @package Elgg.Core.Plugin + * @subpackage UserValidationByEmail + */ + +$user_guids = get_input('user_guids'); +$error = FALSE; + +if (!$user_guids) { + register_error(elgg_echo('uservalidationbyemail:errors:unknown_users')); + forward(REFERRER); +} + +$access = access_get_show_hidden_status(); +access_show_hidden_entities(TRUE); + +foreach ($user_guids as $guid) { + $user = get_entity($guid); + if (!$user instanceof ElggUser) { + $error = TRUE; + continue; + } + + // don't delete validated users + $is_validated = uservalidationbyemail_get_user_validation_status($guid); + + if ($is_validated || !$user->delete()) { + $error = TRUE; + continue; + } +} + +access_show_hidden_entities($access); + +if (count($user_guids) == 1) { + $message_txt = elgg_echo('uservalidationbyemail:messages:deleted_user'); + $error_txt = elgg_echo('uservalidationbyemail:errors:could_not_delete_user'); +} else { + $message_txt = elgg_echo('uservalidationbyemail:messages:deleted_users'); + $error_txt = elgg_echo('uservalidationbyemail:errors:could_not_delete_users'); +} + +if ($error) { + register_error($error_txt); +} else { + system_message($message_txt); +} + +forward(REFERRER);
\ No newline at end of file diff --git a/mod/uservalidationbyemail/actions/resend_validation.php b/mod/uservalidationbyemail/actions/resend_validation.php new file mode 100644 index 000000000..70c2244b9 --- /dev/null +++ b/mod/uservalidationbyemail/actions/resend_validation.php @@ -0,0 +1,52 @@ +<?php +/** + * Resends validation emails to a user or users by guid + * + * @package Elgg.Core.Plugin + * @subpackage UserValidationByEmail + */ + +$user_guids = get_input('user_guids'); +$error = FALSE; + +if (!$user_guids) { + register_error(elgg_echo('uservalidationbyemail:errors:unknown_users')); + forward(REFERRER); +} + +$access = access_get_show_hidden_status(); +access_show_hidden_entities(TRUE); + +foreach ($user_guids as $guid) { + $user = get_entity($guid); + if (!$user instanceof ElggUser) { + $error = TRUE; + continue; + } + + // don't resend emails to validated users + $is_validated = uservalidationbyemail_get_user_validation_status($guid); + + if ($is_validated || !uservalidationbyemail_request_validation($guid)) { + $error = TRUE; + continue; + } +} + +access_show_hidden_entities($access); + +if (count($user_guids) == 1) { + $message_txt = elgg_echo('uservalidationbyemail:messages:resent_validation'); + $error_txt = elgg_echo('uservalidationbyemail:errors:could_not_resend_validation'); +} else { + $message_txt = elgg_echo('uservalidationbyemail:messages:resent_validations'); + $error_txt = elgg_echo('uservalidationbyemail:errors:could_not_resend_validations'); +} + +if ($error) { + register_error($error_txt); +} else { + system_message($message_txt); +} + +forward(REFERRER);
\ No newline at end of file diff --git a/mod/uservalidationbyemail/actions/validate.php b/mod/uservalidationbyemail/actions/validate.php new file mode 100644 index 000000000..c50053dce --- /dev/null +++ b/mod/uservalidationbyemail/actions/validate.php @@ -0,0 +1,53 @@ +<?php +/** + * Validate a user or users by guid + * + * @package Elgg.Core.Plugin + * @subpackage UserValidationByEmail + */ + +$user_guids = get_input('user_guids'); +$error = FALSE; + +if (!$user_guids) { + register_error(elgg_echo('uservalidationbyemail:errors:unknown_users')); + forward(REFERRER); +} + +$access = access_get_show_hidden_status(); +access_show_hidden_entities(TRUE); + +foreach ($user_guids as $guid) { + $user = get_entity($guid); + if (!$user instanceof ElggUser) { + $error = TRUE; + continue; + } + + // only validate if not validated + $is_validated = uservalidationbyemail_get_user_validation_status($guid); + $validate_success = uservalidationbyemail_set_user_validation_status($guid, TRUE); + + if (!$is_validated || !$validate_success || !$user->enable()) { + $error = TRUE; + continue; + } +} + +access_show_hidden_entities($access); + +if (count($user_guids) == 1) { + $message_txt = elgg_echo('uservalidationbyemail:messages:validated_user'); + $error_txt = elgg_echo('uservalidationbyemail:errors:could_not_validate_user'); +} else { + $message_txt = elgg_echo('uservalidationbyemail:messages:validated_users'); + $error_txt = elgg_echo('uservalidationbyemail:errors:could_not_validate_users'); +} + +if ($error) { + register_error($error_txt); +} else { + system_message($message_txt); +} + +forward(REFERRER);
\ No newline at end of file diff --git a/mod/uservalidationbyemail/languages/en.php b/mod/uservalidationbyemail/languages/en.php index 6b3a6f708..31dec24a3 100644 --- a/mod/uservalidationbyemail/languages/en.php +++ b/mod/uservalidationbyemail/languages/en.php @@ -24,7 +24,34 @@ If you can't click on the link, copy and paste it to your browser manually. 'email:confirm:success' => "You have confirmed your email address!", 'email:confirm:fail' => "Your email address could not be verified...", - 'uservalidationbyemail:registerok' => "To activate your account, please confirm your email address by clicking on the link we just sent you." + 'uservalidationbyemail:registerok' => "To activate your account, please confirm your email address by clicking on the link we just sent you.", + + 'uservalidationbyemail:admin:no_unvalidated_users' => 'No unvalidated users.', + + 'uservalidationbyemail:admin:unvalidated' => 'Unvalidated', + 'uservalidationbyemail:admin:user_created' => 'Registered %s', + 'uservalidationbyemail:admin:resend_validation' => 'Resend validation', + 'uservalidationbyemail:admin:validate' => 'Validate', + 'uservalidationbyemail:admin:delete' => 'Delete', + 'uservalidationbyemail:confirm_validate_user' => 'Validate %s?', + 'uservalidationbyemail:confirm_resend_validation' => 'Resend validation email to %s?', + 'uservalidationbyemail:confirm_delete' => 'Delete %s?', + 'uservalidationbyemail:admin:with_checked' => 'With checked:', + + 'uservalidationbyemail:errors:unknown_users' => 'Unknown users', + 'uservalidationbyemail:errors:could_not_validate_user' => 'Could not validate user.', + 'uservalidationbyemail:errors:could_not_validate_users' => 'Could not validate all checked users.', + 'uservalidationbyemail:errors:could_not_delete_user' => 'Could not delete user.', + 'uservalidationbyemail:errors:could_not_delete_users' => 'Could not delete all checked users.', + 'uservalidationbyemail:errors:could_not_resend_validation' => 'Could not resend validation request.', + 'uservalidationbyemail:errors:could_not_resend_validations' => 'Could not resend all validation requests to checked users.', + + 'uservalidationbyemail:messages:validated_user' => 'User validated.', + 'uservalidationbyemail:messages:validated_users' => 'All checked users validated.', + 'uservalidationbyemail:messages:deleted_user' => 'User deleted.', + 'uservalidationbyemail:messages:deleted_users' => 'All checked users deleted.', + 'uservalidationbyemail:messages:resent_validation' => 'Validation request resent.', + 'uservalidationbyemail:messages:resent_validations' => 'Validation requests resent to all checked users.' ); diff --git a/mod/uservalidationbyemail/lib/functions.php b/mod/uservalidationbyemail/lib/functions.php index ed66b40d4..0610c1809 100644 --- a/mod/uservalidationbyemail/lib/functions.php +++ b/mod/uservalidationbyemail/lib/functions.php @@ -104,4 +104,45 @@ function uservalidationbyemail_set_user_validation_status($user_guid, $status, $ } return FALSE; +} + +/** + * Returns the validation status of a user. + * + * @param unknown_type $user_guid + * @return int|null + */ +function uservalidationbyemail_get_user_validation_status($user_guid) { + return get_metadata_byname($user_guid, 'validated'); +} + +/** + * Returns all users who haven't been validated. + * + * "Unvalidated" means metadata of validated is not set or not truthy. + * We can't use the elgg_get_entities_from_metadata() because you can't say + * "where the entity has metadata set OR it's not equal to 1". + * + * This doesn't include any security, so should be called ONLY be admin users! + * @return array + */ +function uservalidationbyemail_get_unvalidated_users() { + global $CONFIG; + + $validated_id = get_metastring_id('validated'); + $one_id = get_metastring_id(1); + + // thanks to daveb@freenode for the SQL tips! + $q = "SELECT e.* FROM {$CONFIG->dbprefix}entities e + WHERE e.type = 'user' + AND 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) + + ORDER BY e.guid DESC"; + + $users = get_data($q, 'entity_row_to_elggstar'); + return $users; }
\ No newline at end of file diff --git a/mod/uservalidationbyemail/start.php b/mod/uservalidationbyemail/start.php index 677fea231..1dcb5509f 100644 --- a/mod/uservalidationbyemail/start.php +++ b/mod/uservalidationbyemail/start.php @@ -33,6 +33,16 @@ function uservalidationbyemail_init() { // register Walled Garden public pages register_plugin_hook('public_pages', 'walled_garden', 'uservalidationbyemail_public_pages'); + + // admin interface to manually validate users + elgg_add_admin_submenu_item('unvalidated', elgg_echo('uservalidationbyemail:admin:unvalidated'), 'users'); + + $action_path = dirname(__FILE__) . '/actions'; + + register_action('uservalidationbyemail/validate', FALSE, "$action_path/validate.php", TRUE); + register_action('uservalidationbyemail/resend_validation', FALSE, "$action_path/resend_validation.php", TRUE); + register_action('uservalidationbyemail/delete', FALSE, "$action_path/delete.php", TRUE); + register_action('uservalidationbyemail/bulk_action', FALSE, "$action_path/bulk_action.php", TRUE); } /** diff --git a/mod/uservalidationbyemail/views/default/admin/users/unvalidated.php b/mod/uservalidationbyemail/views/default/admin/users/unvalidated.php new file mode 100644 index 000000000..4a14482df --- /dev/null +++ b/mod/uservalidationbyemail/views/default/admin/users/unvalidated.php @@ -0,0 +1,35 @@ +<?php +/** + * Admin area to view, validate, resend validation email, or delete unvalidated users. + * + * @package Elgg.Core.Plugin + * @subpackage UserValidationByEmail.Administration + */ + +// @todo pagination would be nice. +$users = uservalidationbyemail_get_unvalidated_users(); + +if ($users) { + foreach ($users as $user) { + $form_body .= elgg_view('uservalidationbyemail/unvalidated_user', array('user' => $user)); + } +} else { + echo elgg_echo('uservalidationbyemail:admin:no_unvalidated_users'); + return; +} + +$form_body .= elgg_echo('uservalidationbyemail:admin:with_checked') . elgg_view('input/pulldown', array( + 'internalname' => 'action_type', + 'options_values' => array( + 'validate' => elgg_echo('uservalidationbyemail:admin:validate'), + 'resend_validation' => elgg_echo('uservalidationbyemail:admin:resend_validation'), + 'delete' => elgg_echo('uservalidationbyemail:admin:delete'), + ) +)); + +$form_body .= '<br />' . elgg_view('input/button', array('value' => elgg_echo('submit'))); + +echo elgg_view('input/form', array( + 'action' => $vars['url'] . 'action/uservalidationbyemail/bulk_action', + 'body' => $form_body +));
\ No newline at end of file diff --git a/mod/uservalidationbyemail/views/default/uservalidationbyemail/unvalidated_user.php b/mod/uservalidationbyemail/views/default/uservalidationbyemail/unvalidated_user.php new file mode 100644 index 000000000..06c4e633e --- /dev/null +++ b/mod/uservalidationbyemail/views/default/uservalidationbyemail/unvalidated_user.php @@ -0,0 +1,53 @@ +<?php +/** + * Formats and list an unvalidated user. + * + * @package Elgg.Core.Plugin + * @subpackage UserValidationByEmail.Administration + */ + +$user = elgg_get_array_value('user', $vars); + +// doesn't work. +//$checkbox = elgg_view('input/checkboxes', array( +// 'internalname' => 'user_guids', +// 'options' => array("$user->username - \"$user->name\" <$user->email>" => $user->guid) +//)); +$checkbox = "<label><input type=\"checkbox\" value=\"$user->guid\" class=\"input_checkboxes\" name=\"user_guids[]\">" + . "$user->username - \"$user->name\" <$user->email></label>"; + +$created = sprintf(elgg_echo('uservalidationbyemail:admin:user_created'), elgg_view_friendly_time($user->time_created)); + +$validate = elgg_view('output/confirmlink', array( + 'confirm' => sprintf(elgg_echo('uservalidationbyemail:confirm_validate_user'), $user->username), + 'href' => $vars['url'] . "action/uservalidationbyemail/validate/?user_guids[]=$user->guid", + 'text' => elgg_echo('uservalidationbyemail:admin:validate') +)); + +$resend_email = elgg_view('output/confirmlink', array( + 'confirm' => sprintf(elgg_echo('uservalidationbyemail:confirm_resend_validation'), $user->username), + 'href' => $vars['url'] . "action/uservalidationbyemail/resend_validation/?user_guids[]=$user->guid", + 'text' => elgg_echo('uservalidationbyemail:admin:resend_validation') +)); + +$delete = elgg_view('output/confirmlink', array( + 'confirm' => sprintf(elgg_echo('uservalidationbyemail:confirm_delete'), $user->username), + 'href' => $vars['url'] . "action/uservalidationbyemail/delete/?user_guids[]=$user->guid", + 'text' => elgg_echo('uservalidationbyemail:admin:delete') +)); + +// @todo All of these hard coded styles need to be removed. +// they're here because you can't currently extend the admin css. +?> + +<div class="admin_settings radius8" style="border: 1px solid black; padding: 5px;"> + <div class="uservalidationbyemail_unvalidated_controls" style="float: right"> + <?php echo "$resend_email | $validate | $delete"; ?> + </div> + + <?php echo $checkbox; ?> + + <div class="uservalidationbyemail_unvalidated_user_details" style="margin-left: 15px; font-size: smaller;"> + <?php echo $created; ?> + </div> +</div> |