Skip to content

Commit 169afed

Browse files
committed
registrati
1 parent 350f0e8 commit 169afed

File tree

10 files changed

+88
-14
lines changed

10 files changed

+88
-14
lines changed

database/create.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CREATE TABLE `etichette` (
1818

1919
CREATE TABLE `utenti` (
2020
`id` int(15) NOT NULL AUTO_INCREMENT,
21-
`email` varchar(20) NOT NULL,
21+
`email` varchar(30) NOT NULL,
2222
`password` varchar(40) NOT NULL,
2323
`nome` varchar(20) NOT NULL,
2424
`cognome` varchar(20) NOT NULL,

src/accedi/errori.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
<?php if (isset($_SESSION['wrong_email']) && $_SESSION['wrong_email']): ?>
22
<?php $_SESSION['wrong_email'] = false ?>
33
<div class="alert alert-warning alert-dismissible fade show" role="alert">
4-
<strong>Holy guacamole!</strong> You should check in on some of those fields below.
4+
<strong>Attenzione!</strong> La mail inserita non corrisponde a nessun account.
55
<button type="button" class="close" data-dismiss="alert" aria-label="Close" onclick="$('.alert').alert()">
66
<span aria-hidden="true">&times;</span>
77
</button>
88
</div>
99
<?php endif; ?>
1010
<?php if (isset($_SESSION['wrong_password']) && $_SESSION['wrong_password']): ?>
1111
<?php $_SESSION['wrong_password'] = false ?>
12-
<b>Attenzione</b> La passowrd non è corretta.
12+
<div class="alert alert-danger alert-dismissible fade show" role="alert">
13+
<strong>Attenzione!</strong> La password inserita non è corretta.
14+
<button type="button" class="close" data-dismiss="alert" aria-label="Close" onclick="$('.alert').alert()">
15+
<span aria-hidden="true">&times;</span>
16+
</button>
17+
</div>
1318
<?php endif; ?>

src/docenti/wrapper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
LEFT JOIN utentidiutenti
1111
ON (
1212
utentidiutenti.idUtente=utenti.id AND
13-
utentidiutenti.idStudente=3
13+
utentidiutenti.idStudente=$idUtente
1414
)
1515
) as utenti
1616
LEFT JOIN lezioni

src/nuovaLezione/form.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,5 @@
8888
<button type="submit" class="btn btn-primary btn-block">Crea nuova lezione</button>
8989
</form>
9090
</div>
91-
<script type="text/javascript" src="script.js">
92-
93-
</script>
91+
<script type="text/javascript" src="script.js"></script>
9492
<!-- Button trigger modal -->

src/queries/existEmail.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
include "../connection.php";
4+
5+
$email = $_GET['email'];
6+
7+
$q['utente'] = count(query("SELECT * FROM utenti WHERE email='$email'"));
8+
9+
echo json_encode($q);
10+
11+
?>

src/registrati/errori.php

Whitespace-only changes.

src/registrati/form.php

+20-6
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,55 @@
22
<div class="card card-register mx-auto mt-5">
33
<div class="card-header">Registrati</div>
44
<div class="card-body">
5-
<form>
5+
<form method="POST">
66
<div class="form-group">
77
<div class="form-row">
88
<div class="col-md-6">
99
<div class="form-label-group">
10-
<input type="text" id="firstName" class="form-control" placeholder="First name" required="required" autofocus="autofocus">
10+
<input name="nome" type="text" id="firstName" class="form-control" placeholder="Nome" required="required" autofocus="autofocus" maxlength="20">
1111
<label for="firstName">Nome</label>
1212
</div>
1313
</div>
1414
<div class="col-md-6">
1515
<div class="form-label-group">
16-
<input type="text" id="lastName" class="form-control" placeholder="Last name" required="required">
16+
<input name="cognome" type="text" id="lastName" class="form-control" placeholder="Cognome" required="required" maxlength="20">
1717
<label for="lastName">Cognome</label>
1818
</div>
1919
</div>
2020
</div>
2121
</div>
2222
<div class="form-group">
2323
<div class="form-label-group">
24-
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required="required">
24+
<input name="email" type="email" id="inputEmail" class="form-control" placeholder="Email" required="required" onchange="controlEmail(this.value)" maxlength="30">
2525
<label for="inputEmail">Email</label>
2626
</div>
2727
</div>
28+
<div id="error">
29+
<div class="alert alert-danger alert-dismissible fade show" role="alert">
30+
<strong>Attenzione!</strong> Indirizzo email gia utilizzato.
31+
</div>
32+
</div>
2833
<div class="form-group">
2934
<div class="form-row">
3035
<div class="col-md-6">
3136
<div class="form-label-group">
32-
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required="required">
37+
<input name="password" type="password" id="inputPassword" class="form-control" placeholder="Password" required="required" maxlength="40">
3338
<label for="inputPassword">Password</label>
3439
</div>
3540
</div>
3641
<div class="col-md-6">
3742
<div class="form-label-group">
38-
<input type="password" id="confirmPassword" class="form-control" placeholder="Confirm password" required="required">
43+
<input type="password" id="confirmPassword" class="form-control" placeholder="Password" required="required" maxlength="40">
3944
<label for="confirmPassword">Ripeti password</label>
4045
</div>
4146
</div>
4247
</div>
4348
</div>
49+
<div id="errorPassword" style="display: none">
50+
<div class="alert alert-danger alert-dismissible fade show" role="alert">
51+
<strong>Attenzione!</strong> Password diverse tra loro.
52+
</div>
53+
</div>
4454
<button type="submit" class="btn btn-primary btn-block">Registrati</button>
4555
</form>
4656
<div class="text-center">
@@ -50,3 +60,7 @@
5060
</div>
5161
</div>
5262
</div>
63+
<script type="text/javascript" src="script.js"></script>
64+
<script type="text/javascript">
65+
66+
</script>

src/registrati/index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Home</title>
66
</head>
77
<body class="bg-dark">
8-
<?php include 'form.php' ?>
98
<?php include 'post.php' ?>
9+
<?php include 'form.php' ?>
1010
</body>
1111
</html>

src/registrati/post.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
include '../connection.php';
4+
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
5+
print_r($_POST);
6+
$nome = $_POST['nome'];
7+
$cognome = $_POST['cognome'];
8+
$email = $_POST['email'];
9+
$password = $_POST['password'];
10+
11+
query("INSERT INTO utenti (`nome`, `cognome`, `email`, `password`) VALUES ('$nome', '$cognome', '$email', SHA('$password'))");
12+
13+
header("Location: ../accedi/?email=$email");
14+
15+
}
16+
17+
?>

src/registrati/script.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var error = $('#error');
2+
error.hide();
3+
4+
var controlEmail = function(email){
5+
$.getJSON('../queries/existEmail.php?email='+email).done(function(e){
6+
if (e['utente']){
7+
error.show();
8+
$(':input[type="submit"]').prop('disabled', true);
9+
$(':input[type="password"]').prop('disabled', true);
10+
} else {
11+
error.hide();
12+
$(':input[type="submit"]').prop('disabled', false);
13+
$(':input[type="password"]').prop('disabled', false);
14+
}
15+
});
16+
}
17+
18+
19+
$('#inputPassword, #confirmPassword').on('keyup', function () {
20+
if ($('#inputPassword').val() == $('#confirmPassword').val()) {
21+
$('#errorPassword').hide();
22+
$(':input[type="submit"]').prop('disabled', false);
23+
$(':input[type="email"]').prop('disabled', false);
24+
} else{
25+
$('#errorPassword').show();
26+
$(':input[type="submit"]').prop('disabled', true);
27+
$(':input[type="email"]').prop('disabled', true);
28+
}
29+
});

0 commit comments

Comments
 (0)