fix login issues

This commit is contained in:
root
2026-04-23 15:30:50 -04:00
parent ca4ba272fc
commit 5128c74892
4 changed files with 60 additions and 0 deletions
+3
View File
@@ -8,6 +8,8 @@ use App\Services\Attendance\SemesterRangeService;
use App\Services\Attendance\StudentAttendanceWriterService;
use App\Services\Attendance\TeacherAttendanceSubmissionService;
use App\Services\Attendance\AttendanceAutoPublishService;
use App\Services\AttendanceTracking\AttendanceMailerService;
use App\Services\AttendanceTracking\DefaultAttendanceMailerService;
use App\Services\Invoices\InvoiceConfigService;
use App\Services\Invoices\InvoiceGradeService;
use App\Services\Invoices\InvoiceTuitionService;
@@ -50,6 +52,7 @@ class AppServiceProvider extends ServiceProvider
$this->app->singleton(StudentAttendanceWriterService::class);
$this->app->singleton(TeacherAttendanceSubmissionService::class);
$this->app->singleton(AttendanceAutoPublishService::class);
$this->app->bind(AttendanceMailerService::class, DefaultAttendanceMailerService::class);
$this->app->singleton(StaffTimeOffLinkService::class);
$this->app->singleton(InvoiceConfigService::class);
@@ -2,6 +2,7 @@
namespace App\Services\AttendanceTracking;
use App\Models\Configuration;
use Illuminate\Support\Facades\Validator;
/**
@@ -0,0 +1,50 @@
<?php
namespace App\Services\AttendanceTracking;
use App\Services\EmailService;
use Illuminate\Support\Facades\Log;
class DefaultAttendanceMailerService implements AttendanceMailerService
{
public function __construct(
protected EmailService $emailService,
protected AttendanceEmailComposerService $emailComposerService
) {
}
public function send(string $to, string $subject, string $html): bool
{
return $this->emailService->send($to, $subject, $html, 'attendance');
}
public function queueAttendanceEvent(array $payload): void
{
$to = trim((string) data_get($payload, 'parent.email', ''));
if ($to === '') {
throw new \InvalidArgumentException('No parent email found for attendance notification.');
}
$student = (array) ($payload['student'] ?? []);
$studentName = trim((string) ($student['firstname'] ?? '') . ' ' . (string) ($student['lastname'] ?? ''));
$subjectType = (string) ($payload['subject'] ?? 'Attendance');
$date = substr((string) ($payload['date'] ?? now()->toDateString()), 0, 10);
$subject = "Attendance Notice: {$subjectType}";
$body = '<p>Dear ' . e((string) data_get($payload, 'parent.name', 'Parent/Guardian')) . ',</p>'
. '<p>This is an attendance notification for your student.</p>'
. '<ul>'
. '<li><strong>Student:</strong> ' . e($studentName !== '' ? $studentName : 'Student') . '</li>'
. '<li><strong>Date:</strong> ' . e($date) . '</li>'
. '<li><strong>Attendance:</strong> ' . e($subjectType) . '</li>'
. '</ul>'
. '<p>If you have any questions, please contact the school office.</p>';
$html = $this->emailComposerService->renderWithEmailLayout($subject, $body);
if (!$this->send($to, $subject, $html)) {
Log::error('Attendance notification email failed for ' . $to);
throw new \RuntimeException('Failed to send attendance notification email.');
}
}
}
@@ -4,6 +4,7 @@ namespace App\Services\Auth;
use App\Models\IpAttempt;
use App\Models\LoginActivity;
use App\Models\Configuration;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
@@ -83,12 +84,17 @@ class ApiLoginSecurityService
public function logSuccessfulLogin(User $user, Request $request): void
{
$schoolYear = trim((string) (Configuration::getConfig('school_year') ?? date('Y')));
$semester = trim((string) (Configuration::getConfig('semester') ?? 'Fall'));
LoginActivity::query()->create([
'user_id' => $user->id,
'email' => $user->email,
'login_time' => utc_now(),
'ip_address' => $request->ip(),
'user_agent' => (string) ($request->userAgent() ?? ''),
'school_year' => $schoolYear,
'semester' => $semester !== '' ? $semester : 'Fall',
]);
}