-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
112 lines (100 loc) · 3.18 KB
/
index.php
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
107
108
109
110
111
112
<?php
require 'pdo.php';
// execQuery($createUsersQuery);
// execQuery($createGamesQuery);
if (isset($_SESSION['user_id'])) {
header("Location: jogo.php");
}
if (isset($_POST)) {
switch($_POST['action']) {
case 'login':
$nickname = $_POST['nickname'];
$password = $_POST['password'];
$queryLogin = "
select id, full_name
from users
where nickname = '$nickname'
and passwd = '$password'
limit 1;
";
$userFound = execQueryFecth($queryLogin);
if ($userFound != null) {
foreach($userFound as $user) {
session_start();
session_id($user['id']);
$_SESSION['user_id'] = $user['id'];
$_SESSION['name'] = $user['full_name'];
}
header("Location: jogo.php");
return;
}
header("Location: index.php?warningLogin=true");
session_destroy();
break;
}
}
?>
<!DOCTYPE html>
<html lang="pt">
<head>
<link rel="stylesheet" type="text/css" href="style/index.css">
<meta charset="UTF-8">
<title>Trab SI401A - Login</title>
</head>
<body>
<header>
Login
</header>
<form id='form_login' action='index.php' method='POST'>
<main>
<label for="nickname">Usuário</label>
<br>
<input id="nickname" type="text" placeholder="Insira o usuário"
name="nickname" required>
<br><br>
<label for="password">Senha</label>
<br>
<input id="password" type="password" placeholder="Insira a senha"
name="password"
required>
<input id="action" type="hidden" name="action" value='login'>
<br><br><br>
<div id="button-section">
<button onclick="submitForm()">Entrar</button>
<br><br>
<button type="button"
onclick="window.location.href='cadastro.php'">Criar conta</button>
</div>
</main>
</form>
</body>
<script>
const submitForm = () => {
document.getElementById("form_login").submit();
}
const hasSignIn = "<?php
if($_GET !== null) {
echo $_GET['signIn'];
}
?>";
if (hasSignIn){
alert("Cadastro realizado com sucesso!");
}
const hasWarningLogin = "<?php
if($_GET !== null) {
echo $_GET['warningLogin'];
}
?>";
if (hasWarningLogin){
alert("Usuário ou senha incorretos!");
}
const isNotAuthorized = "<?php
if($_GET !== null) {
echo $_GET['nonAuth'];
}
?>";
if (isNotAuthorized){
alert("Acesso não autorizado, realize login!");
}
</script>
</html>