-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_process.php
81 lines (55 loc) · 2 KB
/
user_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
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
76
77
78
79
80
81
<?php
require_once("db.php");
require_once("globals.php");
require_once("models/User.php");
require_once("models/Message.php");
require_once("dao/UserDAO.php");
$message = new Message($BASE_URL);
$userDao = new UserDAO($conn, $BASE_URL);
$type = filter_input(INPUT_POST, "type");
if ($type == "update") {
$userData = $userDao->verifyToken();
$name = filter_input(INPUT_POST, "name");
$lastname = filter_input(INPUT_POST, "lastname");
$email = filter_input(INPUT_POST, "email");
$bio = filter_input(INPUT_POST, "bio");
$user = new User();
$userData->name = $name;
$userData->lastname = $lastname;
$userData->email = $email;
$userData->bio = $bio;
if (isset($_FILES["image"]) && !empty($_FILES["image"]["tmp_name"])) {
$image = $_FILES["image"];
$imageTypes = ["image/jpeg", "image/jpg", "image/png"];
$jpgArray = ["image/jpeg", "image/jpg"];
if (in_array($image["type"], $imageTypes)) {
if (in_array($image["type"], $jpgArray)) {
$imageFile = imagecreatefromjpeg($image["tmp_name"]);
} else {
$imageFile = imagecreatefrompng($image["tmp_name"]);
}
$imageName = $user->imageGenerateName();
imagejpeg($imageFile, "img/users/" . $imageName, 100);
$userData->image = $imageName;
} else {
$message->setMessage("Tipo inválido de imagem, insira png ou jpg!", "error", "back");
}
}
$userDao->update($userData);
} else if ($type === "changepassword") {
$password = filter_input(INPUT_POST, "password");
$confirmpassword = filter_input(INPUT_POST, "confirmpassword");
$userData = $userDao->verifyToken();
$id = $userData->id;
if ($password === $confirmpassword) {
$user = new User();
$finalPassword = $user->generatePassword($password);
$user->password = $finalPassword;
$user->id = $id;
$userDao->changePassword($user);
} else {
$message->setMessage("As senhas não coincidem.", "error", "back");
}
} else {
$message->setMessage("Informações inválidas.", "error", "index.php");
}