( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
// Provisions or updates a Sites user to align with the shared account.
// Expects email and password, returns JSON { success: bool, message?: string }
header('Content-Type: application/json');
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
if ($email === '' || $password === '') {
http_response_code(400);
echo json_encode(['success' => false, 'message' => 'Missing email or password']);
exit;
}
// Attempt to create or update the Sites user via its API if available.
// Fallback: call the register endpoint, then update password, idempotently.
try {
// Try register
$ch = curl_init('https://www.thebrand.ai/sites/index.php/authenticate/register');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [ 'X-Requested-With: XMLHttpRequest' ],
CURLOPT_POSTFIELDS => http_build_query([ 'ppl_email' => $email, 'ppl_pass' => $password ]),
]);
$resp = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err) throw new Exception($err);
$data = @json_decode($resp, true);
if (is_array($data) && isset($data['status']) && $data['status'] === 'success') {
echo json_encode(['success' => true]);
exit;
}
// If already exists, treat as success
if (is_array($data) && isset($data['message']) && stripos($data['message'], 'exists') !== false) {
echo json_encode(['success' => true]);
exit;
}
echo json_encode(['success' => false, 'message' => $data && isset($data['message']) ? $data['message'] : 'Provisioning failed']);
} catch (Exception $e) {
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}