Making WordPress.org

Changeset 10029


Ignore:
Timestamp:
07/07/2020 08:02:03 AM (6 years ago)
Author:
dd32
Message:

Login: Allow users to resend the signup confirmation email.

To trigger this, either the user needs to click the resend link on the post-signup profile-info page, or attempt to sign up again using the same username or email.

The emails are rate limited depending on the age of the account, and also based on some WordPress.org anti-spam measures.

See #5278.

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

Legend:

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

    r10010 r10029  
    5555
    5656    if ( $email ) {
    57         wporg_send_confirmation_email( $email );
     57        wporg_login_send_confirmation_email( $email );
    5858    }
    5959
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions-registration.php

    r10028 r10029  
    9292    }
    9393
    94     wporg_send_confirmation_email( $user_email );
     94    wporg_login_send_confirmation_email( $user_email );
    9595
    9696    $url = home_url( sprintf(
     
    107107 * Send a "Welcome to WordPress.org" confirmation email.
    108108 */
    109 function wporg_send_confirmation_email( $user_email ) {
     109function wporg_login_send_confirmation_email( $user ) {
    110110    global $wpdb;
    111111
    112     $user = wporg_get_pending_user( $user_email );
     112    $user = wporg_get_pending_user( $user );
    113113
    114114    if ( ! $user || $user['created'] ) {
     
    117117
    118118    $user_login = $user['user_login'];
     119    $user_email = $user['user_email'];
    119120
    120121    $activation_key = wp_hash( $user_login . ':' . $user_email, 'activation' );
     
    150151function wporg_get_pending_user( $login_or_email ) {
    151152    global $wpdb;
     153
     154    // Is it a pending user object already?
     155    if ( is_array( $login_or_email ) && isset( $login_or_email['pending_id'] ) ) {
     156        return $login_or_email;
     157    }
    152158
    153159    $pending_user = $wpdb->get_row( $wpdb->prepare(
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions-restapi.php

    r9146 r10029  
    1919        'callback' => 'wporg_login_rest_email_in_use'
    2020    ) );
     21
     22    register_rest_route( 'wporg/v1', '/resend-confirmation-email/?', array(
     23        'methods'  => WP_REST_Server::EDITABLE,
     24        'callback' => 'wporg_login_rest_resend_confirmation_email'
     25    ) );
    2126}
    2227add_action( 'rest_api_init', 'wporg_login_rest_routes' );
     
    3136        return [
    3237            'available' => false,
    33             'error' => __( 'That username is already in use.', 'wporg' ) . '<br>' . __( 'Is it yours? <a href="/lostpassword">Reset your password</a>.', 'wporg' ),
     38            'error' => __( 'That username is already in use.', 'wporg' ) . '<br>' .
     39                __( 'Is it yours? <a href="/lostpassword">Reset your password</a>.', 'wporg' ),
    3440            'avatar' => get_avatar( $user, 64 ),
    3541        ];
     
    4046        return [
    4147            'available' => false,
    42             'error' => __( 'That username is already in use.', 'wporg' ) . '<br>' . __( 'The registration is still pending, please check your email for the confirmation link.', 'wporg' ),
     48            'error' => __( 'That username is already in use.', 'wporg' ) . '<br>' .
     49                __( 'The registration is still pending, please check your email for the confirmation link.', 'wporg' ) . '<br>' .
     50                '<a href="#" class="resend">' . __( 'Resend confirmation email.', 'wporg' ) . '</a>',
    4351            'avatar' => get_avatar( $pending->user_email, 64 ),
    4452        ];
     
    6573        return [
    6674            'available' => false,
    67             'error' => __( 'That email address already has an account.', 'wporg' ) . '<br>' . __( 'Is it yours? <a href="/lostpassword">Reset your password</a>.', 'wporg' ),
     75            'error' => __( 'That email address already has an account.', 'wporg' ) . '<br>' .
     76                __( 'Is it yours? <a href="/lostpassword">Reset your password</a>.', 'wporg' ),
    6877            'avatar' => get_avatar( $user, 64 ),
    6978        ];
     
    7483        return [
    7584            'available' => false,
    76             'error' => __( 'That email address already has an account.', 'wporg' ) . '<br>' . __( 'The registration is still pending, please check your email for the confirmation link.', 'wporg' ),
     85            'error' => __( 'That email address already has an account.', 'wporg' ) . '<br>' .
     86                __( 'The registration is still pending, please check your email for the confirmation link.', 'wporg' ) . '<br>' .
     87                '<a href="#" class="resend">' . __( 'Resend confirmation email.', 'wporg' ) . '</a>',
    7788            'avatar' => get_avatar( $email, 64 ),
    7889        ];
     
    91102    return [ 'available' => true ];
    92103}
     104
     105/*
     106 * Resend a confirmation email to create an account.
     107 *
     108 * This API intentionally doesn't report if it performs the action, always returning the success message.
     109 */
     110function wporg_login_rest_resend_confirmation_email( $request ) {
     111    $account = $request['account'];
     112
     113    $success_message = sprintf(
     114        __( 'Please check your email %s for a confirmation link to set your password.', 'wporg' ),
     115        '<code>' . esc_html( $account ) . '</code>'
     116    );
     117
     118    $pending_user = wporg_get_pending_user( $request['account'] );
     119    if ( ! $pending_user || $pending_user['created'] ) {
     120        return $success_message;
     121    }
     122
     123    // Allow for w.org plugins to block the action.
     124    if ( null !== ( $pre_register_error = apply_filters( 'wporg_login_pre_registration', null, $pending_user['user_login'], $pending_user['user_email'], $pending_user['meta']['user_mailinglist'] ) ) ) {
     125        return $success_message;
     126    }
     127
     128    // Only one email per..
     129    // - 1 minute for brand new accounts (<15min)
     130    // - 5 minutes for new accounts (<1hr)
     131    // - 3 hours there after
     132    list( $requested_time, ) = explode( ':', $pending_user['user_activation_key'] );
     133    $time_limit = 3 * HOUR_IN_SECONDS;
     134
     135    if ( time() - strtotime( $pending_user['user_registered'] ) < HOUR_IN_SECONDS ) {
     136        $time_limit = 5 * MINUTE_IN_SECONDS;
     137    }
     138
     139    if ( time() - strtotime( $pending_user['user_registered'] ) < 15 * MINUTE_IN_SECONDS ) {
     140        $time_limit = MINUTE_IN_SECONDS;
     141    }
     142
     143    if ( ( time() - $requested_time ) < $time_limit ) {
     144        return $success_message;
     145    }
     146
     147    wporg_login_send_confirmation_email( $pending_user );
     148
     149    return $success_message;
     150}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/js/registration.js

    r9224 r10029  
    2020
    2121                $.get( rest_url, function( datas ) {
    22                     $this.parents( 'p' ).nextUntil( 'p', 'div.message.error' ).remove();
     22                    $this.closest( 'p' ).nextUntil( 'p', 'div.message' ).remove();
    2323                    $this.removeClass( 'good' );
    2424
    2525                    if ( ! datas.available ) {
    2626                        $this.addClass( 'error' );
    27                         $this.parents( 'p' ).after(
     27                        $this.closest( 'p' ).after(
    2828                            '<div class="message error' + ( datas.avatar ? ' with-avatar' : '' ) +  '"><p>' +
    2929                            ( datas.avatar ? datas.avatar : '' ) + '<span>' +
     
    3131                            '</span></p></div>'
    3232                        );
     33                        $this.closest( 'p' ).next('div.message.error').find( '.resend' ).data( 'account', $this.val() );
    3334                    } else {
    3435                        $this.addClass( 'good' );
     
    3637                } );
    3738            } );
     39
     40            $loginForm.on( 'click', '.resend', function( e ) {
     41                var $this = $(this),
     42                    account = $this.data('account');
     43
     44                e.preventDefault();
     45
     46                $this.closest( 'div.message' ).next('div.message.info').remove();
     47
     48                $.post(
     49                    wporg_registration.rest_url + '/resend-confirmation-email',
     50                    {
     51                        account: account,
     52                    },
     53                    function( datas ) {
     54                        $this.closest( 'div.message' ).after(
     55                            '<div class="message info"><p><span>' + datas + '</span></p></div>'
     56                        );
     57                    }
     58                );
     59
     60            });
    3861
    3962            // If the form has data in it upon load, immediately trigger the validation.
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/pending-profile.php

    r9835 r10029  
    5050get_header();
    5151?>
    52 <div class="message info">
    53     <p><?php
    54         printf(
    55             /* translators: %s Email address */
    56             __( 'Please check your email %s for a confirmation link to set your password.', 'wporg' ),
    57             '<code>' . esc_html( $pending_user['user_email'] ) . '</code>'
    58         );
    59     ?></p>
    60 </div>
     52<form name="registerform" id="registerform" action="" method="post">
    6153
    62 <p class="intro">
    63 <?php _e( 'Complete your WordPress.org Profile information.', 'wporg' ); ?>
    64 </p>
     54    <div class="message info">
     55        <p><?php
     56            printf(
     57                /* translators: %s Email address */
     58                __( 'Please check your email %s for a confirmation link to set your password.', 'wporg' ) . '<br>' .
     59                '<a href="#" class="resend" data-account="%s">' . __( 'Resend confirmation email.', 'wporg' ) . '</a>',
     60                '<code>' . esc_html( $pending_user['user_email'] ) . '</code>',
     61                esc_attr( $pending_user['user_email'] )
     62            );
     63        ?></p>
     64    </div>
    6565
    66 <form name="registerform" id="registerform" action="" method="post">
     66    <p class="intro">
     67    <?php _e( 'Complete your WordPress.org Profile information.', 'wporg' ); ?>
     68    </p>
    6769
    6870    <p class="login-login">
Note: See TracChangeset for help on using the changeset viewer.