From c80d6002330cd7e76f6e94bfffa2ffac090840d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Krzemin=CC=81ski?= Date: Tue, 8 Oct 2024 17:21:02 +0200 Subject: [PATCH] chore: reorder methods --- connectors/class-connector-two-factor.php | 125 +++++++++++----------- 1 file changed, 63 insertions(+), 62 deletions(-) diff --git a/connectors/class-connector-two-factor.php b/connectors/class-connector-two-factor.php index f22dee133..30b3c4ba8 100644 --- a/connectors/class-connector-two-factor.php +++ b/connectors/class-connector-two-factor.php @@ -132,68 +132,6 @@ public function log_override( $data ) { return $data; } - /** - * Callback to watch for 2FA authenticated actions. - * - * @param \WP_User $user Authenticated user. - * @param object $provider The 2FA Provider used. - */ - public function callback_two_factor_user_authenticated( $user, $provider ) { - - /* Translators: %s is the Two Factor provider. */ - $message = __( - 'Authenticated via %s', - 'stream' - ); - - $this->log( - $message, - array( - 'provider' => $provider->get_key(), - ), - $user->ID, - 'auth', - 'authenticated', - $user->ID - ); - } - - /** - * Callback to watch for failed logins with Two Factor errors. - * - * @param string $user_login User login. - * @param \WP_Error $error WP_Error object. - */ - public function callback_wp_login_failed( $user_login, $error ) { - if ( ! str_starts_with( $error->get_error_code(), 'two_factor_' ) ) { - return; - } - - $user = get_user_by( 'login', $user_login ); - if ( ! $user && is_email( $user_login ) ) { - $user = get_user_by( 'email', $user_login ); - } - - /* Translators: %1$s is the user display name, %2$s is the error code, %3$s is the error message. */ - $message = __( - '%1$s Failed 2FA: %2$s %3$s', - 'stream' - ); - - $this->log( - $message, - array( - 'display_name' => $this->escape_percentages( $user->display_name ), - 'code' => $error->get_error_code(), - 'error' => $error->get_error_message(), - ), - $user->ID, - 'auth', - 'failed', - $user->ID - ); - } - /** * Callback to watch for user_meta changes BEFORE it's made. * @@ -295,6 +233,7 @@ public function callback_updated_user_meta( $meta_id, $user_id, $meta_key, $new_ break; } } + /** * Callback to watch for user_meta changes AFTER it's added. * @@ -347,4 +286,66 @@ public function callback_added_user_meta( $meta_id, $user_id, $meta_key, $meta_v break; } } + + /** + * Callback to watch for 2FA authenticated actions. + * + * @param \WP_User $user Authenticated user. + * @param object $provider The 2FA Provider used. + */ + public function callback_two_factor_user_authenticated( $user, $provider ) { + + /* Translators: %s is the Two Factor provider. */ + $message = __( + 'Authenticated via %s', + 'stream' + ); + + $this->log( + $message, + array( + 'provider' => $provider->get_key(), + ), + $user->ID, + 'auth', + 'authenticated', + $user->ID + ); + } + + /** + * Callback to watch for failed logins with Two Factor errors. + * + * @param string $user_login User login. + * @param \WP_Error $error WP_Error object. + */ + public function callback_wp_login_failed( $user_login, $error ) { + if ( ! str_starts_with( $error->get_error_code(), 'two_factor_' ) ) { + return; + } + + $user = get_user_by( 'login', $user_login ); + if ( ! $user && is_email( $user_login ) ) { + $user = get_user_by( 'email', $user_login ); + } + + /* Translators: %1$s is the user display name, %2$s is the error code, %3$s is the error message. */ + $message = __( + '%1$s Failed 2FA: %2$s %3$s', + 'stream' + ); + + $this->log( + $message, + array( + 'display_name' => $this->escape_percentages( $user->display_name ), + 'code' => $error->get_error_code(), + 'error' => $error->get_error_message(), + ), + $user->ID, + 'auth', + 'failed', + $user->ID + ); + } }