/** * Handle the loading of the Activate screen. * * @todo Move the actual activation process into an action in bp-members-actions.php */ function bp_core_screen_activation() { // Bail if not viewing the activation page if (!bp_is_current_component('activate')) { return false; } // If the user is already logged in, redirect away from here if (is_user_logged_in()) { // If activation page is also front page, set to members directory to // avoid an infinite loop. Otherwise, set to root domain. $redirect_to = bp_is_component_front_page('activate') ? bp_get_root_domain() . '/' . bp_get_members_root_slug() : bp_get_root_domain(); // Trailing slash it, as we expect these URL's to be $redirect_to = trailingslashit($redirect_to); /** * Filters the URL to redirect logged in users to when visiting activation page. * * @since BuddyPress (1.9.0) * * @param string $redirect_to URL to redirect user to. */ $redirect_to = apply_filters('bp_loggedin_activate_page_redirect_to', $redirect_to); // Redirect away from the activation page bp_core_redirect($redirect_to); } // grab the key (the old way) $key = isset($_GET['key']) ? $_GET['key'] : ''; // grab the key (the new way) if (empty($key)) { $key = bp_current_action(); } // Get BuddyPress $bp = buddypress(); // we've got a key; let's attempt to activate the signup if (!empty($key)) { /** * Filters the activation signup. * * @since BuddyPress (1.1.0) * * @param bool|int $value Value returned by activation. * Integer on success, boolean on failure. */ $user = apply_filters('bp_core_activate_account', bp_core_activate_signup($key)); // If there were errors, add a message and redirect if (!empty($user->errors)) { bp_core_add_message($user->get_error_message(), 'error'); bp_core_redirect(trailingslashit(bp_get_root_domain() . '/' . $bp->pages->activate->slug)); } $hashed_key = wp_hash($key); // Check if the signup avatar folder exists. If it does, move the folder to // the BP user avatars directory if (file_exists(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key)) { @rename(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key, bp_core_avatar_upload_path() . '/avatars/' . $user); } bp_core_add_message(__('Your account is now active!', 'buddypress')); $bp->activation_complete = true; } /** * Filters the template to load for the Member activation page screen. * * @since BuddyPress (1.1.1) * * @param string $value Path to the Member activation template to load. */ bp_core_load_template(apply_filters('bp_core_template_activate', array('activate', 'registration/activate'))); }
function bp_core_screen_activation() { global $bp, $wpdb; if (!bp_is_current_component('activate')) { return false; } // Check if an activation key has been passed if (isset($_GET['key'])) { // Activate the signup $user = apply_filters('bp_core_activate_account', bp_core_activate_signup($_GET['key'])); // If there were errors, add a message and redirect if (!empty($user->errors)) { bp_core_add_message($user->get_error_message(), 'error'); bp_core_redirect(trailingslashit(bp_get_root_domain() . '/' . $bp->pages->activate->slug)); } // Check for an uploaded avatar and move that to the correct user folder if (is_multisite()) { $hashed_key = wp_hash($_GET['key']); } else { $hashed_key = wp_hash($user); } // Check if the avatar folder exists. If it does, move rename it, move // it and delete the signup avatar dir if (file_exists(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key)) { @rename(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key, bp_core_avatar_upload_path() . '/avatars/' . $user); } bp_core_add_message(__('Your account is now active!', 'buddypress')); $bp->activation_complete = true; } if ('' != locate_template(array('registration/activate'), false)) { bp_core_load_template(apply_filters('bp_core_template_activate', 'activate')); } else { bp_core_load_template(apply_filters('bp_core_template_activate', 'registration/activate')); } }
/** * Activate a pending account. * * @since 2.0.0 * * @param array $signup_ids Single ID or list of IDs to activate. * @return array */ public static function activate($signup_ids = array()) { if (empty($signup_ids) || !is_array($signup_ids)) { return false; } $to_activate = self::get(array('include' => $signup_ids)); if (!($signups = $to_activate['signups'])) { return false; } $result = array(); /** * Fires before activation of user accounts. * * @since 2.0.0 * * @param array $signup_ids Array of IDs to activate. */ do_action('bp_core_signup_before_activate', $signup_ids); foreach ($signups as $signup) { $user = bp_core_activate_signup($signup->activation_key); if (!empty($user->errors)) { $user_id = username_exists($signup->user_login); if (2 !== self::check_user_status($user_id)) { $user_id = false; } if (empty($user_id)) { // Status is not 2, so user's account has been activated. $result['errors'][$signup->signup_id] = array($signup->user_login, esc_html__('the sign-up has already been activated.', 'buddypress')); // Repair signups table. self::validate($signup->activation_key); // We have a user id, account is not active, let's delete it. } else { $result['errors'][$signup->signup_id] = array($signup->user_login, $user->get_error_message()); } } else { $result['activated'][] = $user; } } /** * Fires after activation of user accounts. * * @since 2.0.0 * * @param array $signup_ids Array of IDs activated activate. * @param array $result Array of data for activated accounts. */ do_action('bp_core_signup_after_activate', $signup_ids, $result); /** * Filters the result of the metadata after user activation. * * @since 2.0.0 * * @param array $result Updated metadata related to user activation. */ return apply_filters('bp_core_signup_activate', $result); }
/** * @group bp_core_activate_signup */ public function test_bp_core_activate_signup_password() { global $wpdb; $signups = array('no-blog' => array('signup_id' => $this->factory->signup->create(array('user_login' => 'noblog', 'user_email' => '*****@*****.**', 'activation_key' => 'no-blog', 'meta' => array('field_1' => 'Foo Bar', 'password' => 'foobar'))), 'password' => 'foobar')); if (is_multisite()) { $signups['ms-blog'] = array('signup_id' => $this->factory->signup->create(array('user_login' => 'msblog', 'user_email' => '*****@*****.**', 'domain' => get_current_site()->domain, 'path' => get_current_site()->path . 'ms-blog', 'title' => 'Ding Dang', 'activation_key' => 'ms-blog', 'meta' => array('field_1' => 'Ding Dang', 'password' => 'dingdang'))), 'password' => 'dingdang'); } // Neutralize db errors $suppress = $wpdb->suppress_errors(); foreach ($signups as $key => $data) { $u = bp_core_activate_signup($key); $this->assertEquals(get_userdata($u)->user_pass, $data['password']); } $wpdb->suppress_errors($suppress); }
/** * Handle the loading of the Activate screen. */ function bp_core_screen_activation() { global $bp; if (!bp_is_current_component('activate')) { return false; } // If the user is logged in, redirect away from here if (is_user_logged_in()) { if (bp_is_component_front_page('activate')) { $redirect_to = trailingslashit(bp_get_root_domain() . '/' . bp_get_members_root_slug()); } else { $redirect_to = trailingslashit(bp_get_root_domain()); } bp_core_redirect(apply_filters('bp_loggedin_activate_page_redirect_to', $redirect_to)); return; } // Check if an activation key has been passed if (isset($_GET['key'])) { // Activate the signup $user = apply_filters('bp_core_activate_account', bp_core_activate_signup($_GET['key'])); // If there were errors, add a message and redirect if (!empty($user->errors)) { bp_core_add_message($user->get_error_message(), 'error'); bp_core_redirect(trailingslashit(bp_get_root_domain() . '/' . $bp->pages->activate->slug)); } $hashed_key = wp_hash($_GET['key']); // Check if the avatar folder exists. If it does, move rename it, move // it and delete the signup avatar dir if (file_exists(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key)) { @rename(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key, bp_core_avatar_upload_path() . '/avatars/' . $user); } bp_core_add_message(__('Your account is now active!', 'buddypress')); $bp->activation_complete = true; } bp_core_load_template(apply_filters('bp_core_template_activate', array('activate', 'registration/activate'))); }
/** * Activate a pending account. * * @since BuddyPress (2.0.0) * * @param array $signup_ids Single ID or list of IDs to activate. * @return array */ public static function activate($signup_ids = array()) { if (empty($signup_ids) || !is_array($signup_ids)) { return false; } $to_activate = self::get(array('include' => $signup_ids)); if (!($signups = $to_activate['signups'])) { return false; } $result = array(); do_action('bp_core_signup_before_activate', $signup_ids); foreach ($signups as $signup) { $user = bp_core_activate_signup($signup->activation_key); if (!empty($user->errors)) { $user_id = username_exists($signup->user_login); if (2 !== self::check_user_status($user_id)) { $user_id = false; } if (empty($user_id)) { // Status is not 2, so user's account has been activated $result['errors'][$signup->signup_id] = array($signup->user_login, esc_html__('the sign-up has already been activated.', 'buddypress')); // repare signups table self::validate($signup->activation_key); // we have a user id, account is not active, let's delete it } else { $result['errors'][$signup->signup_id] = array($signup->user_login, $user->get_error_message()); } } else { $result['activated'][] = $user; } } do_action('bp_core_signup_after_activate', $signup_ids, $result); return apply_filters('bp_core_signup_activate', $result); }
function bp_core_screen_activation() { global $bp, $wpdb; if ( BP_ACTIVATION_SLUG != $bp->current_component ) return false; /* Check if an activation key has been passed */ if ( isset( $_GET['key'] ) ) { require_once( ABSPATH . WPINC . '/registration.php' ); /* Activate the signup */ $user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $_GET['key'] ) ); /* If there was errors, add a message and redirect */ if ( $user->errors ) { bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' ); bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG ); } /* Check for an uploaded avatar and move that to the correct user folder */ if ( bp_core_is_multisite() ) $hashed_key = wp_hash( $_GET['key'] ); else $hashed_key = wp_hash( $user ); /* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */ if ( file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key ) ) @rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key, BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user ); bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) ); $bp->activation_complete = true; } if ( '' != locate_template( array( 'registration/activate' ), false ) ) bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) ); else bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) ); }
/** * generated random data */ function test_data() { set_time_limit(0); global $wpdb; $users = $wpdb->get_col("SELECT ID FROM {$wpdb->users} WHERE ID != 1"); if (is_multisite()) { $wpdb->query("DELETE FROM {$wpdb->signups}"); } foreach ($users as $id) { bp_core_delete_account($id); } $ngu = 2; #how much only good users $ngbu = 2; #how much not only good or only bad users $nbu = 2; #how much only bad users $content_types = array('A', 'B', 'C', 'D'); $bpmod =& bpModeration::get_istance(); $statuses = array_keys($bpmod->content_stati); $n_contents = 20; $flags_per_cont = 20; # +/- 30% $goodusers = array(); $badusers = array(); for ($i = 1; $i <= $ngu + $ngbu + $nbu; $i++) { $uid = bp_core_signup_user('user' . $i, 'pass', $i . '@foo.bar', array()); if (is_multisite()) { global $wpdb; $key_sql = "SELECT activation_key FROM {$wpdb->signups} WHERE user_email = '" . $i . "@foo.bar'"; $key = $wpdb->get_var($key_sql); } else { $key = get_user_meta($uid, 'activation_key'); } $uid = bp_core_activate_signup($key); is_multisite() and wp_set_password('pass', $uid); if ($i <= $ngu + $ngbu) { $goodusers[] = $uid; } if ($i > $ngu) { $badusers[] = $uid; } } bpModLoader::load_class('bpModObjContent'); bpModLoader::load_class('bpModObjFlag'); for ($i = 1; $i <= $n_contents; $i++) { $badu = $badusers[mt_rand(0, count($badusers) - 1)]; $cont = new bpModObjContent(); $cont->item_type = $content_types[mt_rand(0, count($content_types) - 1)]; $cont->item_id = mt_rand(1, 1000000); $cont->item_author = $badu; $cont->item_date = gmdate("Y-m-d H:i:s", time() - mt_rand(1000000, 2000000)); $cont->status = $statuses[mt_rand(0, count($statuses) - 1)]; $cont->save(); $flags = mt_rand($flags_per_cont * 0.7, $flags_per_cont * 1.3); for ($j = 1; $j <= $flags; $j++) { while ($badu == ($goodu = $goodusers[mt_rand(0, count($goodusers) - 1)])) { } $f = new bpModObjFlag(); $f->content_id = $cont->content_id; $f->reporter_id = $goodu; $f->date = gmdate("Y-m-d H:i:s", time() - mt_rand(0, 1000000)); $f->save(); } } update_site_option('bp_moderation_test_data_check', 'success'); }