diff --git a/cp/app/Controllers/Auth/AuthController.php b/cp/app/Controllers/Auth/AuthController.php index 9f72ab8..fd3d01a 100644 --- a/cp/app/Controllers/Auth/AuthController.php +++ b/cp/app/Controllers/Auth/AuthController.php @@ -7,6 +7,7 @@ use App\Controllers\Controller; use Respect\Validation\Validator as v; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; +use Pinga\Session; /** * AuthController @@ -59,7 +60,13 @@ class AuthController extends Controller global $container; $data = $request->getParsedBody(); $db = $container->get('db'); - $is2FAEnabled = $db->selectValue('SELECT tfa_enabled, tfa_secret FROM users WHERE email = ?', [$data['email']]); + $is2FAEnabled = $db->selectValue('SELECT tfa_enabled FROM users WHERE email = ?', [$data['email']]); + $isWebaEnabled = $db->selectValue('SELECT auth_method FROM users WHERE email = ?', [$data['email']]); + + if ($isWebaEnabled == 'webauthn') { + $container->get('flash')->addMessage('error', 'WebAuthn enabled for this account'); + return $response->withHeader('Location', '/login')->withStatus(302); + } // If 2FA is enabled and no code is provided, redirect to 2FA code entry if($is2FAEnabled && !isset($data['code'])) { @@ -219,7 +226,7 @@ class AuthController extends Controller // Send success response $user = $db->selectRow('SELECT * FROM users WHERE id = ?', [$user_id]); - Session::regenerate(true); + session_regenerate_id(); $_SESSION['auth_logged_in'] = true; $_SESSION['auth_user_id'] = $user['id']; $_SESSION['auth_email'] = $user['email']; @@ -237,7 +244,7 @@ class AuthController extends Controller 'users_audit', [ 'user_id' => $_SESSION['auth_user_id'], - 'user_event' => 'user.login', + 'user_event' => 'user.login.webauthn', 'user_resource' => 'control.panel', 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'user_ip' => get_client_ip(), diff --git a/cp/app/Controllers/ProfileController.php b/cp/app/Controllers/ProfileController.php index 8798f48..bd25b8c 100644 --- a/cp/app/Controllers/ProfileController.php +++ b/cp/app/Controllers/ProfileController.php @@ -60,19 +60,15 @@ class ProfileController extends Controller [$userId] ); $is_weba_activated = $db->select( - 'SELECT * FROM users_webauthn WHERE user_id = ?', - [$userId] - ); - $user_audit = $db->select( - 'SELECT * FROM users_audit WHERE user_id = ? ORDER BY event_time DESC', + 'SELECT * FROM users_webauthn WHERE user_id = ? ORDER BY created_at DESC LIMIT 5', [$userId] ); if ($is_2fa_activated) { - return view($response,'admin/profile/profile.twig',['email' => $email, 'username' => $username, 'status' => $status, 'role' => $role, 'csrf_name' => $csrfName, 'csrf_value' => $csrfValue, 'userAudit' => $user_audit]); + return view($response,'admin/profile/profile.twig',['email' => $email, 'username' => $username, 'status' => $status, 'role' => $role, 'csrf_name' => $csrfName, 'csrf_value' => $csrfValue]); } else if ($is_weba_activated) { - return view($response,'admin/profile/profile.twig',['email' => $email, 'username' => $username, 'status' => $status, 'role' => $role, 'qrcodeDataUri' => $qrcodeDataUri, 'secret' => $secret, 'csrf_name' => $csrfName, 'csrf_value' => $csrfValue, 'weba' => $is_weba_activated, 'userAudit' => $user_audit]); + return view($response,'admin/profile/profile.twig',['email' => $email, 'username' => $username, 'status' => $status, 'role' => $role, 'qrcodeDataUri' => $qrcodeDataUri, 'secret' => $secret, 'csrf_name' => $csrfName, 'csrf_value' => $csrfValue, 'weba' => $is_weba_activated]); } else { - return view($response,'admin/profile/profile.twig',['email' => $email, 'username' => $username, 'status' => $status, 'role' => $role, 'qrcodeDataUri' => $qrcodeDataUri, 'secret' => $secret, 'csrf_name' => $csrfName, 'csrf_value' => $csrfValue, 'userAudit' => $user_audit]); + return view($response,'admin/profile/profile.twig',['email' => $email, 'username' => $username, 'status' => $status, 'role' => $role, 'qrcodeDataUri' => $qrcodeDataUri, 'secret' => $secret, 'csrf_name' => $csrfName, 'csrf_value' => $csrfValue]); } } @@ -203,10 +199,19 @@ class ProfileController extends Controller 'sign_count' => $counter ] ); - - $msg = 'registration success.'; + $db->update( + 'users', + [ + 'auth_method' => 'webauthn' + ], + [ + 'id' => $userId + ] + ); + + $msg = 'Registration success.'; if ($credential->rootValid === false) { - $msg = 'registration ok, but certificate does not match any of the selected root ca.'; + $msg = 'Registration ok, but certificate does not match any of the selected root ca.'; } $return = new \stdClass(); diff --git a/cp/resources/views/admin/profile/profile.twig b/cp/resources/views/admin/profile/profile.twig index 2f62f01..f9c0dad 100644 --- a/cp/resources/views/admin/profile/profile.twig +++ b/cp/resources/views/admin/profile/profile.twig @@ -134,17 +134,23 @@ {% endif %}
{{ __('Secure your account with WebAuthn. Click the button below to register your device for passwordless sign-in.') }}
- +{{ __('WebAuthn is currently') }} {{ __('enabled') }} {{ __('for your account. If you encounter any issues or need to disable WebAuthn, please contact our support team for assistance.') }}
+{{ __('Device/Browser Info') }} | {{ __('Registration Date') }} | -{{ __('Action') }} |
---|---|---|
{{ device.user_agent }} | {{ device.created_at }} | -- {{ __('Edit') }} - |
{{ __('Secure your account with WebAuthn. Click the button below to register your device for passwordless sign-in.') }}
+ +{{ __('Track and review all user activities in your account below. Monitor logins, profile changes, and other key actions to ensure security and transparency.') }}
{{ __('Event') }} | -{{ __('User Agent') }} | -IP | -{{ __('Location') }} | -{{ __('Timestamp') }} | -
---|---|---|---|---|
{{ user.user_event }} | -{{ user.user_agent }} | -{{ user.user_ip }} | -{{ user.user_location }} | -{{ user.event_time }} | -
{{ __('No log data for user.') }} | -