File size: 2,771 Bytes
490b2ec
 
 
 
 
 
 
 
 
 
951381e
 
490b2ec
 
 
 
 
 
951381e
490b2ec
951381e
 
 
 
 
 
 
490b2ec
 
951381e
 
 
 
 
 
 
 
 
 
490b2ec
 
 
 
 
 
 
951381e
 
490b2ec
 
951381e
490b2ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" >
                   <!-- content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' /> -->

  <title>Login</title>
  <!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> -->
  <link rel="stylesheet" href="css/styles.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
	

</head>
<body>
  <div id="login-container">
    <h1>Login</h1><br>
    <p>Olá! Insira usuário e senha para continuarmos.</p>
    <form action="javascript:autentica()" id="form_id" method="get" autocomplete="new-password">
      <label for="email">Usuário</label>
	  
      <input type="email" name="email" id="email"
	   placeholder="Digite seu usuário" 
	   readonly onclick= "this.removeAttribute('readonly');" 
	   oninvalid="this.setCustomValidity('Por favor entre com um email válido')" 
	   autocomplete="off"
       />

      <label for="password">Senha</label> 
	
      <input type="text" name="password" id="password" 
	   class="js-text-to-password-onedit"
	   placeholder="Digite sua senha"
	   readonly onclick= "this.removeAttribute('readonly');" 
	   autocomplete="off" 
	   style="-webkit-text-security: square;"
	   />
		


      <input type="submit" value="Login" >

    </form>
    <a href="#" id="forgot-pass">Esqueceu a senha?</a>

  </div>


  <script>
    
	 	   function autentica() {

        var xhttp = new XMLHttpRequest();

		var usuario = document.getElementById("email").value;
    	var senha = document.getElementById("password").value;
		

        xhttp.onreadystatechange = function () {
            if (this.readyState == 4)  {
			   if(this.status == 200) {
					var json = JSON.parse(this.responseText);
					storeLogin(json.nome,json.foto);
				//	alert("ACESSO OK : " );
			
					redirect(json.url);
					console.log("redirecionado para "+json.url);
					}
				else
				{
					alert("ACESSO NEGADO : " + this.responseText);		
				}	
            }
		

        };

        xhttp.open("GET", "/autentica?email="+usuario+"&passw="+senha, true);
        xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhttp.send("");

    } 
	
	function redirect(url)
	{	
		window.parent.location.href=url;
		window.parent.location.assign(url);
		window.parent.location.replace(url);
		
	}
	  function storeLogin(name,foto)
	  {
	      setCookieh("LOGIN", name);
	      setCookieh("FOTO", foto);
	  }
	
	  
	  function setCookieh(name,value) {
	 		window.localStorage.setItem(name, value);
	  }
	  
	 
  	
	</script>
</body>
</html>