Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions includes/reader-activation/class-reader-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ final class Reader_Activation {
*/
const SSO_REGISTRATION_METHODS = [ 'google' ];

/**
* Whether the session is authenticating a newly registered reader
*
* @var bool
*/
private static $is_new_reader_auth = false;

/**
* Initialize hooks.
*/
Expand Down Expand Up @@ -750,6 +743,20 @@ public static function set_reader_verified( $user_or_user_id ) {

WooCommerce_Connection::add_wc_notice( __( 'Thank you for verifying your account!', 'newspack-plugin' ), 'success' );

/**
* Upon verification we want to destroy existing sessions to prevent a bad
* actor having originated the account creation from accessing the, now
* verified, account.
*
* If the verification is for the current user, we destroy other sessions.
*/
if ( get_current_user_id() === $user->ID ) {
\wp_destroy_other_sessions();
} else {
$session_tokens = \WP_Session_Tokens::get_instance( $user->ID );
$session_tokens->destroy_all();
}

/**
* Fires after a reader's email address is verified.
*
Expand Down Expand Up @@ -819,15 +826,6 @@ public static function auth_cookie_expiration( $length, $user_id, $remember ) {
$length = YEAR_IN_SECONDS;
}
}

/**
* If the session is authenticating a newly registered reader we want the
* auth cookie to be short lived since the email ownership has not yet been
* verified.
*/
if ( true === self::$is_new_reader_auth ) {
$length = 24 * HOUR_IN_SECONDS;
}
return $length;
}

Expand Down Expand Up @@ -1688,7 +1686,6 @@ public static function register_reader( $email, $display_name = '', $authenticat
Logger::log( 'Created new reader user with ID ' . $user_id );

if ( $authenticate ) {
self::$is_new_reader_auth = true;
self::set_current_reader( $user_id );
}
}
Expand Down