<?php
// api/endpoints/verify-email.php
require_once __DIR__.'/../core/db.php';
require_once __DIR__.'/../core/response.php';

$token = $_GET['token'] ?? '';

$row = fetchOne("SELECT * FROM email_logs WHERE token = :t", ['t'=>$token]);

if (!$row || $row['is_used'] || strtotime($row['expired_at']) < time()) {
    jsonResponse(['success'=>false,'error'=>'Link tidak valid']);
}

execute("UPDATE email_logs SET is_used=1 WHERE id=:id",['id'=>$row['id']]);
execute("UPDATE player SET verification_status='verified' WHERE email=:e",['e'=>$row['email']]);

jsonResponse(['success'=>true]);
 