forked from COLTEC-DAW/E09-Show-do-Bilhao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cadastro.php
75 lines (62 loc) · 2.31 KB
/
cadastro.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
<?php
ob_start();
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Dá Bilhão?</title>
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/css/materialize.min.css">
<link rel="stylesheet" href="css/main.css">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<?php include 'menu.inc'; ?>
<main>
<div class="container">
<?php require 'cadastro.inc'; require 'classes.php';
if ($_POST["nome"] != NULL) {
$usuarios_file = file_get_contents("files/usuarios.json");
$decoded = json_decode($usuarios_file, TRUE);
// transformas os dados da form em obj
$novo_usuario = new User($_POST["nome"], $_POST["email"], $_POST["login"], $_POST["senha"]);
// verifica se o usuario ja existe
// https://stackoverflow.com/questions/4343596/parsing-json-file-with-php
$usuario_existente = FALSE;
$jsonIterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(json_decode($usuarios_file, TRUE)),RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key => $val) {
if(is_array($val)) {
// echo "$key:<br>";
} else {
// echo "$key => $val<br>";
if ($key == "login" && $val == $_POST["login"]) {
$usuario_existente = TRUE;
echo '<h4 class="center-align">Login já existente. Tente novamente ou logue-se.</h4>';
}
}
}
if (!$usuario_existente) {
array_push( $decoded, $novo_usuario);
$arquivo = fopen("files/usuarios.json", 'w');
fwrite($arquivo, json_encode($decoded, JSON_PRETTY_PRINT));
fclose($arquivo);
echo 'Usuario cadastrado,<a href="login.php" class=""> clique aqui para logar</a>';
}
}
?>
</div>
</main>
<?php include 'rodape.inc'; ?>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/js/materialize.min.js"></script>
<script>
$(document).ready(function() {
$('select').material_select();
});
</script>
</body>
</html>