Changeset 6799
- Timestamp:
- 02/28/2018 12:04:48 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-two-factor/wporg-two-factor.php
r6796 r6799 21 21 add_action( 'clear_auth_cookie', [ $this, 'clear_2fa_cookies' ] ); 22 22 add_filter( 'salt', [ $this, 'add_2fa_salt' ], 10, 2 ); 23 add_action( 'set_auth_cookie', [ $this, 'set_auth_cookie_maybe_set_2fa_cookie' ], 10, 6 ); 23 24 24 25 remove_action( 'edit_user_profile', [ 'Two_Factor_Core', 'user_two_factor_options' ] ); … … 96 97 } 97 98 99 function set_auth_cookie_maybe_set_2fa_cookie( $auth_cookie, $expire, $expiration, $user_id, $scheme, $token = '' ) { 100 // Check if they're the current user and 2FA 101 if ( ! is_user_logged_in() || get_current_user_id() !== $user_id ) { 102 return; 103 } 104 105 if ( ! self::is_user_using_two_factor( $user_id ) ) { 106 return; 107 } 108 109 if ( empty( $_COOKIE[ self::WPORG_2FA_COOKIE ] ) ) { 110 return; 111 } 112 113 // At this point we know they have a 2FA account, were already logged in, and had a 2FA cookie 114 $this->set_2fa_cookies( get_userdata( $user_id ), $expire ); 115 } 116 117 98 118 function clear_2fa_cookies() { 99 119 setcookie( self::WPORG_2FA_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN ); … … 101 121 } 102 122 103 function set_2fa_cookies( $user ) { 104 // Set the Expiration based on the main Authentication cookie 105 $auth_cookie_parts = wp_parse_auth_cookie( '', 'secure_auth' ); 106 if ( ! $auth_cookie_parts ) { 107 wp_logout(); 108 return; 109 } 110 111 $expiration = $auth_cookie_parts['expiration']; 123 function set_2fa_cookies( $user, $expiration = false ) { 124 if ( ! $expiration ) { 125 // Set the Expiration based on the main Authentication cookie 126 $auth_cookie_parts = wp_parse_auth_cookie( '', 'secure_auth' ); 127 if ( ! $auth_cookie_parts ) { 128 wp_logout(); 129 return; 130 } 131 $expiration = $auth_cookie_parts['expiration']; 132 } 112 133 113 134 $cookie_value = wp_generate_auth_cookie( $user->ID, $expiration, '2fa', '' /* WordPress.org doesn't use Session Tokens yet */ ); … … 256 277 257 278 $backup_classname = key( $backup_providers ); 258 $backup_provider = $backup_providers[ $backup_classname ];259 279 260 280 if ( ! function_exists( 'login_header' ) ) { … … 287 307 </div><!-- Opened in login_header() --> 288 308 289 <?php if ( 'WPORG_Two_Factor_Primary' === $provider_class ) : ?>309 <?php if ( 'WPORG_Two_Factor_Primary' === $provider_class && $backup_classname ) : ?> 290 310 <div class="backup-methods-wrap"> 291 311 <a href="<?php echo esc_url( add_query_arg( urlencode_deep( array(
Note: See TracChangeset
for help on using the changeset viewer.