SettingsPage.php
5 years ago
SetupWizard.php
5 years ago
UserNotices.php
5 years ago
UserProfile.php
5 years ago
UserRegistered.php
5 years ago
UserRegistered.php
58 lines
| 1 | <?php // phpcs:ignore |
| 2 | |
| 3 | namespace WP2FA\Admin; |
| 4 | |
| 5 | use \WP2FA\WP2FA as WP2FA; |
| 6 | use \WP2FA\Authenticator\Authentication as Authentication; |
| 7 | use \WP2FA\Admin\SettingsPage as SettingsPage; |
| 8 | |
| 9 | /** |
| 10 | * UserProfile - Class for handling user things such as profile settings and admin list views. |
| 11 | */ |
| 12 | class UserRegistered { |
| 13 | |
| 14 | /** |
| 15 | * Classs constructor |
| 16 | */ |
| 17 | public function __construct() { |
| 18 | |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Apply 2FA Grace period |
| 23 | * |
| 24 | * @param int $user_id User id. |
| 25 | */ |
| 26 | public function apply_2fa_grace_period( $user_id ) { |
| 27 | // Get user object. |
| 28 | $user = get_user_by( 'id', $user_id ); |
| 29 | // Check if this user is actually eligible. |
| 30 | $is_needed = Authentication::is_user_eligible_for_2fa( $user->ID ); |
| 31 | $is_user_excluded = WP2FA::is_user_excluded( $user->ID ); |
| 32 | // If they are, add grace_period. |
| 33 | if ( $is_needed && ! $is_user_excluded ) { |
| 34 | $grace_policy = WP2FA::get_wp2fa_setting( 'grace-policy' ); |
| 35 | // Grab grace period. |
| 36 | $create_a_string = WP2FA::get_wp2fa_setting( 'grace-period' ) . ' ' . WP2FA::get_wp2fa_setting( 'grace-period-denominator' ); |
| 37 | |
| 38 | // Check if want to apply the custom period, or instant expiry. |
| 39 | if ( 'use-grace-period' === $grace_policy ) { |
| 40 | $grace_expiry = strtotime( $create_a_string ); |
| 41 | } else { |
| 42 | $grace_expiry = time(); |
| 43 | } |
| 44 | |
| 45 | update_user_meta( $user->ID, 'wp_2fa_grace_period_expiry', $grace_expiry ); |
| 46 | if ( 'no-grace-period' === $grace_policy ) { |
| 47 | update_user_meta( $user->ID, 'wp_2fa_user_enforced_instantly', true ); |
| 48 | } |
| 49 | |
| 50 | SettingsPage::send_2fa_enforced_email( $user->ID ); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | public function check_user_upon_role_change( $user_id, $role, $old_roles ) { |
| 55 | $this->apply_2fa_grace_period( $user_id ); |
| 56 | } |
| 57 | } |
| 58 |