-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsignup_action.php
More file actions
43 lines (34 loc) · 1.19 KB
/
signup_action.php
File metadata and controls
43 lines (34 loc) · 1.19 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
<?php
require './config.php';
require './models/Auth.php';
$name = filter_input(INPUT_POST,'name');
$email = filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL);
$password = filter_input(INPUT_POST,'password');
$birthdate = filter_input(INPUT_POST,'birthdate');
if($name && $email && $password && $birthdate){
$auth = new Auth($pdo,$base);
$birthdate = explode('/',$birthdate);
if(count($birthdate) != 3){
$_SESSION['flash'] = " Data de nascimento inválida.";
header("Location: ".$base."/signup.php");
exit;
}
$birthdate = $birthdate[2].'-'.$birthdate[1].'-'.$birthdate[0];
if(strtotime($birthdate) == false){
$_SESSION['flash'] = " Data de nascimento inválida.";
header("Location: ".$base."/signup.php");
exit;
}
if($auth->emailExists($email,$password) === false){
$auth->registerUser($name,$email,$password,$birthdate);
header("Location: ".$base);
exit;
}else {
$_SESSION['flash'] = " E-mail já cadastrado.";
header("Location: ".$base."/signup.php");
exit;
}
}
$_SESSION['flash'] = " Campos não enviados.";
header("Location: ".$base."/login.php");
exit;