/
class.newUser.php
145 lines (104 loc) · 3.78 KB
/
class.newUser.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
namespace leantime\domain\controllers {
use leantime\core;
use leantime\domain\repositories;
use leantime\domain\services;
class newUser
{
/**
* run - display template and edit data
*
* @access public
*/
public function run()
{
$tpl = new core\template();
$userRepo = new repositories\users();
$project = new repositories\projects();
$language = new core\language();
$values = array(
'firstname' => "",
'lastname' => "",
'user' => "",
'phone' => "",
'role' => "",
'password' => "",
'clientId' => ""
);
//only Admins
if (core\login::userIsAtLeast("clientManager")) {
$projectrelation = array();
if (isset($_POST['save'])) {
$tempPasswordVar = $_POST['password'];
$values = array(
'firstname' => ($_POST['firstname']),
'lastname' => ($_POST['lastname']),
'user' => ($_POST['user']),
'phone' => ($_POST['phone']),
'role' => ($_POST['role']),
'password' => (password_hash($_POST['password'], PASSWORD_DEFAULT)),
'clientId' => ($_POST['client'])
);
//Choice is an illusion for client managers
if (core\login::userHasRole("clientManager")) {
$values['clientId'] = core\login::getUserClientId();
}
if ($values['user'] !== '') {
if ($_POST['password'] == $_POST['password2']) {
if (filter_var($values['user'], FILTER_VALIDATE_EMAIL)) {
if (password_verify($_POST['password'], $values['password']) && $_POST['password'] != '') {
if ($userRepo->usernameExist($values['user']) === false) {
$userId = $userRepo->addUser($values);
//Update Project Relationships
if (isset($_POST['projects'])) {
if ($_POST['projects'][0] !== '0') {
$project->editUserProjectRelations($userId, $_POST['projects']);
} else {
$project->deleteAllProjectRelations($userId);
}
}
$mailer = new core\mailer();
$mailer->setSubject($language->__("email_notifications.new_user_subject"));
$actual_link = BASE_URL;
$message = sprintf($language->__("email_notifications.new_user_message"), $_SESSION["userdata"]["name"], $actual_link, $values["user"], $tempPasswordVar);
$mailer->setHtml($message);
$to = array($values["user"]);
$mailer->sendMail($to, $_SESSION["userdata"]["name"]);
$tpl->setNotification($language->__("notification.user_created"), 'success');
$tpl->redirect(BASE_URL . "/users/showAll");
} else {
$tpl->setNotification($language->__("notification.user_exists"), 'error');
}
} else {
$tpl->setNotification($language->__("notification.passwords_dont_match"), 'error');
}
} else {
$tpl->setNotification($language->__("notification.no_valid_email"), 'error');
}
} else {
$tpl->setNotification($language->__("notification.passwords_dont_match"), 'error');
}
} else {
$tpl->setNotification($language->__("notification.enter_email"), 'error');
}
}
//exit();
$tpl->assign('values', $values);
$clients = new repositories\clients();
if (core\login::userIsAtLeast("manager")) {
$tpl->assign('clients', $clients->getAll());
$tpl->assign('allProjects', $project->getAll());
$tpl->assign('roles', core\login::$userRoles);
} else {
$tpl->assign('clients', array($clients->getClient(core\login::getUserClientId())));
$tpl->assign('allProjects', $project->getClientProjects(core\login::getUserClientId()));
$tpl->assign('roles', core\login::$clientManagerRoles);
}
$tpl->assign('relations', $projectrelation);
$tpl->display('users.newUser');
} else {
$tpl->display('general.error');
}
}
}
}