templates/mobile/mobile.html.twig line 1

Open in your IDE?
  1. {% extends 'basic.html.twig' %}
  2. {% block title %}{{ site_name }} - First ID Demo{% endblock %}
  3. {% block body %}
  4. <div class="container">
  5.     <div class="row">
  6.         <div class="col-md-12">
  7.             <h3>First ID: <span id="firstid"></span></h3>
  8.         </div>
  9.     </div>
  10.     <div class="row mt-4">
  11.         <div class="col-md-4">
  12.             <h4>MAID:</h4>
  13.             <input type="text" id="maidInput" class="mb-2 form-control" placeholder="Enter or generate MAID">
  14.             <button id="generateMaid" class="btn btn-secondary">Generate New MAID</button>
  15.         </div>
  16.         <div class="col-md-4">
  17.             <h4>Email:</h4>
  18.             <input type="text" id="emailInput" class="mb-2 form-control" placeholder="Enter or generate Email">
  19.             <button id="generateEmail" class="btn btn-secondary">Generate New Email</button>
  20.         </div>
  21.         <div class="col-md-4">
  22.             <h4>Configuration:</h4>
  23.             <form id="configForm">
  24.                 <div class="mb-2">
  25.                     <label for="deviceType" class="form-label">Device Type:</label>
  26.                     <select id="deviceType" class="form-select" name="deviceType">
  27.                         <option value="web">Web</option>
  28.                         <option value="mobile">Mobile</option>
  29.                         <option value="tablet">Tablet</option>
  30.                     </select>
  31.                 </div>
  32.                 <div class="mb-2">
  33.                     <label for="deviceManufacturer" class="form-label">Device Manufacturer:</label>
  34.                     <input type="text" id="deviceManufacturer" class="form-control" name="deviceManufacturer">
  35.                 </div>
  36.                 <div class="mb-2">
  37.                     <label for="osVersion" class="form-label">OS Version:</label>
  38.                     <input type="text" id="osVersion" class="form-control" name="osVersion">
  39.                 </div>
  40.                 <div class="mb-2">
  41.                     <label for="buildId" class="form-label">Build ID:</label>
  42.                     <input type="text" id="buildId" class="form-control" name="buildId">
  43.                 </div>
  44.                 <div class="mb-2">
  45.                     <label for="deviceModel" class="form-label">Device Model:</label>
  46.                     <input type="text" id="deviceModel" class="form-control" name="deviceModel">
  47.                 </div>
  48.                 <div class="mb-2">
  49.                     <label for="deviceResolution" class="form-label">Device Resolution:</label>
  50.                     <input type="text" id="deviceResolution" class="form-control" name="deviceResolution" placeholder="e.g., 1920x1080">
  51.                 </div>
  52.                 <div class="mb-2">
  53.                     <label for="deviceRam" class="form-label">Device RAM (MB):</label>
  54.                     <input type="number" id="deviceRam" class="form-control" name="deviceRam">
  55.                 </div>
  56.             </form>
  57.             <button id="generateConfig" class="btn btn-secondary">Generate New Config</button>
  58.         </div>
  59.     </div>
  60.     <div class="mt-4 row">
  61.         <div class="col-md-12">
  62.             <button id="linkEntities" class="btn btn-primary">Link Entities</button>
  63.             <div id="result" class="mt-3"></div>
  64.         </div>
  65.     </div>
  66.     <div class="mt-4 row">
  67.         <div class="col-md-12">
  68.             <h4>History</h4>
  69.             <ul id="history" class="list-group"></ul>
  70.         </div>
  71.     </div>
  72. </div>
  73. <script>
  74.     const API_BASE_URL = 'https://api.preprod.first-id.fr';
  75.     let currentMaid = '';
  76.     let currentEmail = '';
  77.     let currentConfig = {};
  78.     let history = [];
  79.     function addToHistory(maid, email, config, fid, matchingStatus) {
  80.         const newEntry = `MAID: ${maid}, Email: ${email}, Config: ${JSON.stringify(config)}, FID: ${fid}, Matching Status: ${matchingStatus}`;
  81.         history.push(newEntry);
  82.         const historyElement = document.getElementById('history');
  83.         const li = document.createElement('li');
  84.         li.classList.add('list-group-item');
  85.         li.textContent = newEntry;
  86.         historyElement.appendChild(li);
  87.     }
  88.     async function sha256(message) {
  89.         const encoder = new TextEncoder();
  90.         const data = encoder.encode(message);
  91.         const hash = await crypto.subtle.digest('SHA-256', data);
  92.         const hashArray = Array.from(new Uint8Array(hash));
  93.         const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
  94.         return hashHex;
  95.     }
  96.     function updateConfigForm(config) {
  97.         for (const [key, value] of Object.entries(config)) {
  98.             const element = document.getElementById(key);
  99.             if (element) {
  100.                 element.value = value;
  101.             }
  102.         }
  103.     }
  104.     function getConfigFromForm() {
  105.         const form = document.getElementById('configForm');
  106.         const formData = new FormData(form);
  107.         const config = {};
  108.         for (const [key, value] of formData.entries()) {
  109.             config[key] = value;
  110.         }
  111.         return config;
  112.     }
  113.     document.getElementById('generateMaid').addEventListener('click', function() {
  114.         fetch('/mobile/generate-maid')
  115.             .then(response => response.json())
  116.             .then(data => {
  117.                 currentMaid = data.maid;
  118.                 document.getElementById('maidInput').value = currentMaid;
  119.             })
  120.             .catch(error => {
  121.                 console.error('Error:', error);
  122.             });
  123.     });
  124.     document.getElementById('generateEmail').addEventListener('click', function() {
  125.         fetch('/mobile/generate-email')
  126.             .then(response => response.json())
  127.             .then(async data => {
  128.                 currentEmail = await sha256(data.email);
  129.                 document.getElementById('emailInput').value = currentEmail;
  130.             })
  131.             .catch(error => {
  132.                 console.error('Error:', error);
  133.             });
  134.     });
  135.     document.getElementById('generateConfig').addEventListener('click', function() {
  136.         fetch('/mobile/generate-config')
  137.             .then(response => response.json())
  138.             .then(data => {
  139.                 currentConfig = data.config;
  140.                 updateConfigForm(currentConfig);
  141.             })
  142.             .catch(error => {
  143.                 console.error('Error:', error);
  144.             });
  145.     });
  146.     document.getElementById('linkEntities').addEventListener('click', function() {
  147.         currentMaid = document.getElementById('maidInput').value;
  148.         currentEmail = document.getElementById('emailInput').value;
  149.         currentConfig = getConfigFromForm();
  150.         const deviceDataInput = {
  151.             deviceType: currentConfig.deviceType,
  152.             deviceManufacturer: currentConfig.deviceManufacturer,
  153.             osVersion: currentConfig.osVersion,
  154.             buildId: currentConfig.buildId,
  155.             deviceModel: currentConfig.deviceModel,
  156.             deviceResolution: currentConfig.deviceResolution,
  157.             deviceRam: currentConfig.deviceRam,
  158.         };
  159.         fetch(`${API_BASE_URL}/mobile/client`, {
  160.             method: 'POST',
  161.             headers: {
  162.                 'Content-Type': 'application/json',
  163.             },
  164.             body: JSON.stringify({
  165.                 maid: currentMaid,
  166.                 email: currentEmail,
  167.                 ...deviceDataInput,
  168.                 dfid: "true"
  169.             }),
  170.             // mode: 'cors' // This explicitly declares we're making a CORS request
  171.             mode: "no-cors",
  172.             credentials: 'include',
  173.         })
  174.         .then(response => response.json())
  175.         .then(data => {
  176.             console.log("result", data);
  177.             if (data.firstId) {
  178.                 document.getElementById('firstid').textContent = data.firstId;
  179.                 document.getElementById('result').textContent = `Entities linked successfully. Matching status: ${data.matchingStatus}`;
  180.                 addToHistory(currentMaid, currentEmail, deviceDataInput, data.firstId, data.matchingStatus);
  181.             } else {
  182.                 document.getElementById('result').textContent = 'Error: ' + (data.message || 'Unknown error occurred');
  183.             }
  184.         })
  185.         .catch(error => {
  186.             document.getElementById('result').textContent = 'Error: ' + error;
  187.         });
  188.     });
  189. </script>
  190. {% endblock %}