fix invalid token
This commit is contained in:
@@ -442,7 +442,7 @@ class ParentAttendanceReportController extends BaseController
|
||||
}
|
||||
|
||||
// ✅ Build formatted success message
|
||||
$msg = '✅ <strong>Submission received successfully for ' . count($successNames) . ' item' . (count($successNames) > 1 ? 's' : '') . '.</strong><br>';
|
||||
$msg = '✅ <strong>Submission received successfully for ' . count($successNames) . ' student' . (count($successNames) > 1 ? 's' : '') . '.</strong><br>';
|
||||
$msg .= '<ul style="margin-top:5px;">';
|
||||
foreach ($successNames as $s) {
|
||||
$dateLabel = $s['date_label'] ?? ($s['date'] ?? '');
|
||||
|
||||
@@ -26,6 +26,7 @@ use App\Services\Parents\ParentAttendanceService;
|
||||
use App\Services\Parents\ParentEnrollmentService;
|
||||
use App\Services\Parents\ParentEventParticipationService;
|
||||
use App\Services\Parents\ParentPaymentService;
|
||||
use App\Services\Parents\ParentRegistrationNotificationService;
|
||||
use App\Services\Parents\ParentRegistrationService;
|
||||
use App\Support\Enrollment\DeliberationDecision;
|
||||
use App\Support\Enrollment\EnrollmentEligibility;
|
||||
@@ -71,6 +72,7 @@ class ParentController extends BaseController
|
||||
protected ?ParentEnrollmentService $parentEnrollmentService = null;
|
||||
protected ParentEventParticipationService $parentEventParticipationService;
|
||||
protected ParentPaymentService $parentPaymentService;
|
||||
protected ParentRegistrationNotificationService $parentRegistrationNotificationService;
|
||||
protected ?ParentRegistrationService $parentRegistrationService = null;
|
||||
|
||||
|
||||
@@ -95,6 +97,11 @@ class ParentController extends BaseController
|
||||
$this->parentAccountService = new ParentAccountService($this->db, $this->userModel, $this->authorizedUsersModel);
|
||||
$this->parentAttendanceService = new ParentAttendanceService($this->db);
|
||||
$this->parentPaymentService = new ParentPaymentService($this->db);
|
||||
$this->parentRegistrationNotificationService = new ParentRegistrationNotificationService(
|
||||
$this->userModel,
|
||||
$this->studentModel,
|
||||
service('emailService')
|
||||
);
|
||||
$this->parentEnrollmentService = new ParentEnrollmentService(
|
||||
$this->db,
|
||||
$this->userModel,
|
||||
@@ -180,10 +187,9 @@ class ParentController extends BaseController
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Retrieve all parents from the database where role is parent
|
||||
$parents = $this->userModel->where('role', 'parent')->findAll();
|
||||
// Pass the parents to the view
|
||||
return view('administrator/parent', ['parents' => $parents]);
|
||||
return view('administrator/parent', [
|
||||
'parents' => $this->parentAccountService->administratorParentList(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
@@ -194,44 +200,29 @@ class ParentController extends BaseController
|
||||
|
||||
public function store()
|
||||
{
|
||||
// Handle the form submission to create a new parent
|
||||
$data = [
|
||||
'firstname' => $this->request->getPost('firstname'),
|
||||
'lastname' => $this->request->getPost('lastname'),
|
||||
'email' => strtolower($this->request->getPost('email')),
|
||||
'password' => password_hash($this->request->getPost('password'), PASSWORD_DEFAULT),
|
||||
'role' => 'parent',
|
||||
];
|
||||
$this->userModel->insert($data);
|
||||
$this->parentAccountService->createAdministratorParent((array) $this->request->getPost());
|
||||
|
||||
return redirect()->to('/administrator/parent');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
// Retrieve the parent details to edit
|
||||
$parent = $this->userModel->find($id);
|
||||
return view('administrator/edit_parent', ['parent' => $parent]);
|
||||
return view('administrator/edit_parent', [
|
||||
'parent' => $this->parentAccountService->parentById((int) $id),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
// Handle the form submission to update an existing parent
|
||||
$data = [
|
||||
'firstname' => $this->request->getPost('firstname'),
|
||||
'lastname' => $this->request->getPost('lastname'),
|
||||
'email' => strtolower($this->request->getPost('email')),
|
||||
];
|
||||
if ($this->request->getPost('password')) {
|
||||
$data['password'] = password_hash($this->request->getPost('password'), PASSWORD_DEFAULT);
|
||||
}
|
||||
$this->userModel->update($id, $data);
|
||||
$this->parentAccountService->updateAdministratorParent((int) $id, (array) $this->request->getPost());
|
||||
|
||||
return redirect()->to('/administrator/parent');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
// Delete the parent
|
||||
$this->userModel->delete($id);
|
||||
$this->parentAccountService->deleteParent((int) $id);
|
||||
|
||||
return redirect()->to('/administrator/parent');
|
||||
}
|
||||
|
||||
@@ -2192,7 +2183,7 @@ class ParentController extends BaseController
|
||||
}
|
||||
|
||||
if ($registeredStudentIds !== []) {
|
||||
$this->notifyAdminsAboutRegisteredStudents($registeredStudentIds, (int) $parentId);
|
||||
$this->parentRegistrationNotificationService->sendAdminNewStudentEmails($registeredStudentIds, (int) $parentId);
|
||||
}
|
||||
|
||||
if ($studentAdded) {
|
||||
@@ -2208,55 +2199,6 @@ class ParentController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send admin registration emails after commit so only saved students are reported.
|
||||
*
|
||||
* @param list<int> $studentIds
|
||||
*/
|
||||
private function notifyAdminsAboutRegisteredStudents(array $studentIds, int $parentId): void
|
||||
{
|
||||
$parent = $this->userModel->find($parentId);
|
||||
if (! is_array($parent)) {
|
||||
log_message('warning', 'Unable to send admin student registration email: parent not found for ID ' . $parentId);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (array_values(array_unique(array_filter(array_map('intval', $studentIds)))) as $studentId) {
|
||||
$student = $this->studentModel->find($studentId);
|
||||
if (! is_array($student)) {
|
||||
log_message('warning', 'Unable to send admin student registration email: student not found for ID ' . $studentId);
|
||||
continue;
|
||||
}
|
||||
|
||||
$payload = $student;
|
||||
$payload['parents'] = [
|
||||
'user_id' => $parentId,
|
||||
'firstname' => (string) ($parent['firstname'] ?? ''),
|
||||
'lastname' => (string) ($parent['lastname'] ?? ''),
|
||||
'email' => (string) ($parent['email'] ?? ''),
|
||||
];
|
||||
|
||||
$studentFullName = trim((string) ($student['firstname'] ?? '') . ' ' . (string) ($student['lastname'] ?? '')) ?: 'Student ID ' . $studentId;
|
||||
$adminMessage = view('emails/admin_student_registered', ['student' => $payload], ['saveData' => true]);
|
||||
|
||||
try {
|
||||
$sent = service('emailService')->send(
|
||||
'registration@alrahmaisgl.org',
|
||||
'New Student Registered: ' . $studentFullName,
|
||||
$adminMessage,
|
||||
'notifications'
|
||||
);
|
||||
|
||||
if (! $sent) {
|
||||
log_message('error', 'Admin student registration email failed for student ID ' . $studentId);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
log_message('error', 'Admin student registration email failed for student ID ' . $studentId . ': ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Function to check if the parent has registered kids and redirect accordingly
|
||||
public function registerKidCheck()
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ require_once APPPATH . 'Helpers/pbkdf2_helper.php';
|
||||
|
||||
class UserController extends BaseController
|
||||
{
|
||||
private const ACTIVATION_TTL_HOURS = 48;
|
||||
private const ACTIVATION_TTL_MINUTES = 15;
|
||||
protected $userModel;
|
||||
protected $roleModel;
|
||||
protected $userRoleModel;
|
||||
@@ -654,30 +654,7 @@ class UserController extends BaseController
|
||||
|
||||
public function confirm($token)
|
||||
{
|
||||
log_message('info', 'Processing email confirmation.');
|
||||
|
||||
$tokenHash = $this->hashToken($token);
|
||||
$user = $this->userModel
|
||||
->groupStart()
|
||||
->where('token', $tokenHash)
|
||||
->orWhere('token', $token)
|
||||
->groupEnd()
|
||||
->where('created_at >=', Time::now()->subHours(self::ACTIVATION_TTL_HOURS)->toDateTimeString())
|
||||
->first();
|
||||
|
||||
if (!$user || $user['is_verified'] == 1) {
|
||||
return redirect()->to('/invalid_token');
|
||||
}
|
||||
|
||||
|
||||
// Mark the user as verified and generate an account ID
|
||||
$account_id = 'ACC' . str_pad($user['id'], 8, '0', STR_PAD_LEFT); // Example: ACC00000001
|
||||
$this->userModel->update($user['id'], ['is_verified' => 1, 'token' => null, 'account_id' => $account_id]);
|
||||
|
||||
log_message('info', 'User verified and account ID generated: ' . $account_id);
|
||||
|
||||
// Redirect to the set password page
|
||||
return redirect()->to('/set_password/' . $user['id']);
|
||||
return $this->setPassword($token);
|
||||
}
|
||||
|
||||
public function setPassword($token)
|
||||
@@ -690,7 +667,7 @@ class UserController extends BaseController
|
||||
->where('token', $tokenHash)
|
||||
->orWhere('token', $token)
|
||||
->groupEnd()
|
||||
->where('created_at >=', Time::now()->subHours(self::ACTIVATION_TTL_HOURS)->toDateTimeString())
|
||||
->where('created_at >=', Time::now()->subMinutes(self::ACTIVATION_TTL_MINUTES)->toDateTimeString())
|
||||
->first();
|
||||
|
||||
if (!$user || $user['is_verified'] == 1) {
|
||||
@@ -747,7 +724,7 @@ class UserController extends BaseController
|
||||
->where('token', $tokenHash)
|
||||
->orWhere('token', $token)
|
||||
->groupEnd()
|
||||
->where('created_at >=', Time::now()->subHours(self::ACTIVATION_TTL_HOURS)->toDateTimeString())
|
||||
->where('created_at >=', Time::now()->subMinutes(self::ACTIVATION_TTL_MINUTES)->toDateTimeString())
|
||||
->first();
|
||||
|
||||
log_message('debug', "Attempting to set password for user $userId");
|
||||
|
||||
Reference in New Issue
Block a user