@@ -21,226 +21,226 @@ |
||
21 | 21 | |
22 | 22 | class PageCloseRequest extends RequestActionBase |
23 | 23 | { |
24 | - protected function main() |
|
25 | - { |
|
26 | - $this->processClose(); |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Main function for this page, when no specific actions are called. |
|
31 | - * @throws ApplicationLogicException |
|
32 | - */ |
|
33 | - final protected function processClose() |
|
34 | - { |
|
35 | - $this->checkPosted(); |
|
36 | - $database = $this->getDatabase(); |
|
37 | - |
|
38 | - $currentUser = User::getCurrent($database); |
|
39 | - $template = $this->getTemplate($database); |
|
40 | - $request = $this->getRequest($database); |
|
41 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
42 | - |
|
43 | - if ($request->getStatus() === 'Closed') { |
|
44 | - throw new ApplicationLogicException('Request is already closed'); |
|
45 | - } |
|
46 | - |
|
47 | - if ($this->confirmEmailAlreadySent($request, $template)) { |
|
48 | - return; |
|
49 | - } |
|
50 | - |
|
51 | - if ($this->confirmReserveOverride($request, $template, $currentUser, $database)) { |
|
52 | - return; |
|
53 | - } |
|
54 | - |
|
55 | - if ($this->confirmAccountCreated($request, $template)) { |
|
56 | - return; |
|
57 | - } |
|
58 | - |
|
59 | - // I think we're good here... |
|
60 | - $request->setStatus('Closed'); |
|
61 | - $request->setReserved(null); |
|
62 | - |
|
63 | - Logger::closeRequest($database, $request, $template->getId(), null); |
|
64 | - |
|
65 | - $request->save(); |
|
66 | - |
|
67 | - if ($currentUser->getWelcomeTemplate() !== null) { |
|
68 | - $this->enqueueWelcomeTask($request, null, $currentUser, $database); |
|
69 | - } |
|
70 | - |
|
71 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
72 | - // be rolled back. |
|
73 | - |
|
74 | - $this->getNotificationHelper()->requestClosed($request, $template->getName()); |
|
75 | - SessionAlert::success("Request {$request->getId()} has been closed"); |
|
76 | - |
|
77 | - $this->sendMail($request, $template->getText(), $currentUser, false); |
|
78 | - |
|
79 | - $this->redirect(); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @param PdoDatabase $database |
|
84 | - * |
|
85 | - * @return EmailTemplate |
|
86 | - * @throws ApplicationLogicException |
|
87 | - */ |
|
88 | - protected function getTemplate(PdoDatabase $database) |
|
89 | - { |
|
90 | - $templateId = WebRequest::postInt('template'); |
|
91 | - if ($templateId === null) { |
|
92 | - throw new ApplicationLogicException('No template specified'); |
|
93 | - } |
|
94 | - |
|
95 | - /** @var EmailTemplate $template */ |
|
96 | - $template = EmailTemplate::getById($templateId, $database); |
|
97 | - if ($template === false || !$template->getActive()) { |
|
98 | - throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
99 | - } |
|
100 | - |
|
101 | - return $template; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @param Request $request |
|
106 | - * @param EmailTemplate $template |
|
107 | - * |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
111 | - { |
|
112 | - if ($this->checkEmailAlreadySent($request)) { |
|
113 | - $this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl'); |
|
114 | - |
|
115 | - return true; |
|
116 | - } |
|
117 | - |
|
118 | - return false; |
|
119 | - } |
|
120 | - |
|
121 | - protected function checkEmailAlreadySent(Request $request) |
|
122 | - { |
|
123 | - if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) { |
|
124 | - return true; |
|
125 | - } |
|
126 | - |
|
127 | - return false; |
|
128 | - } |
|
129 | - |
|
130 | - protected function checkReserveOverride(Request $request, User $currentUser) |
|
131 | - { |
|
132 | - $reservationId = $request->getReserved(); |
|
133 | - |
|
134 | - if ($reservationId !== 0 && $reservationId !== null) { |
|
135 | - if (!WebRequest::postBoolean('reserveOverride')) { |
|
136 | - if ($currentUser->getId() !== $reservationId) { |
|
137 | - return true; |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - return false; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @param Request $request |
|
147 | - * @param EmailTemplate $template |
|
148 | - * @param User $currentUser |
|
149 | - * @param PdoDatabase $database |
|
150 | - * |
|
151 | - * @return bool |
|
152 | - */ |
|
153 | - protected function confirmReserveOverride( |
|
154 | - Request $request, |
|
155 | - EmailTemplate $template, |
|
156 | - User $currentUser, |
|
157 | - PdoDatabase $database |
|
158 | - ) { |
|
159 | - if ($this->checkReserveOverride($request, $currentUser)) { |
|
160 | - $this->assign('reserveUser', User::getById($request->getReserved(), $database)->getUsername()); |
|
161 | - $this->showConfirmation($request, $template, 'close-confirmations/reserve-override.tpl'); |
|
162 | - |
|
163 | - return true; |
|
164 | - } |
|
165 | - |
|
166 | - return false; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * @param Request $request |
|
171 | - * @param EmailTemplate $template |
|
172 | - * |
|
173 | - * @return bool |
|
174 | - * @throws \Waca\Exceptions\CurlException |
|
175 | - */ |
|
176 | - protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
177 | - { |
|
178 | - if ($this->checkAccountCreated($request, $template)) { |
|
179 | - $this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl'); |
|
180 | - |
|
181 | - return true; |
|
182 | - } |
|
183 | - |
|
184 | - return false; |
|
185 | - } |
|
186 | - |
|
187 | - protected function checkAccountCreated(Request $request, EmailTemplate $template) |
|
188 | - { |
|
189 | - if ($template->getDefaultAction() === EmailTemplate::CREATED && !WebRequest::postBoolean('createOverride')) { |
|
190 | - $parameters = array( |
|
191 | - 'action' => 'query', |
|
192 | - 'list' => 'users', |
|
193 | - 'format' => 'php', |
|
194 | - 'ususers' => $request->getName(), |
|
195 | - ); |
|
196 | - |
|
197 | - $content = $this->getHttpHelper()->get($this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
198 | - $parameters); |
|
199 | - |
|
200 | - $apiResult = unserialize($content); |
|
201 | - $exists = !isset($apiResult['query']['users']['0']['missing']); |
|
202 | - |
|
203 | - if (!$exists) { |
|
204 | - return true; |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - return false; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * @param Request $request |
|
213 | - * @param string $mailText |
|
214 | - * @param User $currentUser |
|
215 | - * @param boolean $ccMailingList |
|
216 | - */ |
|
217 | - protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
218 | - { |
|
219 | - $requestEmailHelper = new RequestEmailHelper($this->getEmailHelper()); |
|
220 | - $requestEmailHelper->sendMail($request, $mailText, $currentUser, $ccMailingList); |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @param Request $request |
|
225 | - * @param EmailTemplate $template |
|
226 | - * @param string $templateName |
|
227 | - * |
|
228 | - * @throws Exception |
|
229 | - * @return void |
|
230 | - */ |
|
231 | - protected function showConfirmation(Request $request, EmailTemplate $template, $templateName) |
|
232 | - { |
|
233 | - $this->assignCSRFToken(); |
|
234 | - |
|
235 | - $this->assign('request', $request->getId()); |
|
236 | - $this->assign('template', $template->getId()); |
|
237 | - |
|
238 | - $this->assign('updateversion', $request->getUpdateVersion()); |
|
239 | - |
|
240 | - $this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false'); |
|
241 | - $this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false'); |
|
242 | - $this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false'); |
|
243 | - |
|
244 | - $this->setTemplate($templateName); |
|
245 | - } |
|
24 | + protected function main() |
|
25 | + { |
|
26 | + $this->processClose(); |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Main function for this page, when no specific actions are called. |
|
31 | + * @throws ApplicationLogicException |
|
32 | + */ |
|
33 | + final protected function processClose() |
|
34 | + { |
|
35 | + $this->checkPosted(); |
|
36 | + $database = $this->getDatabase(); |
|
37 | + |
|
38 | + $currentUser = User::getCurrent($database); |
|
39 | + $template = $this->getTemplate($database); |
|
40 | + $request = $this->getRequest($database); |
|
41 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
42 | + |
|
43 | + if ($request->getStatus() === 'Closed') { |
|
44 | + throw new ApplicationLogicException('Request is already closed'); |
|
45 | + } |
|
46 | + |
|
47 | + if ($this->confirmEmailAlreadySent($request, $template)) { |
|
48 | + return; |
|
49 | + } |
|
50 | + |
|
51 | + if ($this->confirmReserveOverride($request, $template, $currentUser, $database)) { |
|
52 | + return; |
|
53 | + } |
|
54 | + |
|
55 | + if ($this->confirmAccountCreated($request, $template)) { |
|
56 | + return; |
|
57 | + } |
|
58 | + |
|
59 | + // I think we're good here... |
|
60 | + $request->setStatus('Closed'); |
|
61 | + $request->setReserved(null); |
|
62 | + |
|
63 | + Logger::closeRequest($database, $request, $template->getId(), null); |
|
64 | + |
|
65 | + $request->save(); |
|
66 | + |
|
67 | + if ($currentUser->getWelcomeTemplate() !== null) { |
|
68 | + $this->enqueueWelcomeTask($request, null, $currentUser, $database); |
|
69 | + } |
|
70 | + |
|
71 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
72 | + // be rolled back. |
|
73 | + |
|
74 | + $this->getNotificationHelper()->requestClosed($request, $template->getName()); |
|
75 | + SessionAlert::success("Request {$request->getId()} has been closed"); |
|
76 | + |
|
77 | + $this->sendMail($request, $template->getText(), $currentUser, false); |
|
78 | + |
|
79 | + $this->redirect(); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @param PdoDatabase $database |
|
84 | + * |
|
85 | + * @return EmailTemplate |
|
86 | + * @throws ApplicationLogicException |
|
87 | + */ |
|
88 | + protected function getTemplate(PdoDatabase $database) |
|
89 | + { |
|
90 | + $templateId = WebRequest::postInt('template'); |
|
91 | + if ($templateId === null) { |
|
92 | + throw new ApplicationLogicException('No template specified'); |
|
93 | + } |
|
94 | + |
|
95 | + /** @var EmailTemplate $template */ |
|
96 | + $template = EmailTemplate::getById($templateId, $database); |
|
97 | + if ($template === false || !$template->getActive()) { |
|
98 | + throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
99 | + } |
|
100 | + |
|
101 | + return $template; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @param Request $request |
|
106 | + * @param EmailTemplate $template |
|
107 | + * |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
111 | + { |
|
112 | + if ($this->checkEmailAlreadySent($request)) { |
|
113 | + $this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl'); |
|
114 | + |
|
115 | + return true; |
|
116 | + } |
|
117 | + |
|
118 | + return false; |
|
119 | + } |
|
120 | + |
|
121 | + protected function checkEmailAlreadySent(Request $request) |
|
122 | + { |
|
123 | + if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) { |
|
124 | + return true; |
|
125 | + } |
|
126 | + |
|
127 | + return false; |
|
128 | + } |
|
129 | + |
|
130 | + protected function checkReserveOverride(Request $request, User $currentUser) |
|
131 | + { |
|
132 | + $reservationId = $request->getReserved(); |
|
133 | + |
|
134 | + if ($reservationId !== 0 && $reservationId !== null) { |
|
135 | + if (!WebRequest::postBoolean('reserveOverride')) { |
|
136 | + if ($currentUser->getId() !== $reservationId) { |
|
137 | + return true; |
|
138 | + } |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + return false; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @param Request $request |
|
147 | + * @param EmailTemplate $template |
|
148 | + * @param User $currentUser |
|
149 | + * @param PdoDatabase $database |
|
150 | + * |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | + protected function confirmReserveOverride( |
|
154 | + Request $request, |
|
155 | + EmailTemplate $template, |
|
156 | + User $currentUser, |
|
157 | + PdoDatabase $database |
|
158 | + ) { |
|
159 | + if ($this->checkReserveOverride($request, $currentUser)) { |
|
160 | + $this->assign('reserveUser', User::getById($request->getReserved(), $database)->getUsername()); |
|
161 | + $this->showConfirmation($request, $template, 'close-confirmations/reserve-override.tpl'); |
|
162 | + |
|
163 | + return true; |
|
164 | + } |
|
165 | + |
|
166 | + return false; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * @param Request $request |
|
171 | + * @param EmailTemplate $template |
|
172 | + * |
|
173 | + * @return bool |
|
174 | + * @throws \Waca\Exceptions\CurlException |
|
175 | + */ |
|
176 | + protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
177 | + { |
|
178 | + if ($this->checkAccountCreated($request, $template)) { |
|
179 | + $this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl'); |
|
180 | + |
|
181 | + return true; |
|
182 | + } |
|
183 | + |
|
184 | + return false; |
|
185 | + } |
|
186 | + |
|
187 | + protected function checkAccountCreated(Request $request, EmailTemplate $template) |
|
188 | + { |
|
189 | + if ($template->getDefaultAction() === EmailTemplate::CREATED && !WebRequest::postBoolean('createOverride')) { |
|
190 | + $parameters = array( |
|
191 | + 'action' => 'query', |
|
192 | + 'list' => 'users', |
|
193 | + 'format' => 'php', |
|
194 | + 'ususers' => $request->getName(), |
|
195 | + ); |
|
196 | + |
|
197 | + $content = $this->getHttpHelper()->get($this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
198 | + $parameters); |
|
199 | + |
|
200 | + $apiResult = unserialize($content); |
|
201 | + $exists = !isset($apiResult['query']['users']['0']['missing']); |
|
202 | + |
|
203 | + if (!$exists) { |
|
204 | + return true; |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + return false; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * @param Request $request |
|
213 | + * @param string $mailText |
|
214 | + * @param User $currentUser |
|
215 | + * @param boolean $ccMailingList |
|
216 | + */ |
|
217 | + protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
218 | + { |
|
219 | + $requestEmailHelper = new RequestEmailHelper($this->getEmailHelper()); |
|
220 | + $requestEmailHelper->sendMail($request, $mailText, $currentUser, $ccMailingList); |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @param Request $request |
|
225 | + * @param EmailTemplate $template |
|
226 | + * @param string $templateName |
|
227 | + * |
|
228 | + * @throws Exception |
|
229 | + * @return void |
|
230 | + */ |
|
231 | + protected function showConfirmation(Request $request, EmailTemplate $template, $templateName) |
|
232 | + { |
|
233 | + $this->assignCSRFToken(); |
|
234 | + |
|
235 | + $this->assign('request', $request->getId()); |
|
236 | + $this->assign('template', $template->getId()); |
|
237 | + |
|
238 | + $this->assign('updateversion', $request->getUpdateVersion()); |
|
239 | + |
|
240 | + $this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false'); |
|
241 | + $this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false'); |
|
242 | + $this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false'); |
|
243 | + |
|
244 | + $this->setTemplate($templateName); |
|
245 | + } |
|
246 | 246 | } |
@@ -19,54 +19,54 @@ |
||
19 | 19 | |
20 | 20 | abstract class RequestActionBase extends InternalPageBase |
21 | 21 | { |
22 | - /** |
|
23 | - * @param PdoDatabase $database |
|
24 | - * |
|
25 | - * @return Request |
|
26 | - * @throws ApplicationLogicException |
|
27 | - */ |
|
28 | - protected function getRequest(PdoDatabase $database) |
|
29 | - { |
|
30 | - $requestId = WebRequest::postInt('request'); |
|
31 | - if ($requestId === null) { |
|
32 | - throw new ApplicationLogicException('Request ID not found'); |
|
33 | - } |
|
22 | + /** |
|
23 | + * @param PdoDatabase $database |
|
24 | + * |
|
25 | + * @return Request |
|
26 | + * @throws ApplicationLogicException |
|
27 | + */ |
|
28 | + protected function getRequest(PdoDatabase $database) |
|
29 | + { |
|
30 | + $requestId = WebRequest::postInt('request'); |
|
31 | + if ($requestId === null) { |
|
32 | + throw new ApplicationLogicException('Request ID not found'); |
|
33 | + } |
|
34 | 34 | |
35 | - /** @var Request $request */ |
|
36 | - $request = Request::getById($requestId, $database); |
|
35 | + /** @var Request $request */ |
|
36 | + $request = Request::getById($requestId, $database); |
|
37 | 37 | |
38 | - if ($request === false) { |
|
39 | - throw new ApplicationLogicException('Request not found'); |
|
40 | - } |
|
38 | + if ($request === false) { |
|
39 | + throw new ApplicationLogicException('Request not found'); |
|
40 | + } |
|
41 | 41 | |
42 | - return $request; |
|
43 | - } |
|
42 | + return $request; |
|
43 | + } |
|
44 | 44 | |
45 | - final protected function checkPosted() |
|
46 | - { |
|
47 | - // if the request was not posted, send the user away. |
|
48 | - if (!WebRequest::wasPosted()) { |
|
49 | - throw new ApplicationLogicException('This page does not support GET methods.'); |
|
50 | - } |
|
45 | + final protected function checkPosted() |
|
46 | + { |
|
47 | + // if the request was not posted, send the user away. |
|
48 | + if (!WebRequest::wasPosted()) { |
|
49 | + throw new ApplicationLogicException('This page does not support GET methods.'); |
|
50 | + } |
|
51 | 51 | |
52 | - // validate the CSRF token |
|
53 | - $this->validateCSRFToken(); |
|
54 | - } |
|
52 | + // validate the CSRF token |
|
53 | + $this->validateCSRFToken(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param Request $request |
|
58 | - * @param $parentTaskId |
|
59 | - * @param User $user |
|
60 | - * @param PdoDatabase $database |
|
61 | - */ |
|
62 | - protected function enqueueWelcomeTask(Request $request, $parentTaskId, User $user, PdoDatabase $database) |
|
63 | - { |
|
64 | - $welcomeTask = new JobQueue(); |
|
65 | - $welcomeTask->setTask(WelcomeUserTask::class); |
|
66 | - $welcomeTask->setRequest($request->getId()); |
|
67 | - $welcomeTask->setParent($parentTaskId); |
|
68 | - $welcomeTask->setTriggerUserId($user->getId()); |
|
69 | - $welcomeTask->setDatabase($database); |
|
70 | - $welcomeTask->save(); |
|
71 | - } |
|
56 | + /** |
|
57 | + * @param Request $request |
|
58 | + * @param $parentTaskId |
|
59 | + * @param User $user |
|
60 | + * @param PdoDatabase $database |
|
61 | + */ |
|
62 | + protected function enqueueWelcomeTask(Request $request, $parentTaskId, User $user, PdoDatabase $database) |
|
63 | + { |
|
64 | + $welcomeTask = new JobQueue(); |
|
65 | + $welcomeTask->setTask(WelcomeUserTask::class); |
|
66 | + $welcomeTask->setRequest($request->getId()); |
|
67 | + $welcomeTask->setParent($parentTaskId); |
|
68 | + $welcomeTask->setTriggerUserId($user->getId()); |
|
69 | + $welcomeTask->setDatabase($database); |
|
70 | + $welcomeTask->save(); |
|
71 | + } |
|
72 | 72 | } |
73 | 73 | \ No newline at end of file |
@@ -15,22 +15,22 @@ |
||
15 | 15 | |
16 | 16 | class PageDropRequest extends PageCloseRequest |
17 | 17 | { |
18 | - protected function getTemplate(PdoDatabase $database) |
|
19 | - { |
|
20 | - return EmailTemplate::getDroppedTemplate(); |
|
21 | - } |
|
18 | + protected function getTemplate(PdoDatabase $database) |
|
19 | + { |
|
20 | + return EmailTemplate::getDroppedTemplate(); |
|
21 | + } |
|
22 | 22 | |
23 | - protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
24 | - { |
|
25 | - return false; |
|
26 | - } |
|
23 | + protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
24 | + { |
|
25 | + return false; |
|
26 | + } |
|
27 | 27 | |
28 | - protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
29 | - { |
|
30 | - return false; |
|
31 | - } |
|
28 | + protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
29 | + { |
|
30 | + return false; |
|
31 | + } |
|
32 | 32 | |
33 | - protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
34 | - { |
|
35 | - } |
|
33 | + protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
34 | + { |
|
35 | + } |
|
36 | 36 | } |
37 | 37 | \ No newline at end of file |
@@ -34,151 +34,151 @@ |
||
34 | 34 | */ |
35 | 35 | class PageCreateRequest extends RequestActionBase |
36 | 36 | { |
37 | - /** |
|
38 | - * Main function for this page, when no specific actions are called. |
|
39 | - * @return void |
|
40 | - * @throws AccessDeniedException |
|
41 | - * @throws ApplicationLogicException |
|
42 | - */ |
|
43 | - protected function main() |
|
44 | - { |
|
45 | - $this->checkPosted(); |
|
46 | - |
|
47 | - $database = $this->getDatabase(); |
|
48 | - |
|
49 | - $request = $this->getRequest($database); |
|
50 | - $template = $this->getTemplate($database); |
|
51 | - $creationMode = $this->getCreationMode(); |
|
52 | - $user = User::getCurrent($database); |
|
53 | - |
|
54 | - $secMgr = $this->getSecurityManager(); |
|
55 | - if ($secMgr->allows('RequestCreation', User::CREATION_BOT, $user) !== SecurityManager::ALLOWED |
|
56 | - && $creationMode === 'bot' |
|
57 | - ) { |
|
58 | - throw new AccessDeniedException($secMgr); |
|
59 | - } |
|
60 | - elseif ($secMgr->allows('RequestCreation', User::CREATION_OAUTH, $user) !== SecurityManager::ALLOWED |
|
61 | - && $creationMode === 'oauth' |
|
62 | - ) { |
|
63 | - throw new AccessDeniedException($secMgr); |
|
64 | - } |
|
65 | - |
|
66 | - if ($request->getEmailSent()) { |
|
67 | - throw new ApplicationLogicException('This requester has already had an email sent to them. Please fall back to manual creation'); |
|
68 | - } |
|
69 | - |
|
70 | - $request->setStatus(RequestStatus::JOBQUEUE); |
|
71 | - $request->setReserved(null); |
|
72 | - $request->save(); |
|
73 | - |
|
74 | - Logger::enqueuedJobQueue($database, $request); |
|
75 | - |
|
76 | - $creationTaskId = $this->enqueueCreationTask($creationMode, $request, $template, $user, $database); |
|
77 | - |
|
78 | - if ($user->getWelcomeTemplate() !== null) { |
|
79 | - $this->enqueueWelcomeTask($request, $creationTaskId, $user, $database); |
|
80 | - } |
|
81 | - |
|
82 | - SessionAlert::success("Request {$request->getId()} has been queued for autocreation"); |
|
83 | - |
|
84 | - $this->redirect(); |
|
85 | - } |
|
86 | - |
|
87 | - protected function getCreationMode() |
|
88 | - { |
|
89 | - $creationMode = WebRequest::postString('mode'); |
|
90 | - if ($creationMode !== 'oauth' && $creationMode !== 'bot') { |
|
91 | - throw new ApplicationLogicException('Unknown creation mode'); |
|
92 | - } |
|
93 | - |
|
94 | - return $creationMode; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @param PdoDatabase $database |
|
99 | - * |
|
100 | - * @return EmailTemplate |
|
101 | - * @throws ApplicationLogicException |
|
102 | - */ |
|
103 | - protected function getTemplate(PdoDatabase $database) |
|
104 | - { |
|
105 | - $templateId = WebRequest::postInt('template'); |
|
106 | - if ($templateId === null) { |
|
107 | - throw new ApplicationLogicException('No template specified'); |
|
108 | - } |
|
109 | - |
|
110 | - /** @var EmailTemplate $template */ |
|
111 | - $template = EmailTemplate::getById($templateId, $database); |
|
112 | - if ($template === false || !$template->getActive()) { |
|
113 | - throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
114 | - } |
|
115 | - |
|
116 | - if ($template->getDefaultAction() !== EmailTemplate::CREATED) { |
|
117 | - throw new ApplicationLogicException('Specified template is not a creation template!'); |
|
118 | - } |
|
119 | - |
|
120 | - return $template; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @param PdoDatabase $database |
|
125 | - * |
|
126 | - * @return Request |
|
127 | - * @throws ApplicationLogicException |
|
128 | - */ |
|
129 | - protected function getRequest(PdoDatabase $database) |
|
130 | - { |
|
131 | - $request = parent::getRequest($database); |
|
132 | - |
|
133 | - if ($request->getStatus() == RequestStatus::CLOSED) { |
|
134 | - throw new ApplicationLogicException('Request is already closed'); |
|
135 | - } |
|
136 | - |
|
137 | - return $request; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param $creationMode |
|
142 | - * @param Request $request |
|
143 | - * @param EmailTemplate $template |
|
144 | - * @param User $user |
|
145 | - * |
|
146 | - * @param PdoDatabase $database |
|
147 | - * |
|
148 | - * @return int |
|
149 | - * @throws ApplicationLogicException |
|
150 | - */ |
|
151 | - protected function enqueueCreationTask( |
|
152 | - $creationMode, |
|
153 | - Request $request, |
|
154 | - EmailTemplate $template, |
|
155 | - User $user, |
|
156 | - PdoDatabase $database |
|
157 | - ) { |
|
158 | - $creationTaskClass = null; |
|
159 | - |
|
160 | - if ($creationMode == "oauth") { |
|
161 | - $creationTaskClass = UserCreationTask::class; |
|
162 | - } |
|
163 | - |
|
164 | - if ($creationMode == "bot") { |
|
165 | - $creationTaskClass = BotCreationTask::class; |
|
166 | - } |
|
167 | - |
|
168 | - if ($creationTaskClass === null) { |
|
169 | - throw new ApplicationLogicException('Cannot determine creation mode'); |
|
170 | - } |
|
171 | - |
|
172 | - $creationTask = new JobQueue(); |
|
173 | - $creationTask->setTask($creationTaskClass); |
|
174 | - $creationTask->setRequest($request->getId()); |
|
175 | - $creationTask->setEmailTemplate($template->getId()); |
|
176 | - $creationTask->setTriggerUserId($user->getId()); |
|
177 | - $creationTask->setDatabase($database); |
|
178 | - $creationTask->save(); |
|
179 | - |
|
180 | - $creationTaskId = $creationTask->getId(); |
|
181 | - |
|
182 | - return $creationTaskId; |
|
183 | - } |
|
37 | + /** |
|
38 | + * Main function for this page, when no specific actions are called. |
|
39 | + * @return void |
|
40 | + * @throws AccessDeniedException |
|
41 | + * @throws ApplicationLogicException |
|
42 | + */ |
|
43 | + protected function main() |
|
44 | + { |
|
45 | + $this->checkPosted(); |
|
46 | + |
|
47 | + $database = $this->getDatabase(); |
|
48 | + |
|
49 | + $request = $this->getRequest($database); |
|
50 | + $template = $this->getTemplate($database); |
|
51 | + $creationMode = $this->getCreationMode(); |
|
52 | + $user = User::getCurrent($database); |
|
53 | + |
|
54 | + $secMgr = $this->getSecurityManager(); |
|
55 | + if ($secMgr->allows('RequestCreation', User::CREATION_BOT, $user) !== SecurityManager::ALLOWED |
|
56 | + && $creationMode === 'bot' |
|
57 | + ) { |
|
58 | + throw new AccessDeniedException($secMgr); |
|
59 | + } |
|
60 | + elseif ($secMgr->allows('RequestCreation', User::CREATION_OAUTH, $user) !== SecurityManager::ALLOWED |
|
61 | + && $creationMode === 'oauth' |
|
62 | + ) { |
|
63 | + throw new AccessDeniedException($secMgr); |
|
64 | + } |
|
65 | + |
|
66 | + if ($request->getEmailSent()) { |
|
67 | + throw new ApplicationLogicException('This requester has already had an email sent to them. Please fall back to manual creation'); |
|
68 | + } |
|
69 | + |
|
70 | + $request->setStatus(RequestStatus::JOBQUEUE); |
|
71 | + $request->setReserved(null); |
|
72 | + $request->save(); |
|
73 | + |
|
74 | + Logger::enqueuedJobQueue($database, $request); |
|
75 | + |
|
76 | + $creationTaskId = $this->enqueueCreationTask($creationMode, $request, $template, $user, $database); |
|
77 | + |
|
78 | + if ($user->getWelcomeTemplate() !== null) { |
|
79 | + $this->enqueueWelcomeTask($request, $creationTaskId, $user, $database); |
|
80 | + } |
|
81 | + |
|
82 | + SessionAlert::success("Request {$request->getId()} has been queued for autocreation"); |
|
83 | + |
|
84 | + $this->redirect(); |
|
85 | + } |
|
86 | + |
|
87 | + protected function getCreationMode() |
|
88 | + { |
|
89 | + $creationMode = WebRequest::postString('mode'); |
|
90 | + if ($creationMode !== 'oauth' && $creationMode !== 'bot') { |
|
91 | + throw new ApplicationLogicException('Unknown creation mode'); |
|
92 | + } |
|
93 | + |
|
94 | + return $creationMode; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @param PdoDatabase $database |
|
99 | + * |
|
100 | + * @return EmailTemplate |
|
101 | + * @throws ApplicationLogicException |
|
102 | + */ |
|
103 | + protected function getTemplate(PdoDatabase $database) |
|
104 | + { |
|
105 | + $templateId = WebRequest::postInt('template'); |
|
106 | + if ($templateId === null) { |
|
107 | + throw new ApplicationLogicException('No template specified'); |
|
108 | + } |
|
109 | + |
|
110 | + /** @var EmailTemplate $template */ |
|
111 | + $template = EmailTemplate::getById($templateId, $database); |
|
112 | + if ($template === false || !$template->getActive()) { |
|
113 | + throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
114 | + } |
|
115 | + |
|
116 | + if ($template->getDefaultAction() !== EmailTemplate::CREATED) { |
|
117 | + throw new ApplicationLogicException('Specified template is not a creation template!'); |
|
118 | + } |
|
119 | + |
|
120 | + return $template; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @param PdoDatabase $database |
|
125 | + * |
|
126 | + * @return Request |
|
127 | + * @throws ApplicationLogicException |
|
128 | + */ |
|
129 | + protected function getRequest(PdoDatabase $database) |
|
130 | + { |
|
131 | + $request = parent::getRequest($database); |
|
132 | + |
|
133 | + if ($request->getStatus() == RequestStatus::CLOSED) { |
|
134 | + throw new ApplicationLogicException('Request is already closed'); |
|
135 | + } |
|
136 | + |
|
137 | + return $request; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param $creationMode |
|
142 | + * @param Request $request |
|
143 | + * @param EmailTemplate $template |
|
144 | + * @param User $user |
|
145 | + * |
|
146 | + * @param PdoDatabase $database |
|
147 | + * |
|
148 | + * @return int |
|
149 | + * @throws ApplicationLogicException |
|
150 | + */ |
|
151 | + protected function enqueueCreationTask( |
|
152 | + $creationMode, |
|
153 | + Request $request, |
|
154 | + EmailTemplate $template, |
|
155 | + User $user, |
|
156 | + PdoDatabase $database |
|
157 | + ) { |
|
158 | + $creationTaskClass = null; |
|
159 | + |
|
160 | + if ($creationMode == "oauth") { |
|
161 | + $creationTaskClass = UserCreationTask::class; |
|
162 | + } |
|
163 | + |
|
164 | + if ($creationMode == "bot") { |
|
165 | + $creationTaskClass = BotCreationTask::class; |
|
166 | + } |
|
167 | + |
|
168 | + if ($creationTaskClass === null) { |
|
169 | + throw new ApplicationLogicException('Cannot determine creation mode'); |
|
170 | + } |
|
171 | + |
|
172 | + $creationTask = new JobQueue(); |
|
173 | + $creationTask->setTask($creationTaskClass); |
|
174 | + $creationTask->setRequest($request->getId()); |
|
175 | + $creationTask->setEmailTemplate($template->getId()); |
|
176 | + $creationTask->setTriggerUserId($user->getId()); |
|
177 | + $creationTask->setDatabase($database); |
|
178 | + $creationTask->save(); |
|
179 | + |
|
180 | + $creationTaskId = $creationTask->getId(); |
|
181 | + |
|
182 | + return $creationTaskId; |
|
183 | + } |
|
184 | 184 | } |
185 | 185 | \ No newline at end of file |
@@ -20,200 +20,200 @@ |
||
20 | 20 | |
21 | 21 | abstract class PageRegisterBase extends InternalPageBase |
22 | 22 | { |
23 | - /** |
|
24 | - * Main function for this page, when no specific actions are called. |
|
25 | - */ |
|
26 | - protected function main() |
|
27 | - { |
|
28 | - $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup(); |
|
29 | - |
|
30 | - // Dual-mode page |
|
31 | - if (WebRequest::wasPosted()) { |
|
32 | - $this->validateCSRFToken(); |
|
33 | - |
|
34 | - try { |
|
35 | - $this->handlePost($useOAuthSignup); |
|
36 | - } |
|
37 | - catch (ApplicationLogicException $ex) { |
|
38 | - SessionAlert::error($ex->getMessage()); |
|
39 | - $this->redirect('register'); |
|
40 | - } |
|
41 | - } |
|
42 | - else { |
|
43 | - $this->assignCSRFToken(); |
|
44 | - $this->assign("useOAuthSignup", $useOAuthSignup); |
|
45 | - $this->setTemplate($this->getRegistrationTemplate()); |
|
46 | - } |
|
47 | - } |
|
48 | - |
|
49 | - protected abstract function getRegistrationTemplate(); |
|
50 | - |
|
51 | - protected function isProtectedPage() |
|
52 | - { |
|
53 | - return false; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param string $emailAddress |
|
58 | - * |
|
59 | - * @throws ApplicationLogicException |
|
60 | - */ |
|
61 | - protected function validateUniqueEmail($emailAddress) |
|
62 | - { |
|
63 | - $query = 'SELECT COUNT(id) FROM user WHERE email = :email'; |
|
64 | - $statement = $this->getDatabase()->prepare($query); |
|
65 | - $statement->execute(array(':email' => $emailAddress)); |
|
66 | - |
|
67 | - if ($statement->fetchColumn() > 0) { |
|
68 | - throw new ApplicationLogicException('That email address is already in use on this system.'); |
|
69 | - } |
|
70 | - |
|
71 | - $statement->closeCursor(); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @param $emailAddress |
|
76 | - * @param $password |
|
77 | - * @param $username |
|
78 | - * @param $useOAuthSignup |
|
79 | - * @param $confirmationId |
|
80 | - * @param $onwikiUsername |
|
81 | - * |
|
82 | - * @throws ApplicationLogicException |
|
83 | - */ |
|
84 | - protected function validateRequest( |
|
85 | - $emailAddress, |
|
86 | - $password, |
|
87 | - $username, |
|
88 | - $useOAuthSignup, |
|
89 | - $confirmationId, |
|
90 | - $onwikiUsername |
|
91 | - ) { |
|
92 | - if (!WebRequest::postBoolean('guidelines')) { |
|
93 | - throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.'); |
|
94 | - } |
|
95 | - |
|
96 | - $this->validateGeneralInformation($emailAddress, $password, $username); |
|
97 | - $this->validateUniqueEmail($emailAddress); |
|
98 | - $this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param $useOAuthSignup |
|
103 | - * @param $confirmationId |
|
104 | - * @param $onwikiUsername |
|
105 | - * |
|
106 | - * @throws ApplicationLogicException |
|
107 | - */ |
|
108 | - protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername) |
|
109 | - { |
|
110 | - if (!$useOAuthSignup) { |
|
111 | - if ($confirmationId === null || $confirmationId <= 0) { |
|
112 | - throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.'); |
|
113 | - } |
|
114 | - |
|
115 | - if ($onwikiUsername === null) { |
|
116 | - throw new ApplicationLogicException('Please specify your on-wiki username.'); |
|
117 | - } |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @param $emailAddress |
|
123 | - * @param $password |
|
124 | - * @param $username |
|
125 | - * |
|
126 | - * @throws ApplicationLogicException |
|
127 | - */ |
|
128 | - protected function validateGeneralInformation($emailAddress, $password, $username) |
|
129 | - { |
|
130 | - if ($emailAddress === null) { |
|
131 | - throw new ApplicationLogicException('Your email address appears to be invalid!'); |
|
132 | - } |
|
133 | - |
|
134 | - if ($password !== WebRequest::postString('pass2')) { |
|
135 | - throw new ApplicationLogicException('Your passwords did not match, please try again.'); |
|
136 | - } |
|
137 | - |
|
138 | - if (User::getByUsername($username, $this->getDatabase()) !== false) { |
|
139 | - throw new ApplicationLogicException('That username is already in use on this system.'); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param $useOAuthSignup |
|
145 | - * |
|
146 | - * @throws ApplicationLogicException |
|
147 | - * @throws \Exception |
|
148 | - */ |
|
149 | - protected function handlePost($useOAuthSignup) |
|
150 | - { |
|
151 | - // Get the data |
|
152 | - $emailAddress = WebRequest::postEmail('email'); |
|
153 | - $password = WebRequest::postString('pass'); |
|
154 | - $username = WebRequest::postString('name'); |
|
155 | - |
|
156 | - // Only set if OAuth is disabled |
|
157 | - $confirmationId = WebRequest::postInt('conf_revid'); |
|
158 | - $onwikiUsername = WebRequest::postString('wname'); |
|
159 | - |
|
160 | - // Do some validation |
|
161 | - $this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId, |
|
162 | - $onwikiUsername); |
|
163 | - |
|
164 | - $database = $this->getDatabase(); |
|
165 | - |
|
166 | - $user = new User(); |
|
167 | - $user->setDatabase($database); |
|
168 | - |
|
169 | - $user->setUsername($username); |
|
170 | - $user->setEmail($emailAddress); |
|
171 | - |
|
172 | - if (!$useOAuthSignup) { |
|
173 | - $user->setOnWikiName($onwikiUsername); |
|
174 | - $user->setConfirmationDiff($confirmationId); |
|
175 | - } |
|
176 | - |
|
177 | - $user->save(); |
|
178 | - |
|
179 | - $passwordCredentialProvider = new PasswordCredentialProvider($database, $this->getSiteConfiguration()); |
|
180 | - $passwordCredentialProvider->setCredential($user, 1, $password); |
|
181 | - |
|
182 | - $defaultRole = $this->getDefaultRole(); |
|
183 | - |
|
184 | - $role = new UserRole(); |
|
185 | - $role->setDatabase($database); |
|
186 | - $role->setUser($user->getId()); |
|
187 | - $role->setRole($defaultRole); |
|
188 | - $role->save(); |
|
189 | - |
|
190 | - // Log now to get the signup date. |
|
191 | - Logger::newUser($database, $user); |
|
192 | - Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array()); |
|
193 | - |
|
194 | - if ($useOAuthSignup) { |
|
195 | - $oauthProtocolHelper = $this->getOAuthProtocolHelper(); |
|
196 | - $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration()); |
|
197 | - |
|
198 | - $authoriseUrl = $oauth->getRequestToken(); |
|
199 | - WebRequest::setPartialLogin($user); |
|
200 | - $this->redirectUrl($authoriseUrl); |
|
201 | - } |
|
202 | - else { |
|
203 | - // only notify if we're not using the oauth signup. |
|
204 | - $this->getNotificationHelper()->userNew($user); |
|
205 | - WebRequest::setLoggedInUser($user); |
|
206 | - $this->redirect('preferences'); |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - protected abstract function getDefaultRole(); |
|
211 | - |
|
212 | - /** |
|
213 | - * Entry point for registration complete |
|
214 | - */ |
|
215 | - protected function done() |
|
216 | - { |
|
217 | - $this->setTemplate('registration/alert-registrationcomplete.tpl'); |
|
218 | - } |
|
23 | + /** |
|
24 | + * Main function for this page, when no specific actions are called. |
|
25 | + */ |
|
26 | + protected function main() |
|
27 | + { |
|
28 | + $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup(); |
|
29 | + |
|
30 | + // Dual-mode page |
|
31 | + if (WebRequest::wasPosted()) { |
|
32 | + $this->validateCSRFToken(); |
|
33 | + |
|
34 | + try { |
|
35 | + $this->handlePost($useOAuthSignup); |
|
36 | + } |
|
37 | + catch (ApplicationLogicException $ex) { |
|
38 | + SessionAlert::error($ex->getMessage()); |
|
39 | + $this->redirect('register'); |
|
40 | + } |
|
41 | + } |
|
42 | + else { |
|
43 | + $this->assignCSRFToken(); |
|
44 | + $this->assign("useOAuthSignup", $useOAuthSignup); |
|
45 | + $this->setTemplate($this->getRegistrationTemplate()); |
|
46 | + } |
|
47 | + } |
|
48 | + |
|
49 | + protected abstract function getRegistrationTemplate(); |
|
50 | + |
|
51 | + protected function isProtectedPage() |
|
52 | + { |
|
53 | + return false; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param string $emailAddress |
|
58 | + * |
|
59 | + * @throws ApplicationLogicException |
|
60 | + */ |
|
61 | + protected function validateUniqueEmail($emailAddress) |
|
62 | + { |
|
63 | + $query = 'SELECT COUNT(id) FROM user WHERE email = :email'; |
|
64 | + $statement = $this->getDatabase()->prepare($query); |
|
65 | + $statement->execute(array(':email' => $emailAddress)); |
|
66 | + |
|
67 | + if ($statement->fetchColumn() > 0) { |
|
68 | + throw new ApplicationLogicException('That email address is already in use on this system.'); |
|
69 | + } |
|
70 | + |
|
71 | + $statement->closeCursor(); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @param $emailAddress |
|
76 | + * @param $password |
|
77 | + * @param $username |
|
78 | + * @param $useOAuthSignup |
|
79 | + * @param $confirmationId |
|
80 | + * @param $onwikiUsername |
|
81 | + * |
|
82 | + * @throws ApplicationLogicException |
|
83 | + */ |
|
84 | + protected function validateRequest( |
|
85 | + $emailAddress, |
|
86 | + $password, |
|
87 | + $username, |
|
88 | + $useOAuthSignup, |
|
89 | + $confirmationId, |
|
90 | + $onwikiUsername |
|
91 | + ) { |
|
92 | + if (!WebRequest::postBoolean('guidelines')) { |
|
93 | + throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.'); |
|
94 | + } |
|
95 | + |
|
96 | + $this->validateGeneralInformation($emailAddress, $password, $username); |
|
97 | + $this->validateUniqueEmail($emailAddress); |
|
98 | + $this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param $useOAuthSignup |
|
103 | + * @param $confirmationId |
|
104 | + * @param $onwikiUsername |
|
105 | + * |
|
106 | + * @throws ApplicationLogicException |
|
107 | + */ |
|
108 | + protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername) |
|
109 | + { |
|
110 | + if (!$useOAuthSignup) { |
|
111 | + if ($confirmationId === null || $confirmationId <= 0) { |
|
112 | + throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.'); |
|
113 | + } |
|
114 | + |
|
115 | + if ($onwikiUsername === null) { |
|
116 | + throw new ApplicationLogicException('Please specify your on-wiki username.'); |
|
117 | + } |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @param $emailAddress |
|
123 | + * @param $password |
|
124 | + * @param $username |
|
125 | + * |
|
126 | + * @throws ApplicationLogicException |
|
127 | + */ |
|
128 | + protected function validateGeneralInformation($emailAddress, $password, $username) |
|
129 | + { |
|
130 | + if ($emailAddress === null) { |
|
131 | + throw new ApplicationLogicException('Your email address appears to be invalid!'); |
|
132 | + } |
|
133 | + |
|
134 | + if ($password !== WebRequest::postString('pass2')) { |
|
135 | + throw new ApplicationLogicException('Your passwords did not match, please try again.'); |
|
136 | + } |
|
137 | + |
|
138 | + if (User::getByUsername($username, $this->getDatabase()) !== false) { |
|
139 | + throw new ApplicationLogicException('That username is already in use on this system.'); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param $useOAuthSignup |
|
145 | + * |
|
146 | + * @throws ApplicationLogicException |
|
147 | + * @throws \Exception |
|
148 | + */ |
|
149 | + protected function handlePost($useOAuthSignup) |
|
150 | + { |
|
151 | + // Get the data |
|
152 | + $emailAddress = WebRequest::postEmail('email'); |
|
153 | + $password = WebRequest::postString('pass'); |
|
154 | + $username = WebRequest::postString('name'); |
|
155 | + |
|
156 | + // Only set if OAuth is disabled |
|
157 | + $confirmationId = WebRequest::postInt('conf_revid'); |
|
158 | + $onwikiUsername = WebRequest::postString('wname'); |
|
159 | + |
|
160 | + // Do some validation |
|
161 | + $this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId, |
|
162 | + $onwikiUsername); |
|
163 | + |
|
164 | + $database = $this->getDatabase(); |
|
165 | + |
|
166 | + $user = new User(); |
|
167 | + $user->setDatabase($database); |
|
168 | + |
|
169 | + $user->setUsername($username); |
|
170 | + $user->setEmail($emailAddress); |
|
171 | + |
|
172 | + if (!$useOAuthSignup) { |
|
173 | + $user->setOnWikiName($onwikiUsername); |
|
174 | + $user->setConfirmationDiff($confirmationId); |
|
175 | + } |
|
176 | + |
|
177 | + $user->save(); |
|
178 | + |
|
179 | + $passwordCredentialProvider = new PasswordCredentialProvider($database, $this->getSiteConfiguration()); |
|
180 | + $passwordCredentialProvider->setCredential($user, 1, $password); |
|
181 | + |
|
182 | + $defaultRole = $this->getDefaultRole(); |
|
183 | + |
|
184 | + $role = new UserRole(); |
|
185 | + $role->setDatabase($database); |
|
186 | + $role->setUser($user->getId()); |
|
187 | + $role->setRole($defaultRole); |
|
188 | + $role->save(); |
|
189 | + |
|
190 | + // Log now to get the signup date. |
|
191 | + Logger::newUser($database, $user); |
|
192 | + Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array()); |
|
193 | + |
|
194 | + if ($useOAuthSignup) { |
|
195 | + $oauthProtocolHelper = $this->getOAuthProtocolHelper(); |
|
196 | + $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration()); |
|
197 | + |
|
198 | + $authoriseUrl = $oauth->getRequestToken(); |
|
199 | + WebRequest::setPartialLogin($user); |
|
200 | + $this->redirectUrl($authoriseUrl); |
|
201 | + } |
|
202 | + else { |
|
203 | + // only notify if we're not using the oauth signup. |
|
204 | + $this->getNotificationHelper()->userNew($user); |
|
205 | + WebRequest::setLoggedInUser($user); |
|
206 | + $this->redirect('preferences'); |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + protected abstract function getDefaultRole(); |
|
211 | + |
|
212 | + /** |
|
213 | + * Entry point for registration complete |
|
214 | + */ |
|
215 | + protected function done() |
|
216 | + { |
|
217 | + $this->setTemplate('registration/alert-registrationcomplete.tpl'); |
|
218 | + } |
|
219 | 219 | } |
@@ -20,60 +20,60 @@ discard block |
||
20 | 20 | |
21 | 21 | class PageMain extends InternalPageBase |
22 | 22 | { |
23 | - /** |
|
24 | - * Main function for this page, when no actions are called. |
|
25 | - */ |
|
26 | - protected function main() |
|
27 | - { |
|
28 | - $this->assignCSRFToken(); |
|
29 | - |
|
30 | - $config = $this->getSiteConfiguration(); |
|
31 | - $database = $this->getDatabase(); |
|
32 | - $currentUser = User::getCurrent($database); |
|
33 | - |
|
34 | - // general template configuration |
|
35 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
36 | - $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
37 | - |
|
38 | - // Get map of possible usernames |
|
39 | - $userList = UserSearchHelper::get($database)->withReservedRequest(); |
|
40 | - $this->assign('userList', $userList); |
|
41 | - |
|
42 | - $seeAllRequests = $this->barrierTest('seeAllRequests', $currentUser, PageViewRequest::class); |
|
43 | - |
|
44 | - // Fetch request data |
|
45 | - $requestSectionData = array(); |
|
46 | - if ($seeAllRequests) { |
|
47 | - $this->setupStatusSections($database, $config, $requestSectionData); |
|
48 | - $this->setupHospitalQueue($database, $config, $requestSectionData); |
|
49 | - $this->setupJobQueue($database, $config, $requestSectionData); |
|
50 | - } |
|
51 | - $this->setupLastFiveClosedData($database, $seeAllRequests); |
|
52 | - |
|
53 | - // Assign data to template |
|
54 | - $this->assign('requestSectionData', $requestSectionData); |
|
55 | - |
|
56 | - // Extra rights |
|
57 | - $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
58 | - $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
59 | - |
|
60 | - $this->setTemplate('mainpage/mainpage.tpl'); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * @param PdoDatabase $database |
|
65 | - * @param bool $seeAllRequests |
|
66 | - * |
|
67 | - * @internal param User $currentUser |
|
68 | - */ |
|
69 | - private function setupLastFiveClosedData(PdoDatabase $database, $seeAllRequests) |
|
70 | - { |
|
71 | - $this->assign('showLastFive', $seeAllRequests); |
|
72 | - if (!$seeAllRequests) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - $query = <<<SQL |
|
23 | + /** |
|
24 | + * Main function for this page, when no actions are called. |
|
25 | + */ |
|
26 | + protected function main() |
|
27 | + { |
|
28 | + $this->assignCSRFToken(); |
|
29 | + |
|
30 | + $config = $this->getSiteConfiguration(); |
|
31 | + $database = $this->getDatabase(); |
|
32 | + $currentUser = User::getCurrent($database); |
|
33 | + |
|
34 | + // general template configuration |
|
35 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
36 | + $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
37 | + |
|
38 | + // Get map of possible usernames |
|
39 | + $userList = UserSearchHelper::get($database)->withReservedRequest(); |
|
40 | + $this->assign('userList', $userList); |
|
41 | + |
|
42 | + $seeAllRequests = $this->barrierTest('seeAllRequests', $currentUser, PageViewRequest::class); |
|
43 | + |
|
44 | + // Fetch request data |
|
45 | + $requestSectionData = array(); |
|
46 | + if ($seeAllRequests) { |
|
47 | + $this->setupStatusSections($database, $config, $requestSectionData); |
|
48 | + $this->setupHospitalQueue($database, $config, $requestSectionData); |
|
49 | + $this->setupJobQueue($database, $config, $requestSectionData); |
|
50 | + } |
|
51 | + $this->setupLastFiveClosedData($database, $seeAllRequests); |
|
52 | + |
|
53 | + // Assign data to template |
|
54 | + $this->assign('requestSectionData', $requestSectionData); |
|
55 | + |
|
56 | + // Extra rights |
|
57 | + $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
58 | + $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
59 | + |
|
60 | + $this->setTemplate('mainpage/mainpage.tpl'); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * @param PdoDatabase $database |
|
65 | + * @param bool $seeAllRequests |
|
66 | + * |
|
67 | + * @internal param User $currentUser |
|
68 | + */ |
|
69 | + private function setupLastFiveClosedData(PdoDatabase $database, $seeAllRequests) |
|
70 | + { |
|
71 | + $this->assign('showLastFive', $seeAllRequests); |
|
72 | + if (!$seeAllRequests) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + $query = <<<SQL |
|
77 | 77 | SELECT request.id, request.name, request.updateversion |
78 | 78 | FROM request /* PageMain::main() */ |
79 | 79 | JOIN log ON log.objectid = request.id AND log.objecttype = 'Request' |
@@ -82,107 +82,107 @@ discard block |
||
82 | 82 | LIMIT 5; |
83 | 83 | SQL; |
84 | 84 | |
85 | - $statement = $database->prepare($query); |
|
86 | - $statement->execute(); |
|
87 | - |
|
88 | - $last5result = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
89 | - |
|
90 | - $this->assign('lastFive', $last5result); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param PdoDatabase $database |
|
95 | - * @param SiteConfiguration $config |
|
96 | - * @param $requestSectionData |
|
97 | - */ |
|
98 | - private function setupHospitalQueue( |
|
99 | - PdoDatabase $database, |
|
100 | - SiteConfiguration $config, |
|
101 | - &$requestSectionData |
|
102 | - ) { |
|
103 | - $search = RequestSearchHelper::get($database) |
|
104 | - ->limit($config->getMiserModeLimit()) |
|
105 | - ->excludingStatus('Closed') |
|
106 | - ->isHospitalised(); |
|
107 | - |
|
108 | - if ($config->getEmailConfirmationEnabled()) { |
|
109 | - $search->withConfirmedEmail(); |
|
110 | - } |
|
111 | - |
|
112 | - $results = $search->getRecordCount($requestCount)->fetch(); |
|
113 | - |
|
114 | - if($requestCount > 0) { |
|
115 | - $requestSectionData['Hospital - Requests failed auto-creation'] = array( |
|
116 | - 'requests' => $results, |
|
117 | - 'total' => $requestCount, |
|
118 | - 'api' => 'hospital', |
|
119 | - 'type' => 'hospital', |
|
120 | - 'special' => 'Job Queue', |
|
121 | - 'help' => 'This queue lists all the requests which have been attempted to be created in the background, but for which this has failed for one reason or another. Check the job queue to find the error. Requests here may need to be created manually, or it may be possible to re-queue the request for auto-creation by the tool, or it may have been created already. Use your own technical discretion here.' |
|
122 | - ); |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @param PdoDatabase $database |
|
128 | - * @param SiteConfiguration $config |
|
129 | - * @param $requestSectionData |
|
130 | - */ |
|
131 | - private function setupJobQueue( |
|
132 | - PdoDatabase $database, |
|
133 | - SiteConfiguration $config, |
|
134 | - &$requestSectionData |
|
135 | - ) { |
|
136 | - $search = RequestSearchHelper::get($database) |
|
137 | - ->limit($config->getMiserModeLimit()) |
|
138 | - ->byStatus(RequestStatus::JOBQUEUE); |
|
139 | - |
|
140 | - if ($config->getEmailConfirmationEnabled()) { |
|
141 | - $search->withConfirmedEmail(); |
|
142 | - } |
|
143 | - |
|
144 | - $results = $search->getRecordCount($requestCount)->fetch(); |
|
145 | - |
|
146 | - if($requestCount > 0) { |
|
147 | - $requestSectionData['Requests queued in the Job Queue'] = array( |
|
148 | - 'requests' => $results, |
|
149 | - 'total' => $requestCount, |
|
150 | - 'api' => 'JobQueue', |
|
151 | - 'type' => 'JobQueue', |
|
152 | - 'special' => 'Job Queue', |
|
153 | - 'help' => 'This section lists all the requests which are currently waiting to be created by the tool. Requests should automatically disappear from here within a few minutes.' |
|
154 | - ); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param PdoDatabase $database |
|
160 | - * @param SiteConfiguration $config |
|
161 | - * @param $requestSectionData |
|
162 | - */ |
|
163 | - private function setupStatusSections( |
|
164 | - PdoDatabase $database, |
|
165 | - SiteConfiguration $config, |
|
166 | - &$requestSectionData |
|
167 | - ) { |
|
168 | - $search = RequestSearchHelper::get($database)->limit($config->getMiserModeLimit())->notHospitalised(); |
|
169 | - |
|
170 | - if ($config->getEmailConfirmationEnabled()) { |
|
171 | - $search->withConfirmedEmail(); |
|
172 | - } |
|
173 | - |
|
174 | - $requestStates = $config->getRequestStates(); |
|
175 | - $requestsByStatus = $search->fetchByStatus(array_keys($requestStates)); |
|
176 | - |
|
177 | - foreach ($requestStates as $type => $v) { |
|
178 | - $requestSectionData[$v['header']] = array( |
|
179 | - 'requests' => $requestsByStatus[$type]['data'], |
|
180 | - 'total' => $requestsByStatus[$type]['count'], |
|
181 | - 'api' => $v['api'], |
|
182 | - 'type' => $type, |
|
183 | - 'special' => null, |
|
184 | - 'help' => null, |
|
185 | - ); |
|
186 | - } |
|
187 | - } |
|
85 | + $statement = $database->prepare($query); |
|
86 | + $statement->execute(); |
|
87 | + |
|
88 | + $last5result = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
89 | + |
|
90 | + $this->assign('lastFive', $last5result); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param PdoDatabase $database |
|
95 | + * @param SiteConfiguration $config |
|
96 | + * @param $requestSectionData |
|
97 | + */ |
|
98 | + private function setupHospitalQueue( |
|
99 | + PdoDatabase $database, |
|
100 | + SiteConfiguration $config, |
|
101 | + &$requestSectionData |
|
102 | + ) { |
|
103 | + $search = RequestSearchHelper::get($database) |
|
104 | + ->limit($config->getMiserModeLimit()) |
|
105 | + ->excludingStatus('Closed') |
|
106 | + ->isHospitalised(); |
|
107 | + |
|
108 | + if ($config->getEmailConfirmationEnabled()) { |
|
109 | + $search->withConfirmedEmail(); |
|
110 | + } |
|
111 | + |
|
112 | + $results = $search->getRecordCount($requestCount)->fetch(); |
|
113 | + |
|
114 | + if($requestCount > 0) { |
|
115 | + $requestSectionData['Hospital - Requests failed auto-creation'] = array( |
|
116 | + 'requests' => $results, |
|
117 | + 'total' => $requestCount, |
|
118 | + 'api' => 'hospital', |
|
119 | + 'type' => 'hospital', |
|
120 | + 'special' => 'Job Queue', |
|
121 | + 'help' => 'This queue lists all the requests which have been attempted to be created in the background, but for which this has failed for one reason or another. Check the job queue to find the error. Requests here may need to be created manually, or it may be possible to re-queue the request for auto-creation by the tool, or it may have been created already. Use your own technical discretion here.' |
|
122 | + ); |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @param PdoDatabase $database |
|
128 | + * @param SiteConfiguration $config |
|
129 | + * @param $requestSectionData |
|
130 | + */ |
|
131 | + private function setupJobQueue( |
|
132 | + PdoDatabase $database, |
|
133 | + SiteConfiguration $config, |
|
134 | + &$requestSectionData |
|
135 | + ) { |
|
136 | + $search = RequestSearchHelper::get($database) |
|
137 | + ->limit($config->getMiserModeLimit()) |
|
138 | + ->byStatus(RequestStatus::JOBQUEUE); |
|
139 | + |
|
140 | + if ($config->getEmailConfirmationEnabled()) { |
|
141 | + $search->withConfirmedEmail(); |
|
142 | + } |
|
143 | + |
|
144 | + $results = $search->getRecordCount($requestCount)->fetch(); |
|
145 | + |
|
146 | + if($requestCount > 0) { |
|
147 | + $requestSectionData['Requests queued in the Job Queue'] = array( |
|
148 | + 'requests' => $results, |
|
149 | + 'total' => $requestCount, |
|
150 | + 'api' => 'JobQueue', |
|
151 | + 'type' => 'JobQueue', |
|
152 | + 'special' => 'Job Queue', |
|
153 | + 'help' => 'This section lists all the requests which are currently waiting to be created by the tool. Requests should automatically disappear from here within a few minutes.' |
|
154 | + ); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param PdoDatabase $database |
|
160 | + * @param SiteConfiguration $config |
|
161 | + * @param $requestSectionData |
|
162 | + */ |
|
163 | + private function setupStatusSections( |
|
164 | + PdoDatabase $database, |
|
165 | + SiteConfiguration $config, |
|
166 | + &$requestSectionData |
|
167 | + ) { |
|
168 | + $search = RequestSearchHelper::get($database)->limit($config->getMiserModeLimit())->notHospitalised(); |
|
169 | + |
|
170 | + if ($config->getEmailConfirmationEnabled()) { |
|
171 | + $search->withConfirmedEmail(); |
|
172 | + } |
|
173 | + |
|
174 | + $requestStates = $config->getRequestStates(); |
|
175 | + $requestsByStatus = $search->fetchByStatus(array_keys($requestStates)); |
|
176 | + |
|
177 | + foreach ($requestStates as $type => $v) { |
|
178 | + $requestSectionData[$v['header']] = array( |
|
179 | + 'requests' => $requestsByStatus[$type]['data'], |
|
180 | + 'total' => $requestsByStatus[$type]['count'], |
|
181 | + 'api' => $v['api'], |
|
182 | + 'type' => $type, |
|
183 | + 'special' => null, |
|
184 | + 'help' => null, |
|
185 | + ); |
|
186 | + } |
|
187 | + } |
|
188 | 188 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | |
112 | 112 | $results = $search->getRecordCount($requestCount)->fetch(); |
113 | 113 | |
114 | - if($requestCount > 0) { |
|
114 | + if ($requestCount > 0) { |
|
115 | 115 | $requestSectionData['Hospital - Requests failed auto-creation'] = array( |
116 | 116 | 'requests' => $results, |
117 | 117 | 'total' => $requestCount, |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | $results = $search->getRecordCount($requestCount)->fetch(); |
145 | 145 | |
146 | - if($requestCount > 0) { |
|
146 | + if ($requestCount > 0) { |
|
147 | 147 | $requestSectionData['Requests queued in the Job Queue'] = array( |
148 | 148 | 'requests' => $results, |
149 | 149 | 'total' => $requestCount, |
@@ -24,545 +24,545 @@ |
||
24 | 24 | */ |
25 | 25 | class PageUserManagement extends InternalPageBase |
26 | 26 | { |
27 | - /** @var string */ |
|
28 | - private $adminMailingList = '[email protected]'; |
|
29 | - |
|
30 | - /** |
|
31 | - * Main function for this page, when no specific actions are called. |
|
32 | - */ |
|
33 | - protected function main() |
|
34 | - { |
|
35 | - $this->setHtmlTitle('User Management'); |
|
36 | - |
|
37 | - $database = $this->getDatabase(); |
|
38 | - $currentUser = User::getCurrent($database); |
|
39 | - |
|
40 | - // A bit hacky, but it's better than my last solution of creating an object for each user and passing that to |
|
41 | - // the template. I still don't have a particularly good way of handling this. |
|
42 | - OAuthUserHelper::prepareTokenCountStatement($database); |
|
43 | - |
|
44 | - if (WebRequest::getBoolean("showAll")) { |
|
45 | - $this->assign("showAll", true); |
|
46 | - |
|
47 | - $suspendedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_SUSPENDED)->fetch(); |
|
48 | - $this->assign("suspendedUsers", $suspendedUsers); |
|
49 | - |
|
50 | - $declinedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DECLINED)->fetch(); |
|
51 | - $this->assign("declinedUsers", $declinedUsers); |
|
52 | - |
|
53 | - UserSearchHelper::get($database)->getRoleMap($roleMap); |
|
54 | - } |
|
55 | - else { |
|
56 | - $this->assign("showAll", false); |
|
57 | - $this->assign("suspendedUsers", array()); |
|
58 | - $this->assign("declinedUsers", array()); |
|
59 | - |
|
60 | - UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap); |
|
61 | - } |
|
62 | - |
|
63 | - $newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch(); |
|
64 | - $normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch(); |
|
65 | - $adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch(); |
|
66 | - $checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch(); |
|
67 | - $toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch(); |
|
68 | - $this->assign('newUsers', $newUsers); |
|
69 | - $this->assign('normalUsers', $normalUsers); |
|
70 | - $this->assign('adminUsers', $adminUsers); |
|
71 | - $this->assign('checkUsers', $checkUsers); |
|
72 | - $this->assign('toolRoots', $toolRoots); |
|
73 | - |
|
74 | - $this->assign('roles', $roleMap); |
|
75 | - |
|
76 | - $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
77 | - return UserSearchHelper::get($database)->fetchColumn('username'); |
|
78 | - }); |
|
79 | - |
|
80 | - $this->assign('canApprove', $this->barrierTest('approve', $currentUser)); |
|
81 | - $this->assign('canDecline', $this->barrierTest('decline', $currentUser)); |
|
82 | - $this->assign('canRename', $this->barrierTest('rename', $currentUser)); |
|
83 | - $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser)); |
|
84 | - $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser)); |
|
85 | - $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser)); |
|
86 | - |
|
87 | - $this->setTemplate("usermanagement/main.tpl"); |
|
88 | - } |
|
89 | - |
|
90 | - #region Access control |
|
91 | - |
|
92 | - /** |
|
93 | - * Action target for editing the roles assigned to a user |
|
94 | - */ |
|
95 | - protected function editRoles() |
|
96 | - { |
|
97 | - $this->setHtmlTitle('User Management'); |
|
98 | - $database = $this->getDatabase(); |
|
99 | - $userId = WebRequest::getInt('user'); |
|
100 | - |
|
101 | - /** @var User $user */ |
|
102 | - $user = User::getById($userId, $database); |
|
103 | - |
|
104 | - if ($user === false) { |
|
105 | - throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
106 | - } |
|
107 | - |
|
108 | - $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database)); |
|
109 | - |
|
110 | - // Dual-mode action |
|
111 | - if (WebRequest::wasPosted()) { |
|
112 | - $this->validateCSRFToken(); |
|
113 | - |
|
114 | - $reason = WebRequest::postString('reason'); |
|
115 | - if ($reason === false || trim($reason) === '') { |
|
116 | - throw new ApplicationLogicException('No reason specified for roles change'); |
|
117 | - } |
|
118 | - |
|
119 | - /** @var UserRole[] $delete */ |
|
120 | - $delete = array(); |
|
121 | - /** @var string[] $delete */ |
|
122 | - $add = array(); |
|
123 | - |
|
124 | - foreach ($roleData as $name => $r) { |
|
125 | - if ($r['allowEdit'] !== 1) { |
|
126 | - // not allowed, to touch this, so ignore it |
|
127 | - continue; |
|
128 | - } |
|
129 | - |
|
130 | - $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0; |
|
131 | - if ($newValue !== $r['active']) { |
|
132 | - if ($newValue === 0) { |
|
133 | - $delete[] = $r['object']; |
|
134 | - } |
|
135 | - |
|
136 | - if ($newValue === 1) { |
|
137 | - $add[] = $name; |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - // Check there's something to do |
|
143 | - if ((count($add) + count($delete)) === 0) { |
|
144 | - $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
145 | - SessionAlert::warning('No changes made to roles.'); |
|
146 | - |
|
147 | - return; |
|
148 | - } |
|
149 | - |
|
150 | - $removed = array(); |
|
151 | - |
|
152 | - /** @var UserRole $d */ |
|
153 | - foreach ($delete as $d) { |
|
154 | - $removed[] = $d->getRole(); |
|
155 | - $d->delete(); |
|
156 | - } |
|
157 | - |
|
158 | - foreach ($add as $x) { |
|
159 | - $a = new UserRole(); |
|
160 | - $a->setUser($user->getId()); |
|
161 | - $a->setRole($x); |
|
162 | - $a->setDatabase($database); |
|
163 | - $a->save(); |
|
164 | - } |
|
165 | - |
|
166 | - Logger::userRolesEdited($database, $user, $reason, $add, $removed); |
|
167 | - |
|
168 | - // dummy save for optimistic locking. If this fails, the entire txn will roll back. |
|
169 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
170 | - $user->save(); |
|
171 | - |
|
172 | - $this->getNotificationHelper()->userRolesEdited($user, $reason); |
|
173 | - SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
174 | - |
|
175 | - $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
176 | - |
|
177 | - return; |
|
178 | - } |
|
179 | - else { |
|
180 | - $this->assignCSRFToken(); |
|
181 | - $this->setTemplate('usermanagement/roleedit.tpl'); |
|
182 | - $this->assign('user', $user); |
|
183 | - $this->assign('roleData', $roleData); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Action target for suspending users |
|
189 | - * |
|
190 | - * @throws ApplicationLogicException |
|
191 | - */ |
|
192 | - protected function suspend() |
|
193 | - { |
|
194 | - $this->setHtmlTitle('User Management'); |
|
195 | - |
|
196 | - $database = $this->getDatabase(); |
|
197 | - |
|
198 | - $userId = WebRequest::getInt('user'); |
|
199 | - |
|
200 | - /** @var User $user */ |
|
201 | - $user = User::getById($userId, $database); |
|
202 | - |
|
203 | - if ($user === false) { |
|
204 | - throw new ApplicationLogicException('Sorry, the user you are trying to suspend could not be found.'); |
|
205 | - } |
|
206 | - |
|
207 | - if ($user->isSuspended()) { |
|
208 | - throw new ApplicationLogicException('Sorry, the user you are trying to suspend is already suspended.'); |
|
209 | - } |
|
210 | - |
|
211 | - // Dual-mode action |
|
212 | - if (WebRequest::wasPosted()) { |
|
213 | - $this->validateCSRFToken(); |
|
214 | - $reason = WebRequest::postString('reason'); |
|
215 | - |
|
216 | - if ($reason === null || trim($reason) === "") { |
|
217 | - throw new ApplicationLogicException('No reason provided'); |
|
218 | - } |
|
219 | - |
|
220 | - $user->setStatus(User::STATUS_SUSPENDED); |
|
221 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
222 | - $user->save(); |
|
223 | - Logger::suspendedUser($database, $user, $reason); |
|
224 | - |
|
225 | - $this->getNotificationHelper()->userSuspended($user, $reason); |
|
226 | - SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
227 | - |
|
228 | - // send email |
|
229 | - $this->sendStatusChangeEmail( |
|
230 | - 'Your WP:ACC account has been suspended', |
|
231 | - 'usermanagement/emails/suspended.tpl', |
|
232 | - $reason, |
|
233 | - $user, |
|
234 | - User::getCurrent($database)->getUsername() |
|
235 | - ); |
|
236 | - |
|
237 | - $this->redirect('userManagement'); |
|
238 | - |
|
239 | - return; |
|
240 | - } |
|
241 | - else { |
|
242 | - $this->assignCSRFToken(); |
|
243 | - $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
244 | - $this->assign('user', $user); |
|
245 | - $this->assign('status', 'Suspended'); |
|
246 | - $this->assign("showReason", true); |
|
247 | - } |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Entry point for the decline action |
|
252 | - * |
|
253 | - * @throws ApplicationLogicException |
|
254 | - */ |
|
255 | - protected function decline() |
|
256 | - { |
|
257 | - $this->setHtmlTitle('User Management'); |
|
258 | - |
|
259 | - $database = $this->getDatabase(); |
|
260 | - |
|
261 | - $userId = WebRequest::getInt('user'); |
|
262 | - $user = User::getById($userId, $database); |
|
263 | - |
|
264 | - if ($user === false) { |
|
265 | - throw new ApplicationLogicException('Sorry, the user you are trying to decline could not be found.'); |
|
266 | - } |
|
267 | - |
|
268 | - if (!$user->isNewUser()) { |
|
269 | - throw new ApplicationLogicException('Sorry, the user you are trying to decline is not new.'); |
|
270 | - } |
|
271 | - |
|
272 | - // Dual-mode action |
|
273 | - if (WebRequest::wasPosted()) { |
|
274 | - $this->validateCSRFToken(); |
|
275 | - $reason = WebRequest::postString('reason'); |
|
276 | - |
|
277 | - if ($reason === null || trim($reason) === "") { |
|
278 | - throw new ApplicationLogicException('No reason provided'); |
|
279 | - } |
|
280 | - |
|
281 | - $user->setStatus(User::STATUS_DECLINED); |
|
282 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
283 | - $user->save(); |
|
284 | - Logger::declinedUser($database, $user, $reason); |
|
285 | - |
|
286 | - $this->getNotificationHelper()->userDeclined($user, $reason); |
|
287 | - SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
288 | - |
|
289 | - // send email |
|
290 | - $this->sendStatusChangeEmail( |
|
291 | - 'Your WP:ACC account has been declined', |
|
292 | - 'usermanagement/emails/declined.tpl', |
|
293 | - $reason, |
|
294 | - $user, |
|
295 | - User::getCurrent($database)->getUsername() |
|
296 | - ); |
|
297 | - |
|
298 | - $this->redirect('userManagement'); |
|
299 | - |
|
300 | - return; |
|
301 | - } |
|
302 | - else { |
|
303 | - $this->assignCSRFToken(); |
|
304 | - $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
305 | - $this->assign('user', $user); |
|
306 | - $this->assign('status', 'Declined'); |
|
307 | - $this->assign("showReason", true); |
|
308 | - } |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Entry point for the approve action |
|
313 | - * |
|
314 | - * @throws ApplicationLogicException |
|
315 | - */ |
|
316 | - protected function approve() |
|
317 | - { |
|
318 | - $this->setHtmlTitle('User Management'); |
|
319 | - |
|
320 | - $database = $this->getDatabase(); |
|
321 | - |
|
322 | - $userId = WebRequest::getInt('user'); |
|
323 | - $user = User::getById($userId, $database); |
|
324 | - |
|
325 | - if ($user === false) { |
|
326 | - throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.'); |
|
327 | - } |
|
328 | - |
|
329 | - if ($user->isActive()) { |
|
330 | - throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.'); |
|
331 | - } |
|
332 | - |
|
333 | - // Dual-mode action |
|
334 | - if (WebRequest::wasPosted()) { |
|
335 | - $this->validateCSRFToken(); |
|
336 | - $user->setStatus(User::STATUS_ACTIVE); |
|
337 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
338 | - $user->save(); |
|
339 | - Logger::approvedUser($database, $user); |
|
340 | - |
|
341 | - $this->getNotificationHelper()->userApproved($user); |
|
342 | - SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
343 | - |
|
344 | - // send email |
|
345 | - $this->sendStatusChangeEmail( |
|
346 | - 'Your WP:ACC account has been approved', |
|
347 | - 'usermanagement/emails/approved.tpl', |
|
348 | - null, |
|
349 | - $user, |
|
350 | - User::getCurrent($database)->getUsername() |
|
351 | - ); |
|
352 | - |
|
353 | - $this->redirect("userManagement"); |
|
354 | - |
|
355 | - return; |
|
356 | - } |
|
357 | - else { |
|
358 | - $this->assignCSRFToken(); |
|
359 | - $this->setTemplate("usermanagement/changelevel-reason.tpl"); |
|
360 | - $this->assign("user", $user); |
|
361 | - $this->assign("status", "User"); |
|
362 | - $this->assign("showReason", false); |
|
363 | - } |
|
364 | - } |
|
365 | - |
|
366 | - #endregion |
|
367 | - |
|
368 | - #region Renaming / Editing |
|
369 | - |
|
370 | - /** |
|
371 | - * Entry point for the rename action |
|
372 | - * |
|
373 | - * @throws ApplicationLogicException |
|
374 | - */ |
|
375 | - protected function rename() |
|
376 | - { |
|
377 | - $this->setHtmlTitle('User Management'); |
|
378 | - |
|
379 | - $database = $this->getDatabase(); |
|
380 | - |
|
381 | - $userId = WebRequest::getInt('user'); |
|
382 | - $user = User::getById($userId, $database); |
|
383 | - |
|
384 | - if ($user === false) { |
|
385 | - throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.'); |
|
386 | - } |
|
387 | - |
|
388 | - // Dual-mode action |
|
389 | - if (WebRequest::wasPosted()) { |
|
390 | - $this->validateCSRFToken(); |
|
391 | - $newUsername = WebRequest::postString('newname'); |
|
392 | - |
|
393 | - if ($newUsername === null || trim($newUsername) === "") { |
|
394 | - throw new ApplicationLogicException('The new username cannot be empty'); |
|
395 | - } |
|
396 | - |
|
397 | - if (User::getByUsername($newUsername, $database) != false) { |
|
398 | - throw new ApplicationLogicException('The new username already exists'); |
|
399 | - } |
|
400 | - |
|
401 | - $oldUsername = $user->getUsername(); |
|
402 | - $user->setUsername($newUsername); |
|
403 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
404 | - |
|
405 | - $user->save(); |
|
406 | - |
|
407 | - $logEntryData = serialize(array( |
|
408 | - 'old' => $oldUsername, |
|
409 | - 'new' => $newUsername, |
|
410 | - )); |
|
411 | - |
|
412 | - Logger::renamedUser($database, $user, $logEntryData); |
|
413 | - |
|
414 | - SessionAlert::quick("Changed User " |
|
415 | - . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8') |
|
416 | - . " name to " |
|
417 | - . htmlentities($newUsername, ENT_COMPAT, 'UTF-8')); |
|
418 | - |
|
419 | - $this->getNotificationHelper()->userRenamed($user, $oldUsername); |
|
420 | - |
|
421 | - // send an email to the user. |
|
422 | - $this->assign('targetUsername', $user->getUsername()); |
|
423 | - $this->assign('toolAdmin', User::getCurrent($database)->getUsername()); |
|
424 | - $this->assign('oldUsername', $oldUsername); |
|
425 | - $this->assign('mailingList', $this->adminMailingList); |
|
426 | - |
|
427 | - $this->getEmailHelper()->sendMail( |
|
428 | - $user->getEmail(), |
|
429 | - 'Your username on WP:ACC has been changed', |
|
430 | - $this->fetchTemplate('usermanagement/emails/renamed.tpl'), |
|
431 | - array('Reply-To' => $this->adminMailingList) |
|
432 | - ); |
|
433 | - |
|
434 | - $this->redirect("userManagement"); |
|
435 | - |
|
436 | - return; |
|
437 | - } |
|
438 | - else { |
|
439 | - $this->assignCSRFToken(); |
|
440 | - $this->setTemplate('usermanagement/renameuser.tpl'); |
|
441 | - $this->assign('user', $user); |
|
442 | - } |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Entry point for the edit action |
|
447 | - * |
|
448 | - * @throws ApplicationLogicException |
|
449 | - */ |
|
450 | - protected function editUser() |
|
451 | - { |
|
452 | - $this->setHtmlTitle('User Management'); |
|
453 | - |
|
454 | - $database = $this->getDatabase(); |
|
455 | - |
|
456 | - $userId = WebRequest::getInt('user'); |
|
457 | - $user = User::getById($userId, $database); |
|
458 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
459 | - |
|
460 | - if ($user === false) { |
|
461 | - throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
462 | - } |
|
463 | - |
|
464 | - // Dual-mode action |
|
465 | - if (WebRequest::wasPosted()) { |
|
466 | - $this->validateCSRFToken(); |
|
467 | - $newEmail = WebRequest::postEmail('user_email'); |
|
468 | - $newOnWikiName = WebRequest::postString('user_onwikiname'); |
|
469 | - |
|
470 | - if ($newEmail === null) { |
|
471 | - throw new ApplicationLogicException('Invalid email address'); |
|
472 | - } |
|
473 | - |
|
474 | - if (!$oauth->isFullyLinked()) { |
|
475 | - if (trim($newOnWikiName) == "") { |
|
476 | - throw new ApplicationLogicException('New on-wiki username cannot be blank'); |
|
477 | - } |
|
478 | - |
|
479 | - $user->setOnWikiName($newOnWikiName); |
|
480 | - } |
|
481 | - |
|
482 | - $user->setEmail($newEmail); |
|
483 | - |
|
484 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
485 | - |
|
486 | - $user->save(); |
|
487 | - |
|
488 | - Logger::userPreferencesChange($database, $user); |
|
489 | - $this->getNotificationHelper()->userPrefChange($user); |
|
490 | - SessionAlert::quick('Changes to user\'s preferences have been saved'); |
|
491 | - |
|
492 | - $this->redirect("userManagement"); |
|
493 | - |
|
494 | - return; |
|
495 | - } |
|
496 | - else { |
|
497 | - $this->assignCSRFToken(); |
|
498 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
499 | - $this->getSiteConfiguration()); |
|
500 | - $this->setTemplate('usermanagement/edituser.tpl'); |
|
501 | - $this->assign('user', $user); |
|
502 | - $this->assign('oauth', $oauth); |
|
503 | - } |
|
504 | - } |
|
505 | - |
|
506 | - #endregion |
|
507 | - |
|
508 | - /** |
|
509 | - * Sends a status change email to the user. |
|
510 | - * |
|
511 | - * @param string $subject The subject of the email |
|
512 | - * @param string $template The smarty template to use |
|
513 | - * @param string|null $reason The reason for performing the status change |
|
514 | - * @param User $user The user affected |
|
515 | - * @param string $toolAdminUsername The tool admin's username who is making the edit |
|
516 | - */ |
|
517 | - private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername) |
|
518 | - { |
|
519 | - $this->assign('targetUsername', $user->getUsername()); |
|
520 | - $this->assign('toolAdmin', $toolAdminUsername); |
|
521 | - $this->assign('actionReason', $reason); |
|
522 | - $this->assign('mailingList', $this->adminMailingList); |
|
523 | - |
|
524 | - $this->getEmailHelper()->sendMail( |
|
525 | - $user->getEmail(), |
|
526 | - $subject, |
|
527 | - $this->fetchTemplate($template), |
|
528 | - array('Reply-To' => $this->adminMailingList) |
|
529 | - ); |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * @param UserRole[] $activeRoles |
|
534 | - * |
|
535 | - * @return array |
|
536 | - */ |
|
537 | - private function getRoleData($activeRoles) |
|
538 | - { |
|
539 | - $availableRoles = $this->getSecurityManager()->getRoleConfiguration()->getAvailableRoles(); |
|
540 | - |
|
541 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
542 | - $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles); |
|
543 | - |
|
544 | - $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null); |
|
545 | - |
|
546 | - $roleData = array(); |
|
547 | - foreach ($availableRoles as $role => $data) { |
|
548 | - $intersection = array_intersect($data['editableBy'], $userRoles); |
|
549 | - |
|
550 | - $roleData[$role] = $initialValue; |
|
551 | - $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0; |
|
552 | - $roleData[$role]['description'] = $data['description']; |
|
553 | - } |
|
554 | - |
|
555 | - foreach ($activeRoles as $role) { |
|
556 | - if (!isset($roleData[$role->getRole()])) { |
|
557 | - // This value is no longer available in the configuration, allow changing (aka removing) it. |
|
558 | - $roleData[$role->getRole()] = $initialValue; |
|
559 | - $roleData[$role->getRole()]['allowEdit'] = 1; |
|
560 | - } |
|
561 | - |
|
562 | - $roleData[$role->getRole()]['object'] = $role; |
|
563 | - $roleData[$role->getRole()]['active'] = 1; |
|
564 | - } |
|
565 | - |
|
566 | - return $roleData; |
|
567 | - } |
|
27 | + /** @var string */ |
|
28 | + private $adminMailingList = '[email protected]'; |
|
29 | + |
|
30 | + /** |
|
31 | + * Main function for this page, when no specific actions are called. |
|
32 | + */ |
|
33 | + protected function main() |
|
34 | + { |
|
35 | + $this->setHtmlTitle('User Management'); |
|
36 | + |
|
37 | + $database = $this->getDatabase(); |
|
38 | + $currentUser = User::getCurrent($database); |
|
39 | + |
|
40 | + // A bit hacky, but it's better than my last solution of creating an object for each user and passing that to |
|
41 | + // the template. I still don't have a particularly good way of handling this. |
|
42 | + OAuthUserHelper::prepareTokenCountStatement($database); |
|
43 | + |
|
44 | + if (WebRequest::getBoolean("showAll")) { |
|
45 | + $this->assign("showAll", true); |
|
46 | + |
|
47 | + $suspendedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_SUSPENDED)->fetch(); |
|
48 | + $this->assign("suspendedUsers", $suspendedUsers); |
|
49 | + |
|
50 | + $declinedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DECLINED)->fetch(); |
|
51 | + $this->assign("declinedUsers", $declinedUsers); |
|
52 | + |
|
53 | + UserSearchHelper::get($database)->getRoleMap($roleMap); |
|
54 | + } |
|
55 | + else { |
|
56 | + $this->assign("showAll", false); |
|
57 | + $this->assign("suspendedUsers", array()); |
|
58 | + $this->assign("declinedUsers", array()); |
|
59 | + |
|
60 | + UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap); |
|
61 | + } |
|
62 | + |
|
63 | + $newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch(); |
|
64 | + $normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch(); |
|
65 | + $adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch(); |
|
66 | + $checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch(); |
|
67 | + $toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch(); |
|
68 | + $this->assign('newUsers', $newUsers); |
|
69 | + $this->assign('normalUsers', $normalUsers); |
|
70 | + $this->assign('adminUsers', $adminUsers); |
|
71 | + $this->assign('checkUsers', $checkUsers); |
|
72 | + $this->assign('toolRoots', $toolRoots); |
|
73 | + |
|
74 | + $this->assign('roles', $roleMap); |
|
75 | + |
|
76 | + $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
77 | + return UserSearchHelper::get($database)->fetchColumn('username'); |
|
78 | + }); |
|
79 | + |
|
80 | + $this->assign('canApprove', $this->barrierTest('approve', $currentUser)); |
|
81 | + $this->assign('canDecline', $this->barrierTest('decline', $currentUser)); |
|
82 | + $this->assign('canRename', $this->barrierTest('rename', $currentUser)); |
|
83 | + $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser)); |
|
84 | + $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser)); |
|
85 | + $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser)); |
|
86 | + |
|
87 | + $this->setTemplate("usermanagement/main.tpl"); |
|
88 | + } |
|
89 | + |
|
90 | + #region Access control |
|
91 | + |
|
92 | + /** |
|
93 | + * Action target for editing the roles assigned to a user |
|
94 | + */ |
|
95 | + protected function editRoles() |
|
96 | + { |
|
97 | + $this->setHtmlTitle('User Management'); |
|
98 | + $database = $this->getDatabase(); |
|
99 | + $userId = WebRequest::getInt('user'); |
|
100 | + |
|
101 | + /** @var User $user */ |
|
102 | + $user = User::getById($userId, $database); |
|
103 | + |
|
104 | + if ($user === false) { |
|
105 | + throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
106 | + } |
|
107 | + |
|
108 | + $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database)); |
|
109 | + |
|
110 | + // Dual-mode action |
|
111 | + if (WebRequest::wasPosted()) { |
|
112 | + $this->validateCSRFToken(); |
|
113 | + |
|
114 | + $reason = WebRequest::postString('reason'); |
|
115 | + if ($reason === false || trim($reason) === '') { |
|
116 | + throw new ApplicationLogicException('No reason specified for roles change'); |
|
117 | + } |
|
118 | + |
|
119 | + /** @var UserRole[] $delete */ |
|
120 | + $delete = array(); |
|
121 | + /** @var string[] $delete */ |
|
122 | + $add = array(); |
|
123 | + |
|
124 | + foreach ($roleData as $name => $r) { |
|
125 | + if ($r['allowEdit'] !== 1) { |
|
126 | + // not allowed, to touch this, so ignore it |
|
127 | + continue; |
|
128 | + } |
|
129 | + |
|
130 | + $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0; |
|
131 | + if ($newValue !== $r['active']) { |
|
132 | + if ($newValue === 0) { |
|
133 | + $delete[] = $r['object']; |
|
134 | + } |
|
135 | + |
|
136 | + if ($newValue === 1) { |
|
137 | + $add[] = $name; |
|
138 | + } |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + // Check there's something to do |
|
143 | + if ((count($add) + count($delete)) === 0) { |
|
144 | + $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
145 | + SessionAlert::warning('No changes made to roles.'); |
|
146 | + |
|
147 | + return; |
|
148 | + } |
|
149 | + |
|
150 | + $removed = array(); |
|
151 | + |
|
152 | + /** @var UserRole $d */ |
|
153 | + foreach ($delete as $d) { |
|
154 | + $removed[] = $d->getRole(); |
|
155 | + $d->delete(); |
|
156 | + } |
|
157 | + |
|
158 | + foreach ($add as $x) { |
|
159 | + $a = new UserRole(); |
|
160 | + $a->setUser($user->getId()); |
|
161 | + $a->setRole($x); |
|
162 | + $a->setDatabase($database); |
|
163 | + $a->save(); |
|
164 | + } |
|
165 | + |
|
166 | + Logger::userRolesEdited($database, $user, $reason, $add, $removed); |
|
167 | + |
|
168 | + // dummy save for optimistic locking. If this fails, the entire txn will roll back. |
|
169 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
170 | + $user->save(); |
|
171 | + |
|
172 | + $this->getNotificationHelper()->userRolesEdited($user, $reason); |
|
173 | + SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
174 | + |
|
175 | + $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
176 | + |
|
177 | + return; |
|
178 | + } |
|
179 | + else { |
|
180 | + $this->assignCSRFToken(); |
|
181 | + $this->setTemplate('usermanagement/roleedit.tpl'); |
|
182 | + $this->assign('user', $user); |
|
183 | + $this->assign('roleData', $roleData); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Action target for suspending users |
|
189 | + * |
|
190 | + * @throws ApplicationLogicException |
|
191 | + */ |
|
192 | + protected function suspend() |
|
193 | + { |
|
194 | + $this->setHtmlTitle('User Management'); |
|
195 | + |
|
196 | + $database = $this->getDatabase(); |
|
197 | + |
|
198 | + $userId = WebRequest::getInt('user'); |
|
199 | + |
|
200 | + /** @var User $user */ |
|
201 | + $user = User::getById($userId, $database); |
|
202 | + |
|
203 | + if ($user === false) { |
|
204 | + throw new ApplicationLogicException('Sorry, the user you are trying to suspend could not be found.'); |
|
205 | + } |
|
206 | + |
|
207 | + if ($user->isSuspended()) { |
|
208 | + throw new ApplicationLogicException('Sorry, the user you are trying to suspend is already suspended.'); |
|
209 | + } |
|
210 | + |
|
211 | + // Dual-mode action |
|
212 | + if (WebRequest::wasPosted()) { |
|
213 | + $this->validateCSRFToken(); |
|
214 | + $reason = WebRequest::postString('reason'); |
|
215 | + |
|
216 | + if ($reason === null || trim($reason) === "") { |
|
217 | + throw new ApplicationLogicException('No reason provided'); |
|
218 | + } |
|
219 | + |
|
220 | + $user->setStatus(User::STATUS_SUSPENDED); |
|
221 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
222 | + $user->save(); |
|
223 | + Logger::suspendedUser($database, $user, $reason); |
|
224 | + |
|
225 | + $this->getNotificationHelper()->userSuspended($user, $reason); |
|
226 | + SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
227 | + |
|
228 | + // send email |
|
229 | + $this->sendStatusChangeEmail( |
|
230 | + 'Your WP:ACC account has been suspended', |
|
231 | + 'usermanagement/emails/suspended.tpl', |
|
232 | + $reason, |
|
233 | + $user, |
|
234 | + User::getCurrent($database)->getUsername() |
|
235 | + ); |
|
236 | + |
|
237 | + $this->redirect('userManagement'); |
|
238 | + |
|
239 | + return; |
|
240 | + } |
|
241 | + else { |
|
242 | + $this->assignCSRFToken(); |
|
243 | + $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
244 | + $this->assign('user', $user); |
|
245 | + $this->assign('status', 'Suspended'); |
|
246 | + $this->assign("showReason", true); |
|
247 | + } |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Entry point for the decline action |
|
252 | + * |
|
253 | + * @throws ApplicationLogicException |
|
254 | + */ |
|
255 | + protected function decline() |
|
256 | + { |
|
257 | + $this->setHtmlTitle('User Management'); |
|
258 | + |
|
259 | + $database = $this->getDatabase(); |
|
260 | + |
|
261 | + $userId = WebRequest::getInt('user'); |
|
262 | + $user = User::getById($userId, $database); |
|
263 | + |
|
264 | + if ($user === false) { |
|
265 | + throw new ApplicationLogicException('Sorry, the user you are trying to decline could not be found.'); |
|
266 | + } |
|
267 | + |
|
268 | + if (!$user->isNewUser()) { |
|
269 | + throw new ApplicationLogicException('Sorry, the user you are trying to decline is not new.'); |
|
270 | + } |
|
271 | + |
|
272 | + // Dual-mode action |
|
273 | + if (WebRequest::wasPosted()) { |
|
274 | + $this->validateCSRFToken(); |
|
275 | + $reason = WebRequest::postString('reason'); |
|
276 | + |
|
277 | + if ($reason === null || trim($reason) === "") { |
|
278 | + throw new ApplicationLogicException('No reason provided'); |
|
279 | + } |
|
280 | + |
|
281 | + $user->setStatus(User::STATUS_DECLINED); |
|
282 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
283 | + $user->save(); |
|
284 | + Logger::declinedUser($database, $user, $reason); |
|
285 | + |
|
286 | + $this->getNotificationHelper()->userDeclined($user, $reason); |
|
287 | + SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
288 | + |
|
289 | + // send email |
|
290 | + $this->sendStatusChangeEmail( |
|
291 | + 'Your WP:ACC account has been declined', |
|
292 | + 'usermanagement/emails/declined.tpl', |
|
293 | + $reason, |
|
294 | + $user, |
|
295 | + User::getCurrent($database)->getUsername() |
|
296 | + ); |
|
297 | + |
|
298 | + $this->redirect('userManagement'); |
|
299 | + |
|
300 | + return; |
|
301 | + } |
|
302 | + else { |
|
303 | + $this->assignCSRFToken(); |
|
304 | + $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
305 | + $this->assign('user', $user); |
|
306 | + $this->assign('status', 'Declined'); |
|
307 | + $this->assign("showReason", true); |
|
308 | + } |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Entry point for the approve action |
|
313 | + * |
|
314 | + * @throws ApplicationLogicException |
|
315 | + */ |
|
316 | + protected function approve() |
|
317 | + { |
|
318 | + $this->setHtmlTitle('User Management'); |
|
319 | + |
|
320 | + $database = $this->getDatabase(); |
|
321 | + |
|
322 | + $userId = WebRequest::getInt('user'); |
|
323 | + $user = User::getById($userId, $database); |
|
324 | + |
|
325 | + if ($user === false) { |
|
326 | + throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.'); |
|
327 | + } |
|
328 | + |
|
329 | + if ($user->isActive()) { |
|
330 | + throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.'); |
|
331 | + } |
|
332 | + |
|
333 | + // Dual-mode action |
|
334 | + if (WebRequest::wasPosted()) { |
|
335 | + $this->validateCSRFToken(); |
|
336 | + $user->setStatus(User::STATUS_ACTIVE); |
|
337 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
338 | + $user->save(); |
|
339 | + Logger::approvedUser($database, $user); |
|
340 | + |
|
341 | + $this->getNotificationHelper()->userApproved($user); |
|
342 | + SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
343 | + |
|
344 | + // send email |
|
345 | + $this->sendStatusChangeEmail( |
|
346 | + 'Your WP:ACC account has been approved', |
|
347 | + 'usermanagement/emails/approved.tpl', |
|
348 | + null, |
|
349 | + $user, |
|
350 | + User::getCurrent($database)->getUsername() |
|
351 | + ); |
|
352 | + |
|
353 | + $this->redirect("userManagement"); |
|
354 | + |
|
355 | + return; |
|
356 | + } |
|
357 | + else { |
|
358 | + $this->assignCSRFToken(); |
|
359 | + $this->setTemplate("usermanagement/changelevel-reason.tpl"); |
|
360 | + $this->assign("user", $user); |
|
361 | + $this->assign("status", "User"); |
|
362 | + $this->assign("showReason", false); |
|
363 | + } |
|
364 | + } |
|
365 | + |
|
366 | + #endregion |
|
367 | + |
|
368 | + #region Renaming / Editing |
|
369 | + |
|
370 | + /** |
|
371 | + * Entry point for the rename action |
|
372 | + * |
|
373 | + * @throws ApplicationLogicException |
|
374 | + */ |
|
375 | + protected function rename() |
|
376 | + { |
|
377 | + $this->setHtmlTitle('User Management'); |
|
378 | + |
|
379 | + $database = $this->getDatabase(); |
|
380 | + |
|
381 | + $userId = WebRequest::getInt('user'); |
|
382 | + $user = User::getById($userId, $database); |
|
383 | + |
|
384 | + if ($user === false) { |
|
385 | + throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.'); |
|
386 | + } |
|
387 | + |
|
388 | + // Dual-mode action |
|
389 | + if (WebRequest::wasPosted()) { |
|
390 | + $this->validateCSRFToken(); |
|
391 | + $newUsername = WebRequest::postString('newname'); |
|
392 | + |
|
393 | + if ($newUsername === null || trim($newUsername) === "") { |
|
394 | + throw new ApplicationLogicException('The new username cannot be empty'); |
|
395 | + } |
|
396 | + |
|
397 | + if (User::getByUsername($newUsername, $database) != false) { |
|
398 | + throw new ApplicationLogicException('The new username already exists'); |
|
399 | + } |
|
400 | + |
|
401 | + $oldUsername = $user->getUsername(); |
|
402 | + $user->setUsername($newUsername); |
|
403 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
404 | + |
|
405 | + $user->save(); |
|
406 | + |
|
407 | + $logEntryData = serialize(array( |
|
408 | + 'old' => $oldUsername, |
|
409 | + 'new' => $newUsername, |
|
410 | + )); |
|
411 | + |
|
412 | + Logger::renamedUser($database, $user, $logEntryData); |
|
413 | + |
|
414 | + SessionAlert::quick("Changed User " |
|
415 | + . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8') |
|
416 | + . " name to " |
|
417 | + . htmlentities($newUsername, ENT_COMPAT, 'UTF-8')); |
|
418 | + |
|
419 | + $this->getNotificationHelper()->userRenamed($user, $oldUsername); |
|
420 | + |
|
421 | + // send an email to the user. |
|
422 | + $this->assign('targetUsername', $user->getUsername()); |
|
423 | + $this->assign('toolAdmin', User::getCurrent($database)->getUsername()); |
|
424 | + $this->assign('oldUsername', $oldUsername); |
|
425 | + $this->assign('mailingList', $this->adminMailingList); |
|
426 | + |
|
427 | + $this->getEmailHelper()->sendMail( |
|
428 | + $user->getEmail(), |
|
429 | + 'Your username on WP:ACC has been changed', |
|
430 | + $this->fetchTemplate('usermanagement/emails/renamed.tpl'), |
|
431 | + array('Reply-To' => $this->adminMailingList) |
|
432 | + ); |
|
433 | + |
|
434 | + $this->redirect("userManagement"); |
|
435 | + |
|
436 | + return; |
|
437 | + } |
|
438 | + else { |
|
439 | + $this->assignCSRFToken(); |
|
440 | + $this->setTemplate('usermanagement/renameuser.tpl'); |
|
441 | + $this->assign('user', $user); |
|
442 | + } |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Entry point for the edit action |
|
447 | + * |
|
448 | + * @throws ApplicationLogicException |
|
449 | + */ |
|
450 | + protected function editUser() |
|
451 | + { |
|
452 | + $this->setHtmlTitle('User Management'); |
|
453 | + |
|
454 | + $database = $this->getDatabase(); |
|
455 | + |
|
456 | + $userId = WebRequest::getInt('user'); |
|
457 | + $user = User::getById($userId, $database); |
|
458 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
459 | + |
|
460 | + if ($user === false) { |
|
461 | + throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
462 | + } |
|
463 | + |
|
464 | + // Dual-mode action |
|
465 | + if (WebRequest::wasPosted()) { |
|
466 | + $this->validateCSRFToken(); |
|
467 | + $newEmail = WebRequest::postEmail('user_email'); |
|
468 | + $newOnWikiName = WebRequest::postString('user_onwikiname'); |
|
469 | + |
|
470 | + if ($newEmail === null) { |
|
471 | + throw new ApplicationLogicException('Invalid email address'); |
|
472 | + } |
|
473 | + |
|
474 | + if (!$oauth->isFullyLinked()) { |
|
475 | + if (trim($newOnWikiName) == "") { |
|
476 | + throw new ApplicationLogicException('New on-wiki username cannot be blank'); |
|
477 | + } |
|
478 | + |
|
479 | + $user->setOnWikiName($newOnWikiName); |
|
480 | + } |
|
481 | + |
|
482 | + $user->setEmail($newEmail); |
|
483 | + |
|
484 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
485 | + |
|
486 | + $user->save(); |
|
487 | + |
|
488 | + Logger::userPreferencesChange($database, $user); |
|
489 | + $this->getNotificationHelper()->userPrefChange($user); |
|
490 | + SessionAlert::quick('Changes to user\'s preferences have been saved'); |
|
491 | + |
|
492 | + $this->redirect("userManagement"); |
|
493 | + |
|
494 | + return; |
|
495 | + } |
|
496 | + else { |
|
497 | + $this->assignCSRFToken(); |
|
498 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
499 | + $this->getSiteConfiguration()); |
|
500 | + $this->setTemplate('usermanagement/edituser.tpl'); |
|
501 | + $this->assign('user', $user); |
|
502 | + $this->assign('oauth', $oauth); |
|
503 | + } |
|
504 | + } |
|
505 | + |
|
506 | + #endregion |
|
507 | + |
|
508 | + /** |
|
509 | + * Sends a status change email to the user. |
|
510 | + * |
|
511 | + * @param string $subject The subject of the email |
|
512 | + * @param string $template The smarty template to use |
|
513 | + * @param string|null $reason The reason for performing the status change |
|
514 | + * @param User $user The user affected |
|
515 | + * @param string $toolAdminUsername The tool admin's username who is making the edit |
|
516 | + */ |
|
517 | + private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername) |
|
518 | + { |
|
519 | + $this->assign('targetUsername', $user->getUsername()); |
|
520 | + $this->assign('toolAdmin', $toolAdminUsername); |
|
521 | + $this->assign('actionReason', $reason); |
|
522 | + $this->assign('mailingList', $this->adminMailingList); |
|
523 | + |
|
524 | + $this->getEmailHelper()->sendMail( |
|
525 | + $user->getEmail(), |
|
526 | + $subject, |
|
527 | + $this->fetchTemplate($template), |
|
528 | + array('Reply-To' => $this->adminMailingList) |
|
529 | + ); |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * @param UserRole[] $activeRoles |
|
534 | + * |
|
535 | + * @return array |
|
536 | + */ |
|
537 | + private function getRoleData($activeRoles) |
|
538 | + { |
|
539 | + $availableRoles = $this->getSecurityManager()->getRoleConfiguration()->getAvailableRoles(); |
|
540 | + |
|
541 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
542 | + $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles); |
|
543 | + |
|
544 | + $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null); |
|
545 | + |
|
546 | + $roleData = array(); |
|
547 | + foreach ($availableRoles as $role => $data) { |
|
548 | + $intersection = array_intersect($data['editableBy'], $userRoles); |
|
549 | + |
|
550 | + $roleData[$role] = $initialValue; |
|
551 | + $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0; |
|
552 | + $roleData[$role]['description'] = $data['description']; |
|
553 | + } |
|
554 | + |
|
555 | + foreach ($activeRoles as $role) { |
|
556 | + if (!isset($roleData[$role->getRole()])) { |
|
557 | + // This value is no longer available in the configuration, allow changing (aka removing) it. |
|
558 | + $roleData[$role->getRole()] = $initialValue; |
|
559 | + $roleData[$role->getRole()]['allowEdit'] = 1; |
|
560 | + } |
|
561 | + |
|
562 | + $roleData[$role->getRole()]['object'] = $role; |
|
563 | + $roleData[$role->getRole()]['active'] = 1; |
|
564 | + } |
|
565 | + |
|
566 | + return $roleData; |
|
567 | + } |
|
568 | 568 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | continue; |
128 | 128 | } |
129 | 129 | |
130 | - $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0; |
|
130 | + $newValue = WebRequest::postBoolean('role-'.$name) ? 1 : 0; |
|
131 | 131 | if ($newValue !== $r['active']) { |
132 | 132 | if ($newValue === 0) { |
133 | 133 | $delete[] = $r['object']; |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | $user->save(); |
171 | 171 | |
172 | 172 | $this->getNotificationHelper()->userRolesEdited($user, $reason); |
173 | - SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
173 | + SessionAlert::quick('Roles changed for user '.htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
174 | 174 | |
175 | 175 | $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
176 | 176 | |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | Logger::suspendedUser($database, $user, $reason); |
224 | 224 | |
225 | 225 | $this->getNotificationHelper()->userSuspended($user, $reason); |
226 | - SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
226 | + SessionAlert::quick('Suspended user '.htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
227 | 227 | |
228 | 228 | // send email |
229 | 229 | $this->sendStatusChangeEmail( |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | Logger::declinedUser($database, $user, $reason); |
285 | 285 | |
286 | 286 | $this->getNotificationHelper()->userDeclined($user, $reason); |
287 | - SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
287 | + SessionAlert::quick('Declined user '.htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
288 | 288 | |
289 | 289 | // send email |
290 | 290 | $this->sendStatusChangeEmail( |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | Logger::approvedUser($database, $user); |
340 | 340 | |
341 | 341 | $this->getNotificationHelper()->userApproved($user); |
342 | - SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
342 | + SessionAlert::quick('Approved user '.htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
343 | 343 | |
344 | 344 | // send email |
345 | 345 | $this->sendStatusChangeEmail( |
@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | |
23 | 23 | class StatsUsers extends InternalPageBase |
24 | 24 | { |
25 | - public function main() |
|
26 | - { |
|
27 | - $this->setHtmlTitle('Users :: Statistics'); |
|
25 | + public function main() |
|
26 | + { |
|
27 | + $this->setHtmlTitle('Users :: Statistics'); |
|
28 | 28 | |
29 | - $database = $this->getDatabase(); |
|
29 | + $database = $this->getDatabase(); |
|
30 | 30 | |
31 | - $query = <<<SQL |
|
31 | + $query = <<<SQL |
|
32 | 32 | SELECT |
33 | 33 | u.id |
34 | 34 | , u.username |
@@ -44,36 +44,36 @@ discard block |
||
44 | 44 | WHERE u.status = 'Active' |
45 | 45 | SQL; |
46 | 46 | |
47 | - $users = $database->query($query)->fetchAll(PDO::FETCH_ASSOC); |
|
48 | - $this->assign('users', $users); |
|
47 | + $users = $database->query($query)->fetchAll(PDO::FETCH_ASSOC); |
|
48 | + $this->assign('users', $users); |
|
49 | 49 | |
50 | - $this->assign('statsPageTitle', 'Account Creation Tool users'); |
|
51 | - $this->setTemplate("statistics/users.tpl"); |
|
52 | - } |
|
50 | + $this->assign('statsPageTitle', 'Account Creation Tool users'); |
|
51 | + $this->setTemplate("statistics/users.tpl"); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Entry point for the detail action. |
|
56 | - * |
|
57 | - * @throws ApplicationLogicException |
|
58 | - */ |
|
59 | - protected function detail() |
|
60 | - { |
|
61 | - $userId = WebRequest::getInt('user'); |
|
62 | - if ($userId === null) { |
|
63 | - throw new ApplicationLogicException("User not found"); |
|
64 | - } |
|
54 | + /** |
|
55 | + * Entry point for the detail action. |
|
56 | + * |
|
57 | + * @throws ApplicationLogicException |
|
58 | + */ |
|
59 | + protected function detail() |
|
60 | + { |
|
61 | + $userId = WebRequest::getInt('user'); |
|
62 | + if ($userId === null) { |
|
63 | + throw new ApplicationLogicException("User not found"); |
|
64 | + } |
|
65 | 65 | |
66 | - $database = $this->getDatabase(); |
|
66 | + $database = $this->getDatabase(); |
|
67 | 67 | |
68 | - $user = User::getById($userId, $database); |
|
69 | - if ($user == false) { |
|
70 | - throw new ApplicationLogicException('User not found'); |
|
71 | - } |
|
68 | + $user = User::getById($userId, $database); |
|
69 | + if ($user == false) { |
|
70 | + throw new ApplicationLogicException('User not found'); |
|
71 | + } |
|
72 | 72 | |
73 | - $safeUsername = htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'); |
|
74 | - $this->setHtmlTitle($safeUsername . ' :: Users :: Statistics'); |
|
73 | + $safeUsername = htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'); |
|
74 | + $this->setHtmlTitle($safeUsername . ' :: Users :: Statistics'); |
|
75 | 75 | |
76 | - $activitySummary = $database->prepare(<<<SQL |
|
76 | + $activitySummary = $database->prepare(<<<SQL |
|
77 | 77 | SELECT COALESCE(closes.mail_desc, log.action) AS action, COUNT(*) AS count |
78 | 78 | FROM log |
79 | 79 | INNER JOIN user ON log.user = user.id |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | WHERE user.username = :username |
82 | 82 | GROUP BY action; |
83 | 83 | SQL |
84 | - ); |
|
85 | - $activitySummary->execute(array(":username" => $user->getUsername())); |
|
86 | - $activitySummaryData = $activitySummary->fetchAll(PDO::FETCH_ASSOC); |
|
84 | + ); |
|
85 | + $activitySummary->execute(array(":username" => $user->getUsername())); |
|
86 | + $activitySummaryData = $activitySummary->fetchAll(PDO::FETCH_ASSOC); |
|
87 | 87 | |
88 | - $this->assign("user", $user); |
|
89 | - $this->assign("activity", $activitySummaryData); |
|
88 | + $this->assign("user", $user); |
|
89 | + $this->assign("activity", $activitySummaryData); |
|
90 | 90 | |
91 | - $usersCreatedQuery = $database->prepare(<<<SQL |
|
91 | + $usersCreatedQuery = $database->prepare(<<<SQL |
|
92 | 92 | SELECT log.timestamp time, request.name name, request.id id |
93 | 93 | FROM log |
94 | 94 | INNER JOIN request ON (request.id = log.objectid AND log.objecttype = 'Request') |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | AND (emailtemplate.oncreated = '1' OR log.action = 'Closed custom-y') |
100 | 100 | ORDER BY log.timestamp; |
101 | 101 | SQL |
102 | - ); |
|
103 | - $usersCreatedQuery->execute(array(":username" => $user->getUsername())); |
|
104 | - $usersCreated = $usersCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
|
105 | - $this->assign("created", $usersCreated); |
|
102 | + ); |
|
103 | + $usersCreatedQuery->execute(array(":username" => $user->getUsername())); |
|
104 | + $usersCreated = $usersCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
|
105 | + $this->assign("created", $usersCreated); |
|
106 | 106 | |
107 | - $usersNotCreatedQuery = $database->prepare(<<<SQL |
|
107 | + $usersNotCreatedQuery = $database->prepare(<<<SQL |
|
108 | 108 | SELECT log.timestamp time, request.name name, request.id id |
109 | 109 | FROM log |
110 | 110 | JOIN request ON request.id = log.objectid AND log.objecttype = 'Request' |
@@ -115,45 +115,45 @@ discard block |
||
115 | 115 | AND (emailtemplate.oncreated = '0' OR log.action = 'Closed custom-n' OR log.action = 'Closed 0') |
116 | 116 | ORDER BY log.timestamp; |
117 | 117 | SQL |
118 | - ); |
|
119 | - $usersNotCreatedQuery->execute(array(":username" => $user->getUsername())); |
|
120 | - $usersNotCreated = $usersNotCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
|
121 | - $this->assign("notcreated", $usersNotCreated); |
|
122 | - |
|
123 | - /** @var Log[] $logs */ |
|
124 | - $logs = LogSearchHelper::get($database) |
|
125 | - ->byObjectType('User') |
|
126 | - ->byObjectId($user->getId()) |
|
127 | - ->getRecordCount($logCount) |
|
128 | - ->fetch(); |
|
129 | - |
|
130 | - if ($logCount === 0) { |
|
131 | - $this->assign('accountlog', array()); |
|
132 | - } |
|
133 | - else { |
|
134 | - list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
135 | - |
|
136 | - $this->assign("accountlog", $logData); |
|
137 | - $this->assign("users", $users); |
|
138 | - } |
|
139 | - |
|
140 | - $currentUser = User::getCurrent($database); |
|
141 | - $this->assign('canApprove', $this->barrierTest('approve', $currentUser, PageUserManagement::class)); |
|
142 | - $this->assign('canDecline', $this->barrierTest('decline', $currentUser, PageUserManagement::class)); |
|
143 | - $this->assign('canRename', $this->barrierTest('rename', $currentUser, PageUserManagement::class)); |
|
144 | - $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser, PageUserManagement::class)); |
|
145 | - $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser, PageUserManagement::class)); |
|
146 | - $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser, PageUserManagement::class)); |
|
147 | - |
|
148 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
149 | - $this->assign('oauth', $oauth); |
|
150 | - |
|
151 | - if ($oauth->isFullyLinked()) { |
|
152 | - $this->assign('identity', $oauth->getIdentity(true)); |
|
153 | - $this->assign('identityExpired', $oauth->identityExpired()); |
|
154 | - } |
|
155 | - |
|
156 | - $this->assign('statsPageTitle', 'Account Creation Tool users'); |
|
157 | - $this->setTemplate("statistics/userdetail.tpl"); |
|
158 | - } |
|
118 | + ); |
|
119 | + $usersNotCreatedQuery->execute(array(":username" => $user->getUsername())); |
|
120 | + $usersNotCreated = $usersNotCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
|
121 | + $this->assign("notcreated", $usersNotCreated); |
|
122 | + |
|
123 | + /** @var Log[] $logs */ |
|
124 | + $logs = LogSearchHelper::get($database) |
|
125 | + ->byObjectType('User') |
|
126 | + ->byObjectId($user->getId()) |
|
127 | + ->getRecordCount($logCount) |
|
128 | + ->fetch(); |
|
129 | + |
|
130 | + if ($logCount === 0) { |
|
131 | + $this->assign('accountlog', array()); |
|
132 | + } |
|
133 | + else { |
|
134 | + list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
135 | + |
|
136 | + $this->assign("accountlog", $logData); |
|
137 | + $this->assign("users", $users); |
|
138 | + } |
|
139 | + |
|
140 | + $currentUser = User::getCurrent($database); |
|
141 | + $this->assign('canApprove', $this->barrierTest('approve', $currentUser, PageUserManagement::class)); |
|
142 | + $this->assign('canDecline', $this->barrierTest('decline', $currentUser, PageUserManagement::class)); |
|
143 | + $this->assign('canRename', $this->barrierTest('rename', $currentUser, PageUserManagement::class)); |
|
144 | + $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser, PageUserManagement::class)); |
|
145 | + $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser, PageUserManagement::class)); |
|
146 | + $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser, PageUserManagement::class)); |
|
147 | + |
|
148 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
149 | + $this->assign('oauth', $oauth); |
|
150 | + |
|
151 | + if ($oauth->isFullyLinked()) { |
|
152 | + $this->assign('identity', $oauth->getIdentity(true)); |
|
153 | + $this->assign('identityExpired', $oauth->identityExpired()); |
|
154 | + } |
|
155 | + |
|
156 | + $this->assign('statsPageTitle', 'Account Creation Tool users'); |
|
157 | + $this->setTemplate("statistics/userdetail.tpl"); |
|
158 | + } |
|
159 | 159 | } |
@@ -18,54 +18,54 @@ |
||
18 | 18 | |
19 | 19 | class PageLog extends PagedInternalPageBase |
20 | 20 | { |
21 | - /** |
|
22 | - * Main function for this page, when no specific actions are called. |
|
23 | - */ |
|
24 | - protected function main() |
|
25 | - { |
|
26 | - $this->setHtmlTitle('Logs'); |
|
21 | + /** |
|
22 | + * Main function for this page, when no specific actions are called. |
|
23 | + */ |
|
24 | + protected function main() |
|
25 | + { |
|
26 | + $this->setHtmlTitle('Logs'); |
|
27 | 27 | |
28 | - $filterUser = WebRequest::getString('filterUser'); |
|
29 | - $filterAction = WebRequest::getString('filterAction'); |
|
30 | - $filterObjectType = WebRequest::getString('filterObjectType'); |
|
31 | - $filterObjectId = WebRequest::getInt('filterObjectId'); |
|
28 | + $filterUser = WebRequest::getString('filterUser'); |
|
29 | + $filterAction = WebRequest::getString('filterAction'); |
|
30 | + $filterObjectType = WebRequest::getString('filterObjectType'); |
|
31 | + $filterObjectId = WebRequest::getInt('filterObjectId'); |
|
32 | 32 | |
33 | - $database = $this->getDatabase(); |
|
33 | + $database = $this->getDatabase(); |
|
34 | 34 | |
35 | - if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) { |
|
36 | - $filterObjectType = null; |
|
37 | - } |
|
35 | + if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) { |
|
36 | + $filterObjectType = null; |
|
37 | + } |
|
38 | 38 | |
39 | - $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
40 | - return UserSearchHelper::get($database)->fetchColumn('username'); |
|
41 | - }); |
|
39 | + $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
40 | + return UserSearchHelper::get($database)->fetchColumn('username'); |
|
41 | + }); |
|
42 | 42 | |
43 | - $logSearch = LogSearchHelper::get($database); |
|
43 | + $logSearch = LogSearchHelper::get($database); |
|
44 | 44 | |
45 | - $this->setSearchHelper($logSearch); |
|
46 | - $this->setupLimits(); |
|
45 | + $this->setSearchHelper($logSearch); |
|
46 | + $this->setupLimits(); |
|
47 | 47 | |
48 | 48 | |
49 | - /** @var Log[] $logs */ |
|
50 | - $logs = $logSearch->getRecordCount($count)->fetch(); |
|
49 | + /** @var Log[] $logs */ |
|
50 | + $logs = $logSearch->getRecordCount($count)->fetch(); |
|
51 | 51 | |
52 | - if ($count === 0) { |
|
53 | - $this->assign('logs', array()); |
|
54 | - $this->setTemplate('logs/main.tpl'); |
|
52 | + if ($count === 0) { |
|
53 | + $this->assign('logs', array()); |
|
54 | + $this->setTemplate('logs/main.tpl'); |
|
55 | 55 | |
56 | - return; |
|
57 | - } |
|
56 | + return; |
|
57 | + } |
|
58 | 58 | |
59 | - list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
59 | + list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
60 | 60 | |
61 | - $this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId)); |
|
61 | + $this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId)); |
|
62 | 62 | |
63 | - $this->assign("logs", $logData); |
|
64 | - $this->assign("users", $users); |
|
63 | + $this->assign("logs", $logData); |
|
64 | + $this->assign("users", $users); |
|
65 | 65 | |
66 | - $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase())); |
|
67 | - $this->assign('allObjectTypes', LogHelper::getObjectTypes()); |
|
66 | + $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase())); |
|
67 | + $this->assign('allObjectTypes', LogHelper::getObjectTypes()); |
|
68 | 68 | |
69 | - $this->setTemplate("logs/main.tpl"); |
|
70 | - } |
|
69 | + $this->setTemplate("logs/main.tpl"); |
|
70 | + } |
|
71 | 71 | } |