implemented step 05 by Gemini
added action saveConsent and ConsentService
This commit is contained in:
60
src/Services/ConsentService.php
Normal file
60
src/Services/ConsentService.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ConsentService
|
||||
{
|
||||
private FileStorage $storage;
|
||||
private const CONSENT_VERSION = 'webwizard-mvp-2026-06-12';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->storage = new FileStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves user consent for a specific project.
|
||||
*/
|
||||
public function saveConsent(string $projectId, string $userId, string $consentText): bool
|
||||
{
|
||||
// Verify project exists and belongs to user
|
||||
$projectData = $this->storage->get("projects/{$projectId}.json");
|
||||
if (!$projectData) {
|
||||
throw new Exception("Project not found.", 404);
|
||||
}
|
||||
if ($projectData['user_id'] !== $userId) {
|
||||
throw new Exception("Unauthorized access to project.", 403);
|
||||
}
|
||||
|
||||
$consentData = [
|
||||
'project_id' => $projectId,
|
||||
'user_id' => $userId,
|
||||
'consent_text_version' => self::CONSENT_VERSION,
|
||||
'consent_text' => $consentText,
|
||||
'accepted' => true,
|
||||
'accepted_at' => gmdate('Y-m-d\TH:i:s\Z')
|
||||
];
|
||||
|
||||
return $this->storage->put("consent/{$projectId}.json", $consentData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a project has a valid consent record.
|
||||
*/
|
||||
public function hasConsent(string $projectId): bool
|
||||
{
|
||||
return $this->storage->exists("consent/{$projectId}.json");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current consent version.
|
||||
*/
|
||||
public function getVersion(): string
|
||||
{
|
||||
return self::CONSENT_VERSION;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user