Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep stats of logins by 2FA type. #289

Merged
merged 2 commits into from
Jul 30, 2024
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
15 changes: 15 additions & 0 deletions wporg-two-factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function load_webauthn_plugin() {
add_action( 'login_redirect', __NAMESPACE__ . '\redirect_to_2fa_settings', 105, 3 ); // After `wporg_remember_where_user_came_from_redirect()`, before `WP_WPorg_SSO::redirect_to_policy_update()`.
add_action( 'user_has_cap', __NAMESPACE__ . '\remove_capabilities_until_2fa_enabled', 99, 4 ); // Must run _after_ all other plugins.
add_action( 'current_screen', __NAMESPACE__ . '\block_webauthn_settings_page' );
add_action( 'two_factor_user_authenticated', __NAMESPACE__ . '\two_factor_user_authenticated', 10, 2 );

/**
* Determine which providers should be available to users.
Expand Down Expand Up @@ -423,6 +424,20 @@ function after_provider_deactivated( $user_id, $provider = null ) {
}
}

/**
* Record stats for number of authentications per provider per day.
*/
function two_factor_user_authenticated( $user_id, $provider ) {
if ( ! function_exists( 'bump_stats_extra' ) || ! $provider ) {
return;
}

$provider = str_ireplace( [ 'TwoFactor_Provider_', 'Two_Factor_' ], '', $provider->get_key() );
$provider = str_replace( '_', ' ', $provider );

bump_stats_extra( 'two-factor-auth', $provider );
}

/*
* Switch out the TOTP provider for one that encrypts the TOTP key.
*/
Expand Down
Loading