boostgh / templates /index.html
victoirefinal7vi's picture
Create templates/index.html
6468adb verified
<!-- templates/index.html -->
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Générateur de Comptes</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.6.2/axios.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.form-group {
margin-bottom: 15px;
}
.btn {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.btn:disabled {
background-color: #ccc;
}
.status {
margin-top: 20px;
padding: 10px;
border-radius: 4px;
}
.error {
background-color: #ffebee;
color: #c62828;
}
.success {
background-color: #e8f5e9;
color: #2e7d32;
}
.progress {
margin-top: 10px;
padding: 10px;
background-color: #f5f5f5;
border-radius: 4px;
display: none;
}
</style>
</head>
<body>
<h1>Générateur de Comptes</h1>
<div class="form-group">
<label for="num_accounts">Nombre de comptes à créer:</label>
<input type="number" id="num_accounts" min="1" value="1" class="form-control">
</div>
<button onclick="createAccounts()" id="submitBtn" class="btn">Générer les comptes</button>
<div id="status" class="status" style="display: none;"></div>
<div id="progress" class="progress">
<div>Création des comptes en cours...</div>
<div>Comptes créés: <span id="accountsCreated">0</span></div>
</div>
<script>
async function createAccounts() {
const numAccounts = document.getElementById('num_accounts').value;
const submitBtn = document.getElementById('submitBtn');
const status = document.getElementById('status');
const progress = document.getElementById('progress');
submitBtn.disabled = true;
status.style.display = 'none';
progress.style.display = 'block';
try {
const response = await axios.post('/create_accounts', {
num_accounts: numAccounts
}, {
headers: {
'Content-Type': 'application/json'
}
});
// Commencer à vérifier le statut
checkStatus();
status.textContent = response.data.message;
status.className = 'status success';
status.style.display = 'block';
} catch (error) {
status.textContent = error.response?.data?.error || 'Une erreur est survenue';
status.className = 'status error';
status.style.display = 'block';
progress.style.display = 'none';
submitBtn.disabled = false;
}
}
async function checkStatus() {
const accountsCreated = document.getElementById('accountsCreated');
try {
const response = await axios.get('/check_status');
if (response.data.status === 'completed') {
document.getElementById('progress').style.display = 'none';
document.getElementById('submitBtn').disabled = false;
return;
}
accountsCreated.textContent = response.data.accounts_created;
setTimeout(checkStatus, 2000);
} catch (error) {
console.error('Erreur lors de la vérification du statut:', error);
}
}
</script>
</body>
</html>