page = Views::TOTP_AUTHENTICATION_PAGE; $this->token_checker = $token_checker; } /** * @param WP_Error|WP_User $user * * @return bool */ public function supports( $user ): bool { if ( $this->is_wp_user( $user ) ) { return false; } return ! empty( $this->request->post( 'twofas_light_totp_token' ) ); } /** * @return JSON_Response|Not_Handled_Response|Redirect_Response|View_Response * * @throws Invalid_Totp_Token_Exception */ protected function check_code() { $totp_token = new Token( $this->request->post( 'twofas_light_totp_token' ) ); $this->token_checker->check( $totp_token ); if ( ! $totp_token->accepted() ) { throw new Invalid_Totp_Token_Exception( 'Invalid TOTP token supplied' ); } Dispatcher::dispatch( new Standard_Login_Completed( $this->get_user_id() ) ); return $this->json( [ 'user_id' => $this->get_user_id() ], Code::OK ); } }