Making WordPress.org


Ignore:
Timestamp:
09/23/2019 03:52:23 AM (6 years ago)
Author:
dd32
Message:

Login: Store user registrations in a custom table until they confirm their email address (at which time, we create the actual wp_users records).

This is to combat the significant number of unconfirmed accounts that are created, by separating them it's easier to purge them periodically, but also easier to add extra anti-spam checks as needed.

See #4739.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/pending-create.php

    r9139 r9146  
    11<?php
    22/**
    3  * The post-register profile-fields Template
     3 * The post-email-confirm Template
    44 *
    55 * @package wporg-login
    66 */
    77
    8     //      'register-confirm' => '/register/confirm/(?P<confirm_user>[^/]+)/(?P<confirm_key>[^/]+)',
     8$activation_user = WP_WPOrg_SSO::$matched_route_params['confirm_user'] ?? false;
     9$activation_key  = WP_WPOrg_SSO::$matched_route_params['confirm_key']  ?? false;
    910
    10 $confirm_user = isset( WP_WPOrg_SSO::$matched_route_params['confirm_user'] ) ? WP_WPOrg_SSO::$matched_route_params['confirm_user'] : false;
    11 $confirm_key  = isset( WP_WPOrg_SSO::$matched_route_params['confirm_key'] ) ? WP_WPOrg_SSO::$matched_route_params['confirm_key'] : false;
     11$pending_user = wporg_get_pending_user( $activation_user );
     12if ( ! $pending_user ) {
     13    // TODO: add a handler for "Link is expired". The pending user record has been purged.
     14    // See Line 33 below for the second case where this is needed.
     15}
    1216
    13 $can_access = true;
    14 if (
    15     $confirm_user && $confirm_key &&
    16     ( $user = get_user_by( 'login', $confirm_user ) ) &&
    17     $user->exists()
    18 ) {
    19     wp_set_current_user( $user->ID );
     17$can_access = false;
     18if ( $pending_user && $pending_user['user_activation_key'] && ! $pending_user['created'] ) {
     19    $expiration_duration = WEEK_IN_SECONDS; // Time that the user has to confirm the account.
    2020
    21     $user_activation_key = $user->user_activation_key;
    22     if ( ! $user_activation_key ) {
    23         // The activation key may not be in the cached user object, so we'll fetch it manually.
    24         $user_activation_key = $wpdb->get_var( $wpdb->prepare( "SELECT user_activation_key FROM {$wpdb->users} WHERE ID = %d", $user->ID ) );
     21    list( $user_request_time, $hashed_activation_key ) = explode( ':', $pending_user['user_activation_key'], 2 );
     22    $expiration_time                                   = $user_request_time + $expiration_duration;
     23
     24    $hash_is_correct = wp_check_password( $activation_key, $hashed_activation_key );
     25
     26    if ( $hash_is_correct && time() < $expiration_time ) {
     27        $can_access = true;
     28    } elseif ( $hash_is_correct ) {
     29        // TODO: Add a handler for "Link is expired".
     30        // For now, ignore the expiry date on the email links.
     31        // This URL is invalidated once the user is created anyway.
     32        $can_access = true;
    2533    }
    26 
    27     list( $reset_time, $hashed_activation_key ) = explode( ':', $user_activation_key, 2 );
    28 
    29     if ( empty( $wp_hasher ) ) {
    30         require_once ABSPATH . WPINC . '/class-phpass.php';
    31         $wp_hasher = new PasswordHash( 8, true );
    32     }
    33     $can_access = $wp_hasher->CheckPassword( $confirm_key, $hashed_activation_key );
    34 
    35     // Keys are only valid for 7 days (or until used)
    36     $can_access = $can_access && ( $reset_time + ( 7*DAY_IN_SECONDS ) > time() );
     34} elseif ( $pending_user && $pending_user['created'] ) {
     35    wp_safe_redirect( 'https://wordpress.org/support/' );
     36    die();
    3737}
    3838
    3939if ( ! $can_access ) {
    40     wp_set_current_user( 0 );
    4140    wp_safe_redirect( "/" );
    4241    die();
    43 } elseif ( !empty( $_POST['user_pass'] ) ) {
     42}
     43
     44if ( isset( $_POST['user_pass'] ) ) {
    4445    $user_pass = wp_unslash( $_POST['user_pass'] );
     46
     47    if ( $pending_user && ! $pending_user['created'] ) {
     48        $user = wporg_login_create_user_from_pending( $pending_user, $user_pass );
     49        if ( $user ) {
     50            wp_set_current_user( $user->ID );
     51            wp_set_auth_cookie( $user->ID, true );
     52        }
     53    }
    4554
    4655    wporg_login_save_profile_fields();
    4756
    48     add_filter( 'send_password_change_email', '__return_false' );
    49     if ( wp_update_user( wp_slash( array(
    50         'ID' => $user->ID,
    51         'user_pass' => $user_pass,
    52     ) ) ) ) {
    53         $wpdb->update( $wpdb->users, array( 'user_activation_key' => '' ), array( 'ID' => $user->ID ) );
    54         wp_set_auth_cookie( $user->ID, true );
    55         wp_safe_redirect( 'https://wordpress.org/support/' );
    56         die();
    57     }
     57    wp_safe_redirect( 'https://wordpress.org/support/' );
     58    die();
    5859}
    5960
     
    8687<!--    <p class="description indicator-hint"><?php _e( 'Hint: The password should be at least twelve characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ &amp; ).', 'wporg' ); ?></p> -->
    8788
    88     <?php include __DIR__ . '/partials/register-profilefields.php'; ?>
     89    <?php
     90        $fields = &$pending_user['meta'];
     91        include __DIR__ . '/partials/register-profilefields.php';
     92    ?>
    8993
    9094    <p class="login-submit">
Note: See TracChangeset for help on using the changeset viewer.