fix invalid token
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 49s
Tests / PHPUnit (push) Successful in 1m20s

This commit is contained in:
root
2026-08-30 21:10:35 -04:00
parent 140be9922d
commit 332b0d1007
9 changed files with 217 additions and 112 deletions
+4 -27
View File
@@ -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");