WizdomWeb/app/Controllers/ResendVerificationControlle...

61 lines
1.8 KiB
PHP

<?php
/**
* File: ResendVerificationController.php
* Version: 1.4
* Path: /app/Controllers/ResendVerificationController.php
* Purpose: Handles verification email resends using ResendVerificationService for centralized logic.
* Project: Wizdom Networks Website
*/
namespace WizdomNetworks\WizeWeb\Controllers;
use WizdomNetworks\WizeWeb\Core\View;
use WizdomNetworks\WizeWeb\Services\ResendVerificationService;
class ResendVerificationController
{
/**
* @var ResendVerificationService Service that handles logic for resend rate-limiting and dispatch.
*/
private ResendVerificationService $resendService;
/**
* Constructor to initialize ResendVerificationService.
*/
public function __construct()
{
$this->resendService = new ResendVerificationService();
}
/**
* Handles a POST request to resend a verification email.
* Validates email and type, and then delegates the resend attempt to the service.
* Renders either a success or failure view based on outcome.
*
* Expects 'email' and 'type' keys to be set in $_POST.
*
* @return void
*/
public function handle(): void
{
$email = trim($_POST['email'] ?? '');
$type = trim($_POST['type'] ?? '');
if (!$email || !$type || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
View::render('pages/verify_failed', ['reason' => 'Invalid email or type.']);
return;
}
$result = $this->resendService->attemptResend($type, $email);
if (!$result['success']) {
View::render('pages/verify_failed', ['reason' => $result['message']]);
} else {
View::render('pages/verify_success', [
'type' => $type,
'message' => $result['message']
]);
}
}
}