@@ 183-239 (lines=57) @@ | ||
180 | * |
|
181 | * @throws ApplicationLogicException |
|
182 | */ |
|
183 | protected function suspend() |
|
184 | { |
|
185 | $this->setHtmlTitle('User Management'); |
|
186 | ||
187 | $database = $this->getDatabase(); |
|
188 | ||
189 | $userId = WebRequest::getInt('user'); |
|
190 | ||
191 | /** @var User $user */ |
|
192 | $user = User::getById($userId, $database); |
|
193 | ||
194 | if ($user === false) { |
|
195 | throw new ApplicationLogicException('Sorry, the user you are trying to suspend could not be found.'); |
|
196 | } |
|
197 | ||
198 | if ($user->isSuspended()) { |
|
199 | throw new ApplicationLogicException('Sorry, the user you are trying to suspend is already suspended.'); |
|
200 | } |
|
201 | ||
202 | // Dual-mode action |
|
203 | if (WebRequest::wasPosted()) { |
|
204 | $this->validateCSRFToken(); |
|
205 | $reason = WebRequest::postString('reason'); |
|
206 | ||
207 | if ($reason === null || trim($reason) === "") { |
|
208 | throw new ApplicationLogicException('No reason provided'); |
|
209 | } |
|
210 | ||
211 | $user->setStatus(User::STATUS_SUSPENDED); |
|
212 | $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
213 | $user->save(); |
|
214 | Logger::suspendedUser($database, $user, $reason); |
|
215 | ||
216 | $this->getNotificationHelper()->userSuspended($user, $reason); |
|
217 | SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
218 | ||
219 | // send email |
|
220 | $this->sendStatusChangeEmail( |
|
221 | 'Your WP:ACC account has been suspended', |
|
222 | 'usermanagement/emails/suspended.tpl', |
|
223 | $reason, |
|
224 | $user, |
|
225 | User::getCurrent($database)->getUsername() |
|
226 | ); |
|
227 | ||
228 | $this->redirect('userManagement'); |
|
229 | ||
230 | return; |
|
231 | } |
|
232 | else { |
|
233 | $this->assignCSRFToken(); |
|
234 | $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
235 | $this->assign('user', $user); |
|
236 | $this->assign('status', 'Suspended'); |
|
237 | $this->assign("showReason", true); |
|
238 | } |
|
239 | } |
|
240 | ||
241 | /** |
|
242 | * Entry point for the decline action |
|
@@ 246-300 (lines=55) @@ | ||
243 | * |
|
244 | * @throws ApplicationLogicException |
|
245 | */ |
|
246 | protected function decline() |
|
247 | { |
|
248 | $this->setHtmlTitle('User Management'); |
|
249 | ||
250 | $database = $this->getDatabase(); |
|
251 | ||
252 | $userId = WebRequest::getInt('user'); |
|
253 | $user = User::getById($userId, $database); |
|
254 | ||
255 | if ($user === false) { |
|
256 | throw new ApplicationLogicException('Sorry, the user you are trying to decline could not be found.'); |
|
257 | } |
|
258 | ||
259 | if (!$user->isNewUser()) { |
|
260 | throw new ApplicationLogicException('Sorry, the user you are trying to decline is not new.'); |
|
261 | } |
|
262 | ||
263 | // Dual-mode action |
|
264 | if (WebRequest::wasPosted()) { |
|
265 | $this->validateCSRFToken(); |
|
266 | $reason = WebRequest::postString('reason'); |
|
267 | ||
268 | if ($reason === null || trim($reason) === "") { |
|
269 | throw new ApplicationLogicException('No reason provided'); |
|
270 | } |
|
271 | ||
272 | $user->setStatus(User::STATUS_DECLINED); |
|
273 | $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
274 | $user->save(); |
|
275 | Logger::declinedUser($database, $user, $reason); |
|
276 | ||
277 | $this->getNotificationHelper()->userDeclined($user, $reason); |
|
278 | SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
279 | ||
280 | // send email |
|
281 | $this->sendStatusChangeEmail( |
|
282 | 'Your WP:ACC account has been declined', |
|
283 | 'usermanagement/emails/declined.tpl', |
|
284 | $reason, |
|
285 | $user, |
|
286 | User::getCurrent($database)->getUsername() |
|
287 | ); |
|
288 | ||
289 | $this->redirect('userManagement'); |
|
290 | ||
291 | return; |
|
292 | } |
|
293 | else { |
|
294 | $this->assignCSRFToken(); |
|
295 | $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
296 | $this->assign('user', $user); |
|
297 | $this->assign('status', 'Declined'); |
|
298 | $this->assign("showReason", true); |
|
299 | } |
|
300 | } |
|
301 | ||
302 | /** |
|
303 | * Entry point for the approve action |