This repository was archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_signup.php
More file actions
67 lines (58 loc) · 1.77 KB
/
post_signup.php
File metadata and controls
67 lines (58 loc) · 1.77 KB
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
<?php
require_once("php/tools.php");
require_once("php/database.php");
if (isset($_SESSION["id"])) {
header("location: user.php");
exit();
}
$username = isset($_POST["username"]) ? $_POST["username"] : "";
$password = isset($_POST["password"]) ? $_POST["password"] : "";
$password_confirm = isset($_POST["password_confirm"]) ? $_POST["password_confirm"] : "";
$err = [];
if (strlen($username) > 30) {
array_push($err, "[en]Username[/en] deve essere lungo al massimo 30 caratteri.");
}
if (! preg_match("/^[A-Za-z0-9]+$/", $username)) {
array_push($err, "[en]Username[/en] non valido, usa solo lettere o numeri.");
}
if (strlen($password) < 8) {
array_push($err, "La [en]password[/en] deve essere lunga almeno 8 caratteri.");
}
if (! preg_match("/\d/", $password) || ! preg_match("/[a-zA-Z]/", $password)) {
array_push($err, "La [en]password[/en] deve contenere almeno una lettera e un numero.");
}
if ($password != $password_confirm) {
array_push($err, "Le [en]password[/en] non coincidono.");
}
if ($err) {
$_SESSION["error"] = $err;
header("location: signup.php");
exit();
}
try {
$connessione = new Database();
$signup = $connessione->signup($username, $password);
$res = $signup[0];
if ($res) {
$user_id = $signup[1];
$connessione->insertLista($user_id, "Da vedere");
$connessione->insertLista($user_id, "Visti");
$login = $connessione->login($username, $password);
}
unset($connessione);
} catch (Exception) {
unset($connessione);
Tools::errCode(500);
exit();
}
if ($res && !empty($login)) {
$_SESSION["id"] = $login["id"];
$_SESSION["is_admin"] = $login["is_admin"];
header("location: user.php");
exit();
} else {
$_SESSION["error"] = ["Questo [en]username[/en] è in uso da un altro utente. Scegline uno diverso."];
header("location: signup.php");
exit();
}
?>