{% extends 'basic.html.twig' %}
{% block title %}{{ site_name }} - First ID Demo{% endblock %}
{% block body %}
<div class="container">
<div class="row">
<div class="col-md-12">
<h3>First ID: <span id="firstid"></span></h3>
</div>
</div>
<div class="row mt-4">
<div class="col-md-4">
<h4>MAID:</h4>
<input type="text" id="maidInput" class="mb-2 form-control" placeholder="Enter or generate MAID">
<button id="generateMaid" class="btn btn-secondary">Generate New MAID</button>
</div>
<div class="col-md-4">
<h4>Email:</h4>
<input type="text" id="emailInput" class="mb-2 form-control" placeholder="Enter or generate Email">
<button id="generateEmail" class="btn btn-secondary">Generate New Email</button>
</div>
<div class="col-md-4">
<h4>Configuration:</h4>
<form id="configForm">
<div class="mb-2">
<label for="deviceType" class="form-label">Device Type:</label>
<select id="deviceType" class="form-select" name="deviceType">
<option value="web">Web</option>
<option value="mobile">Mobile</option>
<option value="tablet">Tablet</option>
</select>
</div>
<div class="mb-2">
<label for="deviceManufacturer" class="form-label">Device Manufacturer:</label>
<input type="text" id="deviceManufacturer" class="form-control" name="deviceManufacturer">
</div>
<div class="mb-2">
<label for="osVersion" class="form-label">OS Version:</label>
<input type="text" id="osVersion" class="form-control" name="osVersion">
</div>
<div class="mb-2">
<label for="buildId" class="form-label">Build ID:</label>
<input type="text" id="buildId" class="form-control" name="buildId">
</div>
<div class="mb-2">
<label for="deviceModel" class="form-label">Device Model:</label>
<input type="text" id="deviceModel" class="form-control" name="deviceModel">
</div>
<div class="mb-2">
<label for="deviceResolution" class="form-label">Device Resolution:</label>
<input type="text" id="deviceResolution" class="form-control" name="deviceResolution" placeholder="e.g., 1920x1080">
</div>
<div class="mb-2">
<label for="deviceRam" class="form-label">Device RAM (MB):</label>
<input type="number" id="deviceRam" class="form-control" name="deviceRam">
</div>
</form>
<button id="generateConfig" class="btn btn-secondary">Generate New Config</button>
</div>
</div>
<div class="mt-4 row">
<div class="col-md-12">
<button id="linkEntities" class="btn btn-primary">Link Entities</button>
<div id="result" class="mt-3"></div>
</div>
</div>
<div class="mt-4 row">
<div class="col-md-12">
<h4>History</h4>
<ul id="history" class="list-group"></ul>
</div>
</div>
</div>
<script>
const API_BASE_URL = 'https://api.preprod.first-id.fr';
let currentMaid = '';
let currentEmail = '';
let currentConfig = {};
let history = [];
function addToHistory(maid, email, config, fid, matchingStatus) {
const newEntry = `MAID: ${maid}, Email: ${email}, Config: ${JSON.stringify(config)}, FID: ${fid}, Matching Status: ${matchingStatus}`;
history.push(newEntry);
const historyElement = document.getElementById('history');
const li = document.createElement('li');
li.classList.add('list-group-item');
li.textContent = newEntry;
historyElement.appendChild(li);
}
async function sha256(message) {
const encoder = new TextEncoder();
const data = encoder.encode(message);
const hash = await crypto.subtle.digest('SHA-256', data);
const hashArray = Array.from(new Uint8Array(hash));
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
return hashHex;
}
function updateConfigForm(config) {
for (const [key, value] of Object.entries(config)) {
const element = document.getElementById(key);
if (element) {
element.value = value;
}
}
}
function getConfigFromForm() {
const form = document.getElementById('configForm');
const formData = new FormData(form);
const config = {};
for (const [key, value] of formData.entries()) {
config[key] = value;
}
return config;
}
document.getElementById('generateMaid').addEventListener('click', function() {
fetch('/mobile/generate-maid')
.then(response => response.json())
.then(data => {
currentMaid = data.maid;
document.getElementById('maidInput').value = currentMaid;
})
.catch(error => {
console.error('Error:', error);
});
});
document.getElementById('generateEmail').addEventListener('click', function() {
fetch('/mobile/generate-email')
.then(response => response.json())
.then(async data => {
currentEmail = await sha256(data.email);
document.getElementById('emailInput').value = currentEmail;
})
.catch(error => {
console.error('Error:', error);
});
});
document.getElementById('generateConfig').addEventListener('click', function() {
fetch('/mobile/generate-config')
.then(response => response.json())
.then(data => {
currentConfig = data.config;
updateConfigForm(currentConfig);
})
.catch(error => {
console.error('Error:', error);
});
});
document.getElementById('linkEntities').addEventListener('click', function() {
currentMaid = document.getElementById('maidInput').value;
currentEmail = document.getElementById('emailInput').value;
currentConfig = getConfigFromForm();
const deviceDataInput = {
deviceType: currentConfig.deviceType,
deviceManufacturer: currentConfig.deviceManufacturer,
osVersion: currentConfig.osVersion,
buildId: currentConfig.buildId,
deviceModel: currentConfig.deviceModel,
deviceResolution: currentConfig.deviceResolution,
deviceRam: currentConfig.deviceRam,
};
fetch(`${API_BASE_URL}/mobile/client`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
maid: currentMaid,
email: currentEmail,
...deviceDataInput,
dfid: "true"
}),
// mode: 'cors' // This explicitly declares we're making a CORS request
mode: "no-cors",
credentials: 'include',
})
.then(response => response.json())
.then(data => {
console.log("result", data);
if (data.firstId) {
document.getElementById('firstid').textContent = data.firstId;
document.getElementById('result').textContent = `Entities linked successfully. Matching status: ${data.matchingStatus}`;
addToHistory(currentMaid, currentEmail, deviceDataInput, data.firstId, data.matchingStatus);
} else {
document.getElementById('result').textContent = 'Error: ' + (data.message || 'Unknown error occurred');
}
})
.catch(error => {
document.getElementById('result').textContent = 'Error: ' + error;
});
});
</script>
{% endblock %}