Add domain status notifications & login alerts
Introduce richer notifications and domain status handling across the app. - NotificationService: Add domain status alert formatting/sending, in-app notifications for available/registered/redemption/pending_delete, richer session_new and session_failed notifications (geolocation + UA parsing) and helpers for human-readable status labels. - Auth/TwoFactor: Emit notifications for successful logins (including remember-me and 2FA) and failed login attempts; update last-login timestamp on various flows. - DomainController: Wrap bulk domain create in try/catch to handle duplicate race conditions and log failures. - WhoisService: Detect redemption_period and pending_delete statuses from WHOIS/EPP statuses. - Settings/Setting: Add settings support for notification status triggers and bump default app_version to 1.1.2; persist/update status trigger values. - Views/Layout/View helpers: Add parsing/formatting for login notification data, add new status labels/classes (available, redemption_period, pending_delete), update notification icons/colors mapping. - Top-nav & Notifications UI: Enhance dropdown with rich login/failed-login display (flags, device icons), clickable domain redirects when marking read, badge IDs for dynamic updates. - Error admin UI: Add copy error report button with robust clipboard fallback and toast UI reused from messages; improved copy UX in admin index/detail. - Installer: Add new migration 024 to installer migration lists and adjust detected toVersion to 1.1.2. - DB: Add migration file 024_add_status_notifications_v1.1.2.sql (new file). These changes add user-facing alerts for domain lifecycle events and stronger login/security notifications while improving UI feedback and robustness during bulk operations.
This commit is contained in:
@@ -94,10 +94,10 @@ class AuthController extends Controller
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
$logger = new \App\Services\Logger();
|
||||
$logger->warning("Login failed - User not found or not active", [
|
||||
$this->logger->warning("Login failed - User not found or not active", [
|
||||
'username' => $username,
|
||||
'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown'
|
||||
'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown',
|
||||
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? 'unknown'
|
||||
]);
|
||||
$_SESSION['error'] = 'Invalid username or password';
|
||||
$this->redirect('/login');
|
||||
@@ -106,11 +106,23 @@ class AuthController extends Controller
|
||||
|
||||
// Verify password
|
||||
if (!$this->userModel->verifyPassword($password, $user['password'])) {
|
||||
$logger = new \App\Services\Logger();
|
||||
$logger->warning("Login failed - Password verification failed", [
|
||||
$this->logger->warning("Login failed - Wrong password", [
|
||||
'username' => $username,
|
||||
'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown'
|
||||
'user_id' => $user['id'],
|
||||
'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown',
|
||||
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? 'unknown'
|
||||
]);
|
||||
|
||||
// Notify the target user about failed login attempt (wrong password)
|
||||
try {
|
||||
$ipAddress = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
|
||||
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? null;
|
||||
$notificationService = new \App\Services\NotificationService();
|
||||
$notificationService->notifyFailedLogin($user['id'], 'Wrong password', $ipAddress, $userAgent, $username);
|
||||
} catch (\Exception $e) {
|
||||
// Don't block response if notification fails
|
||||
}
|
||||
|
||||
$_SESSION['error'] = 'Invalid username or password';
|
||||
$this->redirect('/login');
|
||||
return;
|
||||
@@ -183,6 +195,16 @@ class AuthController extends Controller
|
||||
// Update last login
|
||||
$this->userModel->updateLastLogin($user['id']);
|
||||
|
||||
// Create login notification
|
||||
try {
|
||||
$ipAddress = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
|
||||
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? null;
|
||||
$notificationService = new \App\Services\NotificationService();
|
||||
$notificationService->notifyNewLogin($user['id'], 'Direct login', $ipAddress, $userAgent);
|
||||
} catch (\Exception $e) {
|
||||
// Don't block login if notification fails
|
||||
}
|
||||
|
||||
// Set success message for login
|
||||
$_SESSION['success'] = 'Login successful! Welcome back, ' . htmlspecialchars($user['full_name']) . '.';
|
||||
|
||||
@@ -744,6 +766,19 @@ class AuthController extends Controller
|
||||
// Session is automatically tracked by DatabaseSessionHandler
|
||||
// No need to manually create session record
|
||||
|
||||
// Update last login timestamp
|
||||
$this->userModel->updateLastLogin($user['id']);
|
||||
|
||||
// Create login notification for remember-me auto-login
|
||||
try {
|
||||
$ipAddress = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
|
||||
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? null;
|
||||
$notificationService = new \App\Services\NotificationService();
|
||||
$notificationService->notifyNewLogin($user['id'], 'Remember me', $ipAddress, $userAgent);
|
||||
} catch (\Exception $e) {
|
||||
// Don't block login if notification fails
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user