Making WordPress.org

Changeset 10981


Ignore:
Timestamp:
05/17/2021 04:58:00 AM (4 years ago)
Author:
dd32
Message:

Registration: Allow changing of email address during the registration flow.

This is only available once per account, and only prior to confirming the email address.

Fixes #5181.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login
Files:
6 edited

Legend:

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

    r10964 r10981  
    326326 * Save the user profile fields, potentially prior to user creation and prior to email confirmation.
    327327 */
    328 function wporg_login_save_profile_fields( $pending_user = false ) {
     328function wporg_login_save_profile_fields( $pending_user = false, $state = '' ) {
    329329    if ( ! $_POST || empty( $_POST['user_fields'] ) ) {
    330330        return false;
     
    358358    }
    359359
     360    $updated_email = false;
     361    if (
     362        'pending' === $state &&
     363        empty( $pending_user['meta']['changed_email'] ) && // Only if they've not changed it before.
     364        ! empty( $_POST['user_email'] ) &&
     365        wp_unslash( $_POST['user_email'] ) !== $pending_user['user_email']
     366    ) {
     367        // Validate the email
     368        $error_user_email = rest_do_request( new WP_REST_Request( 'GET', '/wporg/v1/email-in-use/' . wp_unslash( $_POST['user_email'] ) ) );
     369        if ( $error_user_email->get_data()['available'] ) {
     370            // Change their email, resend confirmation.
     371            $pending_user['meta']['changed_email'] = $pending_user['user_email'];
     372            $pending_user['user_email']            = wp_unslash( $_POST['user_email'] );
     373            $pending_user['user_activation_key']   = ''; // Clear any existing email hash.
     374            $updated_email                         = true;
     375
     376            // Validate heuristics.
     377            if ( function_exists( 'wporg_registration_check_private_heuristics' ) ) {
     378                // Returns block, review, allow.
     379                $pending_user['meta']['heuristics'] = wporg_registration_check_private_heuristics( [
     380                    'user_login' => $pending_user['user_login'],
     381                    'user_email' => $pending_user['user_email']
     382                ] );
     383            }
     384
     385            // If the new email fails our checks, and the user hasn't manually been approved..
     386            if ( 'allow' !== $pending_user['meta']['heuristics'] && $pending_user['cleared'] < 2 ) {
     387                $pending_user['cleared'] = 0;
     388            }
     389        }
     390    }
     391
    360392    if ( $pending_user ) {
    361393        wporg_update_pending_user( $pending_user );
     394        if ( $updated_email ) {
     395            wporg_login_send_confirmation_email( $pending_user );
     396        }
    362397    }
    363398
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions.php

    r10948 r10981  
    5757 */
    5858function wporg_login_replace_css() {
    59     wp_enqueue_style( 'wporg-login', get_template_directory_uri() . '/stylesheets/login.css', array( 'login', 'dashicons' ), '20210414' );
     59    wp_enqueue_style( 'wporg-login', get_template_directory_uri() . '/stylesheets/login.css', array( 'login', 'dashicons' ), '20210517' );
    6060}
    6161add_action( 'login_init', 'wporg_login_replace_css' );
     
    7373
    7474    wp_enqueue_style( 'wporg-normalize', get_template_directory_uri() . '/stylesheets/normalize.css', 3 );
    75     wp_enqueue_style( 'wporg-login', get_template_directory_uri() . '/stylesheets/login.css', array( 'login', 'dashicons' ), '20210414' );
     75    wp_enqueue_style( 'wporg-login', get_template_directory_uri() . '/stylesheets/login.css', array( 'login', 'dashicons' ), '20210517' );
    7676}
    7777add_action( 'wp_enqueue_scripts', 'wporg_login_scripts' );
     
    9898    );
    9999
    100     wp_register_script( 'wporg-registration', get_template_directory_uri() . '/js/registration.js', array( 'recaptcha-api', 'jquery' ), '20200707' );
     100    wp_register_script( 'wporg-registration', get_template_directory_uri() . '/js/registration.js', array( 'recaptcha-api', 'jquery' ), '20210517' );
    101101    wp_localize_script( 'wporg-registration', 'wporg_registration', array(
    102         'rest_url' => esc_url_raw( rest_url( "wporg/v1" ) )
     102        'rest_url' => esc_url_raw( rest_url( 'wporg/v1' ) )
    103103    ) );
    104104
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/js/registration.js

    r10029 r10981  
    6060            });
    6161
     62            $loginForm.on( 'click', '.change-email', function( e ) {
     63                e.preventDefault();
     64
     65                $(this).remove();
     66                $loginForm.find( '.login-email' ).removeClass( 'hidden' ).find( 'input' ).addClass( 'error' );
     67            });
     68
    6269            // If the form has data in it upon load, immediately trigger the validation.
    6370            if ( $loginForm.find('#user_login').val() ) {
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/pending-create.php

    r10964 r10981  
    5151}
    5252
    53 if ( wporg_login_save_profile_fields( $pending_user ) ) {
     53if ( wporg_login_save_profile_fields( $pending_user, 'create' ) ) {
    5454    // re-fetch the user, it's probably changed.
    5555    $pending_user = wporg_get_pending_user( $activation_user );
     
    149149    <p class="login-login">
    150150        <label for="user_login"><?php _e( 'Username', 'wporg' ); ?></label>
    151         <input type="text" disabled="disabled" class=" disabled" value="<?php echo esc_attr( $activation_user ); ?>" size="20" />
     151        <input type="text" disabled="disabled" class="disabled" value="<?php echo esc_attr( $activation_user ); ?>" size="20" />
    152152    </p>
    153153
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/pending-profile.php

    r10928 r10981  
    4444}
    4545
    46 if ( wporg_login_save_profile_fields( $pending_user ) ) {
     46if ( wporg_login_save_profile_fields( $pending_user, 'pending' ) ) {
    4747    // re-fetch the user, it's probably changed.
    4848    $pending_user = wporg_get_pending_user( $profile_user );
    4949}
    5050wp_enqueue_script( 'wporg-registration' );
     51
     52// Allow changing the email, if they've not already changed it once.
     53$email_change_available = empty( $pending_user['meta']['changed_email'] );
    5154
    5255get_header();
     
    5962            printf(
    6063                /* translators: %s Email address */
    61                 __( 'Please check your email %s for a confirmation link to set your password.', 'wporg' ) . '<br>' .
    62                 '<a href="#" class="resend" data-account="%s">' . __( 'Resend confirmation email.', 'wporg' ) . '</a>',
     64                __( 'Please check your email %s for a confirmation link to set your password.', 'wporg' ) .
     65                '<br><br>' . '<a href="#" class="resend" data-account="%s">' . __( 'Resend confirmation email.', 'wporg' ) . '</a>' .
     66                ( $email_change_available ? '<br>' . '<a href="#" class="change-email">' . __( 'Incorrect email? Update email address.', 'wporg' ) . '</a>' : '' ),
    6367                '<code>' . esc_html( $pending_user['user_email'] ) . '</code>',
    6468                esc_attr( $pending_user['user_email'] )
     
    6771            printf(
    6872                /* translators: %s Email address */
    69                 __( 'Your account is pending approval. You will receive an email at %s to set your password when approved.', 'wporg' ) . '<br>' .
    70                 __( 'Please contact %s for more details.', 'wporg' ),
     73                __( 'Your account is pending approval. You will receive an email at %s to set your password when approved.', 'wporg' ) .
     74                '<br>' . __( 'Please contact %s for more details.', 'wporg' ) .
     75                ( $email_change_available ? '<br><br>' . '<a href="#" class="change-email">' . __( 'Incorrect email? Update email address.', 'wporg' ) . '</a>' : '' ),
    7176                '<code>' . esc_html( $pending_user['user_email'] ) . '</code>',
    7277                '<a href="mailto:' . $sso::SUPPORT_EMAIL . '">' . $sso::SUPPORT_EMAIL . '</a>'
     
    8388        <label for="user_login"><?php _e( 'Username', 'wporg' ); ?></label>
    8489        <input type="text" disabled="disabled" class=" disabled" value="<?php echo esc_attr( $profile_user ); ?>" size="20" />
     90    </p>
     91
     92    <p class="login-email hidden">
     93        <label for="user_email"><?php _e( 'Email', 'wporg' ); ?></label>
     94        <input type="text" name="user_email" value="<?php echo esc_attr( $pending_user['user_email'] ); ?>" size="20" maxlength="100" />
    8595    </p>
    8696
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/stylesheets/login.css

    r10899 r10981  
    5050    font-size: 14px;
    5151}
    52 
     52.hidden,
    5353#backtoblog {
    5454    display: none;
     
    444444}
    445445
    446 body.route-pending-profile .login-login input.disabled,
    447 body.route-pending-create .login-login input.disabled {
     446body.route-pending-profile input.disabled,
     447body.route-pending-create input.disabled {
    448448    color: #666;
    449449    background: transparent;
Note: See TracChangeset for help on using the changeset viewer.