Making WordPress.org

Changeset 10928


Ignore:
Timestamp:
04/27/2021 04:24:21 AM (5 years ago)
Author:
dd32
Message:

Login: Allow registrations with "low reCaptcha scores" to register, but go into a pending-moderation state.

This will allow legitimate users who receive a "Please try again" error to be manually approved.

This will also allow us to experiment with more aggressive anti-spam measures, as the majority of current spam registrations are human generated.

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

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/admin/class-user-registrations-list-table.php

    r10901 r10928  
    22
    33class User_Registrations_List_Table extends WP_List_Table {
     4
     5        function get_views() {
     6                global $wpdb;
     7
     8                $views = [
     9                        [
     10                                'all',
     11                                'All',
     12                        ],
     13                        [
     14                                'pending',
     15                                'Pending Email Confirmation',
     16                        ],
     17                        [
     18                                'registered',
     19                                'Completed registration',
     20                        ],
     21                        [
     22                                'spam',
     23                                'Caught in spam',
     24                        ],
     25                        [
     26                                'akismet',
     27                                'Akismet said no',
     28                        ]
     29                ];
     30
     31                $default      = 'all';
     32                $current_view = $_REQUEST['view'] ?? $default;
     33
     34                if ( isset( $_GET['s'] ) ) {
     35                        $default = 'search';
     36                        $views[0] = [
     37                                'search', 'All search results'
     38                        ];
     39
     40                        array_unshift( $views, [ 'all', 'All' ] );
     41
     42                        if ( 'all' === $current_view ) {
     43                                $current_view = 'search';
     44                        }
     45                }
     46
     47                return array_map(
     48                        function( $item ) use ( $current_view ) {
     49                                global $wpdb;
     50
     51                                $count = $wpdb->get_var(
     52                                        "SELECT count(*) FROM {$wpdb->base_prefix}user_pending_registrations WHERE " .
     53                                        $this->get_where_sql( $item[0] )
     54                                );
     55
     56                                $url = admin_url( 'index.php?page=user-registrations' );
     57                                if ( !empty( $_GET['s'] ) && 'all' != $item[0] ) {
     58                                        $url = add_query_arg( 's', urlencode( $_GET['s'] ), $url );
     59                                }
     60
     61                                $url = add_query_arg( 'view', $item[0], $url );
     62
     63                                return sprintf(
     64                                        '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>',
     65                                        $url,
     66                                        $current_view === $item[0] ? 'current' : '',
     67                                        $item[1],
     68                                        number_format_i18n( $count ),
     69                                );
     70                        }, $views
     71                );
     72        }
     73
     74        protected function get_view_sql_where( $view ) {
     75                switch ( $view ) {
     76                        case 'pending':
     77                                return 'created = 0 AND cleared = 1';
     78                        case 'spam':
     79                                return 'cleared = 0';
     80                        case 'akismet':
     81                                return "meta LIKE '%akismet_result\":\"spam%'";
     82                        case 'registered':
     83                                return 'created = 1';
     84                        default:
     85                        case 'all':
     86                                return '1=1';
     87                }
     88        }
     89
     90        protected function get_where_sql( $view = null ) {
     91                global $wpdb;
     92
     93                $where = $this->get_view_sql_where( $view ?: ( $_REQUEST['view'] ?? 'all' ) );
     94
     95                if ( isset( $_GET['s'] ) && 'all' != $view ) {
     96                         $search_like = '%' . $wpdb->esc_like( wp_unslash( $_GET['s'] ) ) . '%';
     97                         $where .= $wpdb->prepare(
     98                                 " AND ( user_login LIKE %s OR user_email LIKE %s OR meta LIKE %s )",
     99                                 $search_like, $search_like, $search_like
     100                        );
     101                }
     102
     103                return $where;
     104        }
    4105
    5106        function get_columns() {
    6107                return [
    7                         'pending_id'      => 'ID',
    8                         'created'         => 'Created',
    9108                        'user_login'      => 'User Login',
    10                         'user_email'      => 'User Email',
    11                         'user_ip'         => 'IP',
    12                         'scores'          => 'reCaptcha',
    13                         'akismet'         => 'Akismet',
    14                         'user_registered' => 'Registered Date',
    15                         'created_date'    => 'Created Date',
     109                        'meta'            => 'Meta',
     110                        'scores'          => 'Anti-spam<br>reCaptcha Akismet',
     111                        'user_registered' => 'Registered',
    16112                ];
    17113         }
     
    19115         public function get_sortable_columns() {
    20116                return [
    21                         'pending_id'      => array( 'pending_id', false ),
    22                         'created'         => array( 'created', true ),
    23117                        'user_login'      => array( 'user_login', true ),
    24                         'user_email'      => array( 'user_email', true ),
    25118                        'scores'          => array( 'scores', true ),
    26                         'akismet'         => array( 'akismet', true ),
    27119                        'user_registered' => array( 'user_registered', true ),
    28                         'created_date'    => array( 'created_date', true ),
    29120                ];
    30121         }
     
    52143           $current_page = $this->get_pagenum();
    53144
    54            $where = '1 = 1 ';
    55            if ( isset( $_GET['s'] ) ) {
    56                         $search_like = '%' . $wpdb->esc_like( $_GET['s'] ) . '%';
    57                         $where .= $wpdb->prepare(
    58                                 "AND ( user_login LIKE %s OR user_email LIKE %s OR meta LIKE %s )",
    59                                 $search_like, $search_like, $search_like
    60                    );
    61            }
     145           $where = $this->get_where_sql();
    62146
    63147           $per_page_offset = ($current_page-1) * $per_page;
     
    82166        }
    83167
    84         function column_created( $item ) {
    85                 echo ( $item->created ? 'Yes' : 'No' );
    86 
    87                 if ( ! $item->created ) {
    88                         $url = add_query_arg(
    89                                 'email',
    90                                 urlencode( $item->user_email ),
    91                                 admin_url( 'admin-post.php?action=login_resend_email' )
    92                         );
    93                         $url = wp_nonce_url( $url, 'resend_' . $item->user_email );
    94                         echo $this->row_actions( [
    95                                 'resend' => '<a href="' . esc_url( $url ) . '">Resend Email</a>',
    96                         ] );
    97                 }
    98         }
    99 
    100168        function column_user_registered( $item ) {
    101169                printf(
     
    104172                        human_time_diff( strtotime( $item->user_registered ) )
    105173                );
    106         }
    107 
    108         function column_created_date( $item ) {
     174
    109175                if ( $item->created_date && '0000-00-00 00:00:00' !== $item->created_date ) {
    110176                        printf(
    111                                 '<abbr title="%s">%s ago</abbr>',
     177                                '<br>Created: <abbr title="%s">%s ago</abbr>',
    112178                                esc_attr( $item->created_date ),
    113179                                human_time_diff( strtotime( $item->created_date ) )
    114180                        );
    115                 } else {
    116                         echo '&nbsp;';
    117181                }
    118182        }
     
    122186                        $url = esc_url( 'https://profiles.wordpress.org/' . $item->user_login . '/' );
    123187                        echo "<a href='$url'>" . esc_html( $item->user_login ) . '</a>';
     188
     189                        if (
     190                                ( $user = get_user_by( 'login', $item->user_login ) ) &&
     191                                'BLOCKED' === substr( $user->user_pass, 0, 7 )
     192                        ) {
     193                                echo ' <span class="delete-red">(blocked)</span>';
     194                        }
     195
    124196                } else {
    125197                        echo esc_html( $item->user_login );
    126198                }
    127         }
    128 
    129         function column_user_email( $item ) {
     199
     200                echo '<hr>';
     201
    130202                list( $email_user, $domain ) = explode( '@', $item->user_email, 2 );
    131203
     
    136208                        esc_html( $domain )
    137209                );
    138         }
    139 
    140 
    141         function column_user_ip( $item ) {
     210
     211                $row_actions = [];
     212
     213                if ( ! $item->created && $item->cleared ) {
     214                        $url = add_query_arg(
     215                                'email',
     216                                urlencode( $item->user_email ),
     217                                admin_url( 'admin-post.php?action=login_resend_email' )
     218                        );
     219                        $url = wp_nonce_url( $url, 'resend_' . $item->user_email );
     220
     221                        $row_actions['resend'] = '<a href="' . esc_url( $url ) . '">Resend Email</a>';
     222                }
     223
     224                if ( ! $item->created ) {
     225                        if ( $item->user_activation_key ) {
     226                                $url = add_query_arg(
     227                                        'email',
     228                                        urlencode( $item->user_email ),
     229                                        admin_url( 'admin-post.php?action=login_block' )
     230                                );
     231                                $url = wp_nonce_url( $url, 'block_' . $item->user_email );
     232       
     233                                $row_actions['block'] = '<a href="' . esc_url( $url ) . '">Block Registration</a>';
     234                        }
     235
     236                        $url = add_query_arg(
     237                                'email',
     238                                urlencode( $item->user_email ),
     239                                admin_url( 'admin-post.php?action=login_delete' )
     240                        );
     241                        $url = wp_nonce_url( $url, 'delete_' . $item->user_email );
     242
     243                        $row_actions['delete'] = '<a href="' . esc_url( $url ) . '">Delete</a>';
     244
     245                } else {
     246                        $url = add_query_arg(
     247                                'email',
     248                                urlencode( $item->user_email ),
     249                                admin_url( 'admin-post.php?action=login_block_account' )
     250                        );
     251                        $url = wp_nonce_url( $url, 'block_account_' . $item->user_email );
     252
     253                        if (
     254                                ! ( $user = get_user_by( 'login', $item->user_login ) ) ||
     255                                'BLOCKED' !== substr( $user->user_pass, 0, 7 )
     256                        ) {
     257                                $row_actions['block-account'] = '<a href="' . esc_url( $url ) . '">Block Account</a>';
     258                        }
     259
     260                }
     261
     262                if ( $row_actions ) {
     263                        echo $this->row_actions( $row_actions );
     264                }
     265
     266        }
     267
     268
     269        function column_meta( $item ) {
    142270                $meta = json_decode( $item->meta );
    143271
     
    158286                        )
    159287                );
     288                echo '<hr>';
     289
     290                foreach ( [ 'url', 'from', 'occ', 'interests' ] as $field ) {
     291                        if ( !empty( $meta->$field ) ) {
     292                                printf( "%s: %s<br>", esc_html( $field ), esc_html( $meta->$field ) );
     293                        }
     294                }
    160295        }
    161296
    162297        function column_scores( $item ) {
     298
     299                echo ( $item->cleared ? 'Passed' : 'Failed' ) . '<br>';
     300
    163301                foreach ( json_decode( $item->scores ) as $type => $val ) {
    164302                        printf(
     
    168306                        );
    169307                }
    170         }
    171 
    172         function column_akismet( $item ) {
    173                 $meta = json_decode( $item->meta, true );
    174 
    175                 echo $meta['akismet_result'] ?? '';
     308
     309                $meta    = json_decode( $item->meta );
     310                $akismet = $meta->akismet_result ?? '';
     311                if ( $akismet ) {
     312                        printf(
     313                                '<abbr title="%s">%s</abbr> ',
     314                                esc_attr( 'Akismet' ),
     315                                esc_html( strtolower( $akismet ) )
     316                        );
     317                }
     318
     319                $row_actions = [];
     320
     321                if ( ! $item->created && $item->user_activation_key ) {
     322                        $url = add_query_arg(
     323                                'email',
     324                                urlencode( $item->user_email ),
     325                                admin_url( 'admin-post.php?action=login_block' )
     326                        );
     327                        $url = wp_nonce_url( $url, 'block_' . $item->user_email );
     328
     329                        $row_actions['block'] = '<a href="' . esc_url( $url ) . '">Block Registration</a>';
     330                }
     331
     332                if ( ! $item->cleared ) {
     333                        $url = add_query_arg(
     334                                'email',
     335                                urlencode( $item->user_email ),
     336                                admin_url( 'admin-post.php?action=login_mark_as_cleared' )
     337                        );
     338                        $url = wp_nonce_url( $url, 'clear_' . $item->user_email );
     339                        $row_actions['approve-reg'] = '<a href="' . esc_url( $url ) . '">Approve</a>';
     340                }
     341
     342                if ( $row_actions ) {
     343                        echo $this->row_actions( $row_actions );
     344                }
    176345        }
    177346
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/admin/ui.php

    r10029 r10928  
    1313});
    1414
     15function wporg_login_admin_action_text( $action ) {
     16        switch ( $action ) {
     17                case 'resent-email':
     18                        return 'The registration email has been resent.';
     19                case 'approved':
     20                        return 'The registration has been approved, and a confirmation email has been sent.';
     21                case 'deleted':
     22                        return 'The registration record has been removed.';
     23                case 'blocked':
     24                        return 'The registration has been blocked.';
     25                case 'blocked_account':
     26                        return 'Account blocked.';
     27                default:
     28                        return 'Action performed.';
     29        }
     30}
     31
    1532function wporg_login_admin_page() {
    1633        $wp_list_table = new User_Registrations_List_Table();
    1734        $wp_list_table->prepare_items();
    1835
    19         echo '<style>
     36        ?><script>
     37        jQuery( document ).ready( function($) {
     38                $( 'table .row-actions a' ).click( function( e ) {
     39                        e.preventDefault();
     40
     41                        var $this = $(this),
     42                                $tr   = $this.parents('tr'),
     43                                $tds  = $tr.find( 'td:not(:first)' );
     44
     45                        $tds.remove();
     46                        $tr.find( '.row-actions' ).remove();
     47                        $tr.append( "<td colspan=" + $tds.length + ">...</td>" );
     48
     49                        var url = $this.prop('href') + '&ajax=1';
     50
     51                        $.get( url, function( data ) {
     52                                $tr.find('td:last').text( data );
     53                        } );
     54                });
     55        } );
     56        </script>
     57        <style>
    2058                table.dashboard_page_user-registrations td > a {
    2159                        color: inherit;
     
    2462                        text-decoration: underline;
    2563                }
    26         </style>';
     64                table.dashboard_page_user-registrations .delete-red {
     65                        color: #b32d2e;
     66                }
     67        </style>
     68        <?php
    2769
    2870        echo '<div class="wrap">';
     
    3072        echo '<hr class="wp-header-end">';
    3173
    32         if ( isset( $_REQUEST['resent-email'] ) ) {
    33                 echo '<div class="updated notice"><p>The registration email has been resent.</p></div>';
     74        if ( isset( $_GET['action'] ) ) {
     75                echo '<div class="updated notice"><p>';
     76                echo wporg_login_admin_action_text( $_GET['action'] );
     77                echo '</p></div>';
    3478        }
    3579
     
    3781        printf( '<input type="hidden" name="page" value="%s">', esc_attr( $_GET['page'] ) );
    3882
    39         //$wp_list_table->views();
     83        $wp_list_table->views();
    4084        $wp_list_table->search_box( 'Search', 's' );
    4185        $wp_list_table->display();
     
    58102        }
    59103
    60         wp_safe_redirect( add_query_arg(
    61                 's',
    62                 urlencode( $email ),
    63                 'https://login.wordpress.org/wp-admin/index.php?page=user-registrations&resent-email=true'
    64         ) );
    65         exit;
    66 });
     104        if ( isset( $_GET['ajax'] ) ) {
     105                die( wporg_login_admin_action_text( 'resent-email' ) );
     106        }
     107
     108        wp_safe_redirect( add_query_arg(
     109                's',
     110                urlencode( $email ),
     111                'https://login.wordpress.org/wp-admin/index.php?page=user-registrations&action=resent-email'
     112        ) );
     113        exit;
     114} );
     115
     116add_action( 'admin_post_login_mark_as_cleared', function() {
     117        if ( ! current_user_can( 'manage_users' ) ) {
     118                wp_die();
     119        }
     120
     121        $email = $_REQUEST['email'] ?? '';
     122
     123        check_admin_referer( 'clear_' . $email );
     124
     125        $user = wporg_get_pending_user( $email );
     126        if ( $user ) {
     127                $user['cleared'] = 2;
     128                wporg_update_pending_user( $user );
     129
     130                wporg_login_send_confirmation_email( $user['user_email'] );
     131        }
     132
     133        if ( isset( $_GET['ajax'] ) ) {
     134                die( wporg_login_admin_action_text( 'approved' ) );
     135        }
     136
     137        wp_safe_redirect( add_query_arg(
     138                's',
     139                urlencode( $email ),
     140                'https://login.wordpress.org/wp-admin/index.php?page=user-registrations&action=approved'
     141        ) );
     142        exit;
     143} );
     144
     145add_action( 'admin_post_login_block', function() {
     146        if ( ! current_user_can( 'manage_users' ) ) {
     147                wp_die();
     148        }
     149
     150        $email = $_REQUEST['email'] ?? '';
     151
     152        check_admin_referer( 'block_' . $email );
     153
     154        $user = wporg_get_pending_user( $email );
     155        if ( $user ) {
     156                $user['cleared']             = 0;
     157                $user['user_activation_key'] = '';
     158                $user['user_profile_key']    = '';
     159
     160                wporg_update_pending_user( $user );
     161        }
     162
     163        if ( isset( $_GET['ajax'] ) ) {
     164                die( wporg_login_admin_action_text( 'blocked' ) );
     165        }
     166
     167        wp_safe_redirect( add_query_arg(
     168                's',
     169                urlencode( $email ),
     170                'https://login.wordpress.org/wp-admin/index.php?page=user-registrations&action=blocked'
     171        ) );
     172        exit;
     173} );
     174
     175add_action( 'admin_post_login_delete', function() {
     176        if ( ! current_user_can( 'manage_users' ) ) {
     177                wp_die();
     178        }
     179
     180        $email = $_REQUEST['email'] ?? '';
     181
     182        check_admin_referer( 'delete_' . $email );
     183
     184        $user = wporg_get_pending_user( $email );
     185        if ( $user ) {
     186                wporg_delete_pending_user( $user );
     187        }
     188
     189        if ( isset( $_GET['ajax'] ) ) {
     190                die( wporg_login_admin_action_text( 'deleted' ) );
     191        }
     192
     193        wp_safe_redirect( add_query_arg(
     194                's',
     195                urlencode( $email ),
     196                'https://login.wordpress.org/wp-admin/index.php?page=user-registrations&action=deleted'
     197        ) );
     198        exit;
     199} );
     200
     201add_action( 'admin_post_login_block_account', function() {
     202        if ( ! current_user_can( 'manage_users' ) ) {
     203                wp_die();
     204        }
     205
     206        $email = $_REQUEST['email'] ?? '';
     207
     208        check_admin_referer( 'block_account_' . $email );
     209
     210        $user = get_user_by( 'email', $email );
     211        if ( $user && defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
     212                // Load the support forums..
     213                include_once WP_PLUGIN_DIR . '/bbpress/bbpress.php';
     214                include_once WP_PLUGIN_DIR . '/support-forums/support-forums.php';
     215
     216                // Then switch to it (Must be done after bbPress is loaded to get roles)
     217                switch_to_blog( WPORG_SUPPORT_FORUMS_BLOGID );
     218
     219                // Set the user to blocked. Support forum hooks will take care of the rest.
     220                bbp_set_user_role( $user->ID, bbp_get_blocked_role() );
     221
     222                restore_current_blog();
     223        }
     224
     225        if ( isset( $_GET['ajax'] ) ) {
     226                die( wporg_login_admin_action_text( 'blocked_account' ) );
     227        }
     228
     229        wp_safe_redirect( add_query_arg(
     230                's',
     231                urlencode( $email ),
     232                'https://login.wordpress.org/wp-admin/index.php?page=user-registrations&action=blocked_account'
     233        ) );
     234        exit;
     235} );
     236
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions-registration.php

    r10902 r10928  
    11<?php
    22
    3 function wporg_login_check_recapcha_status( $check_v3_action = false ) {
     3function wporg_login_check_recapcha_status( $check_v3_action = false, $block_low_scores = true ) {
    44
    55        // reCaptcha V3 Checks
     
    2222
    2323                // Block super-low scores.
    24                 if ( (float)$result['score'] < (float) get_option( 'recaptcha_v3_threshold', 0.2 ) ) {
     24                if ( $block_low_scores && (float)$result['score'] < (float) get_option( 'recaptcha_v3_threshold', 0.2 ) ) {
    2525                        return false;
    2626                }
     
    122122        }
    123123
     124        $pending_user['meta']['akismet_result'] = wporg_login_check_akismet( $user_login, $user_email );
     125
     126        $pending_user['cleared'] = (
     127                'spam' !== $pending_user['meta']['akismet_result'] &&
     128                (float)$pending_user['scores']['pending'] >= (float) get_option( 'recaptcha_v3_threshold', 0.2 )
     129        );
     130
    124131        $inserted = wporg_update_pending_user( $pending_user );
    125132        if ( ! $inserted ) {
     
    147154        $user = wporg_get_pending_user( $user );
    148155
    149         if ( ! $user || $user['created'] ) {
     156        if ( ! $user || $user['created'] || ! $user['cleared'] ) {
    150157                return false;
    151158        }
     
    230237        }
    231238
     239}
     240
     241function wporg_delete_pending_user( $pending_user ) {
     242        global $wpdb;
     243
     244        if ( empty( $pending_user['pending_id'] ) ) {
     245                return false;
     246        }
     247
     248        return $wpdb->delete(
     249                "{$wpdb->base_prefix}user_pending_registrations",
     250                array( 'pending_id' => $pending_user['pending_id'] )
     251        );
    232252}
    233253
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions-restapi.php

    r10295 r10928  
    122122
    123123        $pending_user = wporg_get_pending_user( $request['account'] );
    124         if ( ! $pending_user || $pending_user['created'] ) {
     124        if ( ! $pending_user || $pending_user['created'] || ! $pending_user['user_activation_key'] ) {
    125125                return $success_message;
    126126        }
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/pending-create.php

    r10901 r10928  
    66 */
    77
    8 // Clear the pending cookies, they're no longer needed.
    9 if ( isset( $_COOKIE['wporg_profile_user'] ) ) {
    10         setcookie( 'wporg_profile_user', false, time()-DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
    11         setcookie( 'wporg_profile_key', false,  time()-DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
    12 }
     8$sso = WPOrg_SSO::get_instance();
    139
    1410// Migrate to cookies.
    15 if ( !empty( WP_WPOrg_SSO::$matched_route_params['confirm_user'] ) ) {
    16         setcookie( 'wporg_confirm_user', WP_WPOrg_SSO::$matched_route_params['confirm_user'], time()+DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
    17         setcookie( 'wporg_confirm_key',  WP_WPOrg_SSO::$matched_route_params['confirm_key'],  time()+DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
     11if ( !empty( $sso::$matched_route_params['confirm_user'] ) ) {
     12        setcookie( 'wporg_confirm_user', $sso::$matched_route_params['confirm_user'], time()+DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
     13        setcookie( 'wporg_confirm_key',  $sso::$matched_route_params['confirm_key'],  time()+DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
    1814
    1915        wp_safe_redirect( '/register/create' );
     
    6056}
    6157
    62 
    63 $error_recapcha_status = $error_akismet = false;
    64 if ( isset( $_POST['user_pass'] ) ) {
     58$error_recapcha_status = false;
     59if ( isset( $_POST['user_pass'] ) && 2 !== $pending_user['cleared'] ) {
    6560
    6661        // Check reCaptcha status
    67         if ( ! wporg_login_check_recapcha_status( 'pending_create' ) ) {
    68                 // No no. "Please try again."
     62        if ( ! wporg_login_check_recapcha_status( 'pending_create', false ) ) {
     63                unset( $_POST['user_pass'] );
    6964                $error_recapcha_status = true;
    70                 unset( $_POST['user_pass'] );
    71         }
    72 
    73         // Check Akismet
    74         $akismet = wporg_login_check_akismet(
     65
     66                // Allow a recaptcha fail to try again, but if they're blocked due to low score, mark them as needing approval.
     67                if ( ! wporg_login_check_recapcha_status( 'pending_create', true ) ) {
     68                        $pending_user['cleared'] = 0;
     69                }
     70
     71                // Store for reference.
     72                if ( isset( $_POST['_reCaptcha_v3_token'] ) ) {
     73                        $recaptcha_api = wporg_login_recaptcha_api(
     74                                $_POST['_reCaptcha_v3_token'],
     75                                RECAPTCHA_V3_PRIVKEY
     76                        );
     77                        $pending_user['scores']['create_attempt'] = -1;
     78                        if ( $recaptcha_api && $recaptcha_api['success'] && 'pending_create' == $recaptcha_api['action'] ) {
     79                                $pending_user['scores']['create_attempt'] = $recaptcha_api['score'];
     80                        }
     81                }
     82        }
     83
     84        // Check Akismet with new profile information
     85        $pending_user['meta']['akismet_result'] = wporg_login_check_akismet(
    7586                $pending_user['user_login'],
    7687                $pending_user['user_email'],
     
    8394        );
    8495
    85         // Store for reference.
    86         $pending_user['meta']['akismet_result'] = $akismet;
     96        if ( 'spam' === $pending_user['meta']['akismet_result'] ) {
     97                $pending_user['cleared'] = 0;
     98                unset( $_POST['user_pass'] );
     99        }
     100
    87101        wporg_update_pending_user( $pending_user );
    88 
    89         if ( 'spam' == $akismet ) {
    90                 // No no. "Please try again."
    91                 $error_akismet = true;
    92                 unset( $_POST['user_pass'] );
    93         }
    94 
     102}
     103
     104if ( ! $pending_user['cleared'] ) {
     105        if ( ! empty( $_COOKIE['wporg_profile_user'] ) ) {
     106                // Throw the user back to the pending screen after being detected as spam at this point.
     107                wp_safe_redirect( '/register/create-profile/' );
     108                die();
     109        }
     110
     111        unset( $_POST['user_pass'] );
    95112}
    96113
     
    101118                $user = wporg_login_create_user_from_pending( $pending_user, $user_pass );
    102119                if ( $user ) {
     120
     121                        // Clear the cookies, they're no longer needed.
     122                        setcookie( 'wporg_profile_user', false, time()-DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
     123                        setcookie( 'wporg_profile_key',  false, time()-DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
    103124                        setcookie( 'wporg_confirm_user', false, time()-DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
    104125                        setcookie( 'wporg_confirm_key',  false, time()-DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
     
    121142?>
    122143
    123 <p class="intro">
    124 <?php _e( 'Set your password and complete your WordPress.org Profile information.', 'wporg' ); ?>
    125 </p>
    126 
    127144<form name="registerform" id="registerform" action="" method="post">
    128145
    129                 <p class="login-login">
    130                         <label for="user_login"><?php _e( 'Username', 'wporg' ); ?></label>
    131                         <input type="text" disabled="disabled" class=" disabled" value="<?php echo esc_attr( $activation_user ); ?>" size="20" />
    132                 </p>
    133 
    134                 <div class="user-pass1-wrap">
     146        <?php if ( ! $pending_user['cleared'] ) { ?>
     147        <div class="message info">
     148                <p><?php
     149                        printf(
     150                                /* translators: %s Email address */
     151                                __( 'Your account is pending approval. You will receive an email at %s to set your password when approved.', 'wporg' ) . '<br>' .
     152                                __( 'Please contact %s for more details.', 'wporg' ),
     153                                '<code>' . esc_html( $pending_user['user_email'] ) . '</code>',
     154                                '<a href="mailto:' . $sso::SUPPORT_EMAIL . '">' . $sso::SUPPORT_EMAIL . '</a>'
     155                        );
     156                ?></p>
     157        </div>
     158        <?php } ?>
     159
     160        <p class="intro">
     161                <?php _e( 'Set your password and complete your WordPress.org Profile information.', 'wporg' ); ?>
     162        </p>
     163
     164        <p class="login-login">
     165                <label for="user_login"><?php _e( 'Username', 'wporg' ); ?></label>
     166                <input type="text" disabled="disabled" class=" disabled" value="<?php echo esc_attr( $activation_user ); ?>" size="20" />
     167        </p>
     168
     169        <div class="user-pass1-wrap">
    135170                <p>
    136171                        <label for="pass1"><?php _e( 'Password', 'wporg' ); ?></label>
     
    145180        </div>
    146181
    147 <!--    <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> -->
    148 
    149182        <?php
    150183                $fields = &$pending_user['meta'];
    151184                include __DIR__ . '/partials/register-profilefields.php';
    152185        ?>
     186
    153187        <?php
    154                 if ( $error_recapcha_status || $error_akismet ) {
     188                if ( $error_recapcha_status ) {
    155189                        echo '<div class="message error"><p>' . __( 'Please try again.', 'wporg' ) . '</p></div>';
    156190                }
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/pending-profile.php

    r10898 r10928  
    66 */
    77
     8$sso = WPOrg_SSO::get_instance();
     9
    810 // Migrate to cookies.
    9 if ( !empty( WP_WPOrg_SSO::$matched_route_params['profile_user'] ) ) {
    10         setcookie( 'wporg_profile_user', WP_WPOrg_SSO::$matched_route_params['profile_user'], time()+DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
    11         setcookie( 'wporg_profile_key',  WP_WPOrg_SSO::$matched_route_params['profile_key'],  time()+DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
     11if ( !empty( $sso::$matched_route_params['profile_user'] ) ) {
     12        setcookie( 'wporg_profile_user', $sso::$matched_route_params['profile_user'], time()+DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
     13        setcookie( 'wporg_profile_key',  $sso::$matched_route_params['profile_key'],  time()+DAY_IN_SECONDS, '/register/', 'login.wordpress.org', true, true );
    1214
    1315        wp_safe_redirect( '/register/create-profile' );
     
    5456        <div class="message info">
    5557                <p><?php
     58                if ( $pending_user['cleared'] ) {
    5659                        printf(
    5760                                /* translators: %s Email address */
     
    6164                                esc_attr( $pending_user['user_email'] )
    6265                        );
     66                } else {
     67                        printf(
     68                                /* 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' ),
     71                                '<code>' . esc_html( $pending_user['user_email'] ) . '</code>',
     72                                '<a href="mailto:' . $sso::SUPPORT_EMAIL . '">' . $sso::SUPPORT_EMAIL . '</a>'
     73                        );
     74                }
    6375                ?></p>
    6476        </div>
    6577
    6678        <p class="intro">
    67         <?php _e( 'Complete your WordPress.org Profile information.', 'wporg' ); ?>
     79                <?php _e( 'Complete your WordPress.org Profile information.', 'wporg' ); ?>
    6880        </p>
    6981
     
    7284                <input type="text" disabled="disabled" class=" disabled" value="<?php echo esc_attr( $profile_user ); ?>" size="20" />
    7385        </p>
    74 
    7586
    7687        <?php
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/register.php

    r10904 r10928  
    1515}
    1616
    17 $error_user_login = $error_user_email = $error_recapcha_status = $error_akismet = $terms_of_service_error = false;
     17$error_user_login = $error_user_email = $error_recapcha_status = $terms_of_service_error = false;
    1818if ( $_POST ) {
    1919
     
    3434        // handle user registrations.
    3535        if ( ! $error_user_login && ! $error_user_email && ! $terms_of_service_error ) {
    36                 if ( ! wporg_login_check_recapcha_status( 'register' ) ) {
     36
     37                $recaptcha = wporg_login_check_recapcha_status( 'register', false /* Allow low scores to pass through */ );
     38
     39                if ( ! $recaptcha ) {
    3740                        $error_recapcha_status = true;
    3841                } else {
    39                         $akismet = wporg_login_check_akismet( $user_login, $user_email );
    40 
    4142                        $tos_meta_key = WPOrg_SSO::TOS_USER_META_KEY;
    4243                        $meta = [
    4344                                'user_mailinglist' => $user_mailinglist,
    44                                 'akismet_result'   => $akismet,
    4545                                $tos_meta_key      => $terms_of_service,
    4646                        ];
    4747
    48                         if ( 'spam' === $akismet ) {
    49                                 $error_akismet = true;
    50                         } else {
    51                                 wporg_login_create_pending_user( $user_login, $user_email, $meta );
    52                                 die();
    53                         }
     48                        wporg_login_create_pending_user( $user_login, $user_email, $meta );
     49                        die();
    5450                }
    5551        }
     
    123119        </p>
    124120        <?php
    125                 if ( $error_recapcha_status || $error_akismet ) {
     121                if ( $error_recapcha_status ) {
    126122                        echo '<div class="message error"><p>' . __( 'Please try again.', 'wporg' ) . '</p></div>';
    127123                }
Note: See TracChangeset for help on using the changeset viewer.