~tmpod/litenesshut

f58be7d1ddb56ce80e2db95fcc05b8d5558787f7 — tmpod 9 months ago
Versão inicial, obsoleta

Registada apenas para efeitos de arquivo.
1 files changed, 91 insertions(+), 0 deletions(-)

A index.html
A  => index.html +91 -0
@@ 1,91 @@
<!DOCTYPE html>
<html lang="pt">

<head>
    <title>LitenessHut</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        * {
            font-family: sans;
            margin: 10px;
        }
    </style>
</head>

<body>
    <h1>LitenessHut</h1>

    <form id="login" hidden>
        <label for="email">Endereço de e-mail</label>
        <input type="email" name="email" placeholder="gymbro@pro.ta">
        <br>
        <label for="email">Senha</label>
        <input type="password" name="password">
        <br>
        <button>Entrar</button>
    </form>

    <div id="rest">
        <button id="logout">Sair</button>
        <button id="get">Gerar</button>
        <br>
        <img id="code" src="" alt="Código QR">
    </div>

    <script>
        function hide(e) {e.setAttribute("hidden", true);}
        function show(e) {e.removeAttribute("hidden");}

        let login = document.getElementById("login");
        let rest = document.getElementById("rest");

        if (localStorage.getItem("token") === null) {
            console.log("Not logged in");
            show(login);
            hide(rest);
        } else {
            console.log("Logged in");
        }

        login.addEventListener("submit", async e => {
            e.preventDefault();

            // let resp = await fetch("https://...",);
            let token = "MzFlMjE0YzU3N2UwMWIwNzYwODA0M2JjMWY0ZDUxZmMzYjc4MTMxMmE4NjhlNzcyYzBjMGQxM2YwYjM3NmMzYw";

            localStorage.setItem("token", token);
            hide(login);
            show(rest);
            console.log("Logged in");
        });

        let logout = document.getElementById("logout");
        logout.addEventListener("click", e => {
            show(login);
            hide(rest);
            localStorage.removeItem("token");
            console.log("Logged out");
        });

        let getBtn = document.getElementById("get");
        let code = document.getElementById("code");
        getBtn.addEventListener("click", async e => {
            let headers = new Headers({
                "Authorization": `Bearer ${localStorage.getItem("token")}`,
                "Host": "vivagym.myvitale.com",
                "User-Agent": "okhttp/5.0.0-alpha.2",
            });
            let resp = await fetch("https://vivagym.myvitale.com/api/v2.0/exerp/qr", {
                headers:
                    headers,
                cors: "no-cors",
            });
            console.log(resp);
            code.setAttribute("src", resp.code);
            console.log("New code generated");
        });
    </script>
</body>

</html>