Making WordPress.org

Changeset 4470


Ignore:
Timestamp:
12/04/2016 05:54:55 PM (8 years ago)
Author:
dd32
Message:

Login.WordPress.org: Allow user registration through login.wordpress.org

This change does many things, including, but not limited to:

  • Making all the routes have proper templates, rather than being template-parts
  • Removing all the extra WordPress functionalities and outputs
  • Adding the Registration pages and routes
  • Updating SSO to handle routes with URL params
  • Adding rest endpoints for username/email validation

See #148, #1524

Location:
sites/trunk
Files:
14 added
7 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/common/includes/wporg-sso/wp-plugin.php

    r4413 r4470  
    2222            'lostpassword' => '/lostpassword',
    2323            'oauth'        => '/oauth',
     24            'register-profile' => '/register/profile/(?P<profile_user>[^/]+)/(?P<profile_nonce>[^/]+)',
     25            'register-confirm' => '/register/confirm/(?P<confirm_user>[^/]+)/(?P<confirm_key>[^/]+)',
     26            'register'         => '/register',
    2427        );
     28
     29        /**
     30         * Holds the route hit in `valid_sso_paths`
     31         * @var bool|string
     32         */
     33        static $matched_route = false;
     34
     35        /**
     36         * Holds any matched route params.
     37         * @var array
     38         */
     39        static $matched_route_params = array();
    2540
    2641        /**
     
    7085         */
    7186        public function disable_password_reset_for_blocked_users( $allow, $user_id ) {
    72             if ( ! defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
     87            if ( ! $allow || ! defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
    7388                return $allow;
    7489            }
     
    7691            $user = new WP_User( $user_id, '', WPORG_SUPPORT_FORUMS_BLOGID );
    7792            $is_blocked = ! empty( $user->allcaps['bbp_blocked'] );
     93
    7894            return ! $is_blocked;
    7995        }
     
    150166                if ( ! preg_match( '!/wp-login\.php$!', $this->script ) ) {
    151167                    // ... but not on its login screen.
    152                     if ( preg_match( '!^(' . implode( '|', $this->valid_sso_paths ) . ')([/?]{1,2}.*)?$!', $_SERVER['REQUEST_URI'] ) ) {
    153                         // If we're on the path of interest
    154 
     168                    self::$matched_route = false;
     169                    self::$matched_route_params = array();
     170                    foreach ( $this->valid_sso_paths as $route => $regex ) {
     171                        if ( preg_match( '!^' . $regex . '(?:[/?]{1,2}.*)?$!', $_SERVER['REQUEST_URI'], $matches ) ) {
     172                            self::$matched_route = $route;
     173                            self::$matched_route_params = $matches;
     174                            break;
     175                        }
     176                    }
     177
     178                    // If we're on the path of interest
     179                    if ( self::$matched_route ) {
    155180                        // Add a custom filter others can apply (theme, etc).
    156181                        add_filter( 'is_valid_wporg_sso_path' , '__return_true' );
     
    187212                            }
    188213                        }
     214                    } elseif ( ( is_admin() && is_super_admin() ) || preg_match( '!^/wp-json(/?$|/.+)!i', $_SERVER['REQUEST_URI'] ) ) {
     215                        // Do nothing, allow access to wp-admin and wp-json on login.wordpress.org
    189216                    } elseif ( is_user_logged_in() ) {
    190217                        // Logged in catch all, before last fallback
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions.php

    r4417 r4470  
    55 * @package wporg-login
    66 */
     7
     8require __DIR__ . '/functions-restapi.php';
     9require __DIR__ . '/functions-registration.php';
    710
    811/**
     
    2629 */
    2730function wporg_login_body_class( $classes ) {
    28 //  $classes[] = 'wporg-responsive';
    29     $classes[] = 'wporg-login';
     31    if ( WP_WPOrg_SSO::$matched_route ) {
     32        $classes[] = 'route-' . WP_WPOrg_SSO::$matched_route;
     33    }
     34
     35    // Remove the 404 class..
     36    if ( false !== ( $pos = array_search( 'error404', $classes ) ) ) {
     37        unset( $classes[ $pos ] );
     38    }
    3039    return $classes;
    3140}
     
    4453 */
    4554function wporg_login_replace_css() {
    46     wp_enqueue_style( 'wporg-login', get_template_directory_uri() . '/stylesheets/login.css', array( 'login', 'dashicons', 'l10n' ), 2.3 );
     55    wp_enqueue_style( 'wporg-login', get_template_directory_uri() . '/stylesheets/login.css', array( 'login', 'dashicons', 'l10n' ), '20161204' );
    4756}
    4857add_action( 'login_init', 'wporg_login_replace_css' );
     
    5362function wporg_login_scripts() {
    5463    $script_debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
    55     $suffix       = $script_debug ? '' : '.min';
    5664
    5765    // Concatenates core scripts when possible.
     
    6169
    6270    wp_enqueue_style( 'wporg-normalize', get_template_directory_uri() . '/stylesheets/normalize.css', 3 );
    63     wp_enqueue_style( 'wporg-login', get_template_directory_uri() . '/stylesheets/login.css', array( 'login', 'dashicons', 'l10n' ), 2.3 );
    64 
    65     // No emoji support needed.
    66     remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
    67     remove_action( 'wp_print_styles', 'print_emoji_styles' );
    68 
    69     // No Jetpack styles needed.
    70     add_filter( 'jetpack_implode_frontend_css', '__return_false' );
    71 
    72     // No embeds needed.
    73     remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
    74     remove_action( 'wp_head', 'wp_oembed_add_host_js' );
     71    wp_enqueue_style( 'wporg-login', get_template_directory_uri() . '/stylesheets/login.css', array( 'login', 'dashicons', 'l10n' ), '20161204' );
    7572}
    7673add_action( 'wp_enqueue_scripts', 'wporg_login_scripts' );
     74
     75function wporg_login_register_scripts() {
     76    wp_register_script( 'recaptcha-api', 'https://www.google.com/recaptcha/api.js', array(), '2' );
     77
     78    wp_register_script( 'wporg-registration', get_template_directory_uri() . "/js/registration.js", array( 'recaptcha-api', 'jquery' ), '20161114' );
     79    wp_localize_script( 'wporg-registration', 'wporg_registration', array(
     80        'rest_url' => esc_url_raw( rest_url( "wporg/v1" ) )
     81    ) );
     82}
     83add_action( 'init', 'wporg_login_register_scripts' );
     84
     85/**
     86 * Avoid sending a 404 header but send a 200 with nocache headers.
     87 */
     88function wporg_login_pre_handle_404( $false, $wp_query ) {
     89    $wp_query->set_404(); // Set the query as 404 to avoid things running thinking it's a real page
     90    status_header( 200 ); // but return a 200
     91    return true;
     92}
     93add_filter( 'pre_handle_404', 'wporg_login_pre_handle_404', 10, 2 );
     94
     95/**
     96 * Filters the page template to load wporg-login/$route.php.
     97 *
     98 * @param array $templates The templates WordPress intends to load.
     99 * @return array The templates the theme intends to use.
     100 */
     101function wporg_login_filter_templates( $templates ) {
     102    $route = WP_WPOrg_SSO::$matched_route;
     103
     104    if ( ! $route || 'root' === $route ) {
     105        $route = 'login';
     106    }
     107
     108    return array( "{$route}.php", 'index.php' );
     109}
     110add_filter( 'index_template_hierarchy', 'wporg_login_filter_templates' );
     111
     112// No emoji support needed.
     113remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
     114remove_action( 'wp_print_styles', 'print_emoji_styles' );
     115
     116// No Jetpack styles needed.
     117add_filter( 'jetpack_implode_frontend_css', '__return_false' );
     118
     119// No embeds needed.
     120remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
     121remove_action( 'wp_head', 'wp_oembed_add_host_js' );
     122remove_action( 'rest_api_init', 'wp_oembed_register_route' );
     123
     124// Don't perform any WP_Query queries on this site..
     125add_filter( 'posts_request', '__return_empty_string' );
     126// Don't attempt to do canonical lookups..
     127remove_filter( 'template_redirect', 'redirect_canonical' );
     128// There's no need to edit the site..
     129remove_action( 'wp_head', 'wlwmanifest_link' );
     130remove_action( 'wp_head', 'rsd_link' );
     131// We don't need all the rest routes either..
     132remove_action( 'rest_api_init', 'create_initial_rest_routes', 99 );
     133
     134// Don't need all the wp-admin specific user metas on user create/update
     135add_filter( 'insert_user_meta', '__return_empty_array', 1 );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/header.php

    r2492 r4470  
    1616<?php wp_head(); ?>
    1717</head>
    18 <body class="wp-core-ui login">
     18<body <?php body_class( 'wp-core-ui login' ); ?>>
    1919
    2020<div id="login">
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/index.php

    r4119 r4470  
    66 */
    77
    8 get_header();
     8// Silence is Golden. If we're at this point, then no template exists for the given request yet.
     9wp_safe_redirect( '/' );
    910
    10 /**
    11  * Test if the path we're on is one that we use, depending on if it
    12  * has a partial or not, or load the 404 partial as fallback.
    13  *
    14  * Note that the path is first validated in WP_WPOrg_SSO::redirect_all_login_or_signup_to_sso().
    15  * @see https://meta.trac.wordpress.org/browser/sites/trunk/common/includes/wporg-sso/wp-plugin.php
    16  */
    17 
    18 if ( apply_filters( 'is_valid_wporg_sso_path', false ) && preg_match( '!^(/[^/\?]*)([/\?]{1,2}.*)?$!', $_SERVER['REQUEST_URI'], $matches ) ) {
    19     $screen = '/' === $matches[1] ? 'login' : preg_replace( '/[^a-z0-9-]/', '', $matches[1] );
    20 } else {
    21     $screen = '404';
    22 }
    23 
    24 $partials_dir = __DIR__ . '/partials/';
    25 $partial      = $partials_dir . $screen . '.php';
    26 
    27 if ( file_exists( $partial ) ) {
    28     if ( ! headers_sent() ) {
    29         status_header( 200 );
    30     }
    31     require_once( $partial );
    32 } else {
    33     if ( ! headers_sent() ) {
    34         status_header( 404 );
    35     }
    36     require_once( $partials_dir . '404.php');
    37 }
    38 
    39 get_footer();
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/stylesheets/login.css

    r2579 r4470  
    256256    -webkit-box-shadow: none !important;
    257257    box-shadow: none !important;
     258    overflow: visible;
    258259}
    259260
     
    320321}
    321322
     323
     324body.route-register,
     325body.route-register-profile,
     326body.route-register-confirm {
     327    padding-top: 105px;
     328    height: auto;
     329}
     330
     331body.route-register #login,
     332body.route-register-profile #login,
     333body.route-register-confirm #login {
     334    width: 365px;
     335}
     336
     337body.route-register input.input,
     338body.route-register-profile input.input,
     339body.route-register-confirm input.input {
     340    margin-bottom: 0;
     341}
     342body.route-register #login form p,
     343body.route-register-profile #login form p,
     344body.route-register-confirm #login form p {
     345    margin-bottom: 16px;
     346}
     347
     348body.login form input.input::-webkit-input-placeholder { /* Chrome/Opera/Safari */
     349    opacity: 0.5;
     350}
     351body.login form input.input::-moz-placeholder { /* Firefox 19+ */
     352    opacity: 0.5;
     353}
     354body.login form input.input:-ms-input-placeholder { /* IE 10+ */
     355    opacity: 0.5;
     356}
     357body.login form input.input:-moz-placeholder { /* Firefox 18- */
     358    opacity: 0.5;
     359}
     360body.login form input.error {
     361    background-color: #FAE5E8;
     362    border: 3px solid #D42A41;
     363}
     364body.login form input.good {
     365    border-color: #83c373;
     366}
     367
     368body.route-register #login .message.error,
     369body.route-register-profile #login .message.error,
     370body.route-register-confirm #login .message.error {
     371    border-left-color: #dc3232;
     372    margin-bottom: auto !important;
     373    margin-left: -24px;
     374    padding-left: 24px;
     375    padding-right: 0;
     376}
     377body.route-register .message.error .avatar {
     378    float: left;
     379    border-radius: 50%;
     380    margin-right: 1em;
     381}
     382
     383form .login-mailinglist label {
     384    font-size: 12px;
     385    line-height: 1;
     386    cursor: pointer;
     387}
     388
    322389.oauth {
    323390    width: 100%;
Note: See TracChangeset for help on using the changeset viewer.