Rename the top-level lib/ directory to core/ so the project root immediately communicates which code is core platform and which lives in modules/. PHP namespaces (MintyPHP\*) are unchanged — only the Composer PSR-4 path mapping moves from lib/ to core/. Module-internal lib/ directories (modules/*/lib/) are untouched. Updated across the full stack: - composer.json PSR-4 mapping - bootstrap entry points (web/index.php, bin/*, tests/bootstrap.php) - tooling configs (phpstan.neon, phpunit.xml, php-cs-fixer) - 26 architecture contract tests - enforcement-policy, guard-catalog, quality-gates - all documentation (CLAUDE.md, README, 25 docs/, .agents/skills/) - bin/qa-extended.sh search paths - .claude/settings.local.json permission paths Workflow: .agents/runs/CORE-LIB-RENAME-001/ (Analyst → Planner → Executor → Code Review (4 findings fixed) → Security Review → Acceptance Test → Finalizer) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
73 lines
2.2 KiB
PHP
73 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Repository\Auth;
|
|
|
|
use MintyPHP\DB;
|
|
|
|
/** Stores email verification codes with attempt counters, expiry, and completion status. */
|
|
class EmailVerificationRepository implements EmailVerificationRepositoryInterface
|
|
{
|
|
public function create(int $userId, string $codeHash, string $expiresAt): ?int
|
|
{
|
|
$id = DB::insert(
|
|
'insert into email_verifications (user_id, code_hash, expires_at, attempts, used_at, created) values (?,?,?,?,NULL,NOW())',
|
|
(string) $userId,
|
|
$codeHash,
|
|
$expiresAt,
|
|
0
|
|
);
|
|
return $id ? (int) $id : null;
|
|
}
|
|
|
|
public function invalidateForUser(int $userId): bool
|
|
{
|
|
$result = DB::update(
|
|
'update email_verifications set used_at = NOW() where user_id = ? and used_at is null',
|
|
(string) $userId
|
|
);
|
|
return $result !== false;
|
|
}
|
|
|
|
public function findActiveByUserId(int $userId): ?array
|
|
{
|
|
$row = DB::selectOne(
|
|
'select id, user_id, code_hash, expires_at, attempts, used_at from email_verifications where user_id = ? and used_at is null and expires_at > UTC_TIMESTAMP() order by id desc limit 1',
|
|
(string) $userId
|
|
);
|
|
if (!$row || !isset($row['email_verifications'])) {
|
|
return null;
|
|
}
|
|
return $row['email_verifications'];
|
|
}
|
|
|
|
public function findById(int $id): ?array
|
|
{
|
|
$row = DB::selectOne(
|
|
'select id, user_id, code_hash, expires_at, attempts, used_at from email_verifications where id = ? limit 1',
|
|
(string) $id
|
|
);
|
|
if (!$row || !isset($row['email_verifications'])) {
|
|
return null;
|
|
}
|
|
return $row['email_verifications'];
|
|
}
|
|
|
|
public function incrementAttempts(int $id): bool
|
|
{
|
|
$result = DB::update(
|
|
'update email_verifications set attempts = attempts + 1 where id = ?',
|
|
(string) $id
|
|
);
|
|
return $result !== false;
|
|
}
|
|
|
|
public function markUsed(int $id): bool
|
|
{
|
|
$result = DB::update(
|
|
'update email_verifications set used_at = NOW() where id = ?',
|
|
(string) $id
|
|
);
|
|
return $result !== false;
|
|
}
|
|
}
|