Skip to content

Commit

Permalink
chore: reorder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinkrzeminski committed Oct 8, 2024
1 parent 3ccb4df commit c80d600
Showing 1 changed file with 63 additions and 62 deletions.
125 changes: 63 additions & 62 deletions connectors/class-connector-two-factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
);
}
}

0 comments on commit c80d600

Please sign in to comment.