-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_process.php
47 lines (41 loc) · 1.48 KB
/
auth_process.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
<?php
require_once("globals.php");
require_once("db.php");
require_once("models/User.php");
require_once("dao/UserDAO.php");
require_once("models/Message.php");
$message = new Message($BASE_URL);
$userDAO = new UserDAO($conn, $BASE_URL);
$type = filter_input(INPUT_POST, "type");
if ($type === "register") {
$name = filter_input(INPUT_POST, "name");
$lastname = filter_input(INPUT_POST, "lastname");
$email = filter_input(INPUT_POST, "email");
$password = filter_input(INPUT_POST, "password");
$confirmpassword = filter_input(INPUT_POST, "confirmpassword");
if ($name && $lastname && $name && $password) {
if ($password === $confirmpassword) {
if ($userDAO->findByEmail($email) === false) {
$user = new User();
$userToken = $user->generateToken();
$finalPassword = $user->generatePassword($password);
$user->name = $name;
$user->lastname = $lastname;
$user->email = $email;
$user->password = $finalPassword;
$user->token = $userToken;
$auth = true;
$userDAO->create($user, $auth);
} else {
$message->setMessage("Email já cadastrado.", "error", "back");
}
} else {
$message->setMessage("As senhas não são idênticas", "error", "back");
}
} else {
$message->setMessage("Por favor, preencha todos os campos.", "error", "back");
}
} else if ($type === "login") {
$email = filter_input(INPUT_POST, "email");
$password = filter_input(INPUT_POST, "password");
}