Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

250 QCM #36

Closed
lol-linux opened this issue Jun 10, 2024 · 1 comment
Closed

250 QCM #36

lol-linux opened this issue Jun 10, 2024 · 1 comment

Comments

@lol-linux
Copy link

lol-linux commented Jun 10, 2024

I would like to know how I can modify my code so that it displays the QCM and allows me to respond. Thank you in advance.

`

<title>Test de Connexion EcoleDirecte</title> <style> body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f5f5f5; margin: 0; } #status { padding: 20px; border: 1px solid #ccc; background-color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,0.1); } .success { color: green; } .error { color: red; } </style>
Chargement...
<script>

document.addEventListener("DOMContentLoaded", function() {
const statusElement = document.getElementById("status");

const credentials = {
    identifiant: "",
    motdepasse: "",
    isRelogin: false,
    uuid: ""
};

const requestData = {
    method: "POST",
    headers: {
        "Content-Type": "application/x-www-form-urlencoded",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
    },
    body: `data=${encodeURIComponent(JSON.stringify(credentials))}`
};

fetch("https://api.ecoledirecte.com/v3/login.awp", requestData)
    .then(response => response.json())
    .then(data => {
        if (data.code === 200) {
            statusElement.textContent = "Connexion réussie à l'API  !";
            statusElement.classList.add("success");
        } else if (data.code === 250) {
            statusElement.textContent = "Code de réponse de l'API : 250";
            statusElement.classList.add("success");
        } else {
            statusElement.textContent = `Échec de la connexion : ${data.message || "Erreur inconnue"}`;
            statusElement.classList.add("error");
        }
    })
    .catch(error => {
        console.error("Erreur lors de la requête :", error);
        statusElement.textContent = "Échec de la connexion : erreur réseau ou serveur.";
        statusElement.classList.add("error");
    });

});

</script>
`
@M6a5x98
Copy link

M6a5x98 commented Jun 13, 2024

When the script reaches the point where it detects data.code === 250 fetch the qcm endpoint and create a form on the page with all responses decoded from base 64.
In .then(serverResponse) callback function after fetch :

let question = serverResponse.data.question;
let reponses = [];
serverResponse.data.propositions.forEach(proposition => {
     reponses.push(atob(proposition))
})
//Create a <form> element with all datas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants