Making WordPress.org


Ignore:
Timestamp:
01/18/2016 09:11:31 PM (11 years ago)
Author:
stephdau
Message:

WordPress.org SSO: new custom template handling for login experience.

See #1524: wporg-sso part of the work.

File:
1 edited

Legend:

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

    r2204 r2314  
    7373                                if ( ! preg_match( '/\/wp-login\.php$/', $this->script ) ) {
    7474                                        // ... but not on its login screen.
    75                                         if ( preg_match( '/^\/oauth([\/\?]{1}.*)?$/', $_SERVER['REQUEST_URI'] ) ) {
    76                                                 // Let the theme render for oauth paths (/oauth, /oauth/, /oauth/*, but not /notoauth or /oauthnot)
     75                                        if ( preg_match( '/^\/(\?.*)?$/', $_SERVER['REQUEST_URI'] ) ) {
     76                                                // If at host root (/)
     77                                                if ( ! empty( $_GET['action'] ) ) {
     78                                                        // If there's an action, it's really meant for wp-login.php, redirect
     79                                                        $get = $_GET;
     80                                                        if ( in_array( $get['action'], array( 'logout', 'loggedout' ) ) ) {
     81                                                                // But make sure to show our custom screen when needed
     82                                                                $get['redirect_to'] = '/?screen=loggedout';
     83                                                        }
     84                                                        $this->_safe_redirect( add_query_arg( $get, $this->sso_login_url . '/wp-login.php' ) );
     85                                                        return;
     86                                                } else {
     87                                                        // Else let the theme render, or redirect if logged in
     88                                                        if ( is_user_logged_in() ) {
     89                                                                $this->_redirect_to_profile();
     90                                                        } else {
     91                                                                if ( empty( $_GET['screen'] ) ) {
     92                                                                        add_filter( 'login_form_defaults', array( &$this, 'login_form_defaults' ) );
     93                                                                }
     94                                                        }
     95                                                        return;
     96                                                }
     97                                        } else if ( preg_match( '/^\/oauth([\/\?]{1}.*)?$/', $_SERVER['REQUEST_URI'] ) ) {
     98                                                // Let the theme render for oauth paths (/oauth, /oauth/, /oauth/*, but
     99                                                // not /notoauth or /oauthnot), or redirect if logged in
     100                                                if ( is_user_logged_in() ) {
     101                                                        $this->_redirect_to_profile();
     102                                                }
    77103                                                return;
    78104                                        } else  if ( is_user_logged_in() ) {
    79                                                 // Or mimic what happens after a login without a specified redirect (send to profile).
    80                                                 $this->_safe_redirect( 'https://wordpress.org/support/profile/' . get_currentuserinfo()->user_login );
     105                                                // Logged in catch all, before last fallback
     106                                                $this->_redirect_to_profile();
    81107                                        } else {
    82108                                                // Otherwise, redirect to the login screen.
     
    109135                        return $url;
    110136                }
     137
     138               
     139                /**
     140                 * Filters the defaults captions and options for the login form
     141                 *
     142                 * @param array $defaults
     143                 * @return array
     144                 */
     145                public function login_form_defaults( $defaults ) {
     146                        $defaults['label_remember'] = __( 'Remember me', 'wporg-sso' );
     147                        $defaults['label_log_in']   = __( 'Log in', 'wporg-sso' );
     148                        if ( ! empty( $_GET['redirect_to'] ) ) {
     149                                $defaults['redirect'] = $_GET['redirect_to']; // always ultimately checked for safety at redir time
     150                        }
     151                        return $defaults;
     152                }
     153               
     154                /**
     155                 * Redirects the user to her/his (support) profile.
     156                 */
     157                protected function _redirect_to_profile() {
     158                        if ( ! is_user_logged_in() ) {
     159                                return;
     160                        }
     161                        $this->_safe_redirect( 'https://wordpress.org/support/profile/' . get_currentuserinfo()->user_login );
     162                }
    111163        }
    112164       
Note: See TracChangeset for help on using the changeset viewer.