@@ -19,150 +19,150 @@ |
||
| 19 | 19 | |
| 20 | 20 | class PageRequestAccount extends PublicInterfacePageBase |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Main function for this page, when no specific actions are called. |
|
| 24 | - * @return void |
|
| 25 | - */ |
|
| 26 | - protected function main() |
|
| 27 | - { |
|
| 28 | - // dual mode page |
|
| 29 | - if (WebRequest::wasPosted()) { |
|
| 30 | - $request = $this->createNewRequest(); |
|
| 31 | - |
|
| 32 | - $validationErrors = $this->validateRequest($request); |
|
| 33 | - |
|
| 34 | - if (count($validationErrors) > 0) { |
|
| 35 | - foreach ($validationErrors as $validationError) { |
|
| 36 | - SessionAlert::error($validationError->getErrorMessage()); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // Preserve the data after an error |
|
| 40 | - WebRequest::setSessionContext('accountReq', |
|
| 41 | - array( |
|
| 42 | - 'username' => WebRequest::postString('name'), |
|
| 43 | - 'email' => WebRequest::postEmail('email'), |
|
| 44 | - 'comments' => WebRequest::postString('comments'), |
|
| 45 | - ) |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - // Validation error, bomb out early. |
|
| 49 | - $this->redirect(); |
|
| 50 | - |
|
| 51 | - return; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - // actually save the request to the database |
|
| 55 | - if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) { |
|
| 56 | - $this->saveAsEmailConfirmation($request); |
|
| 57 | - } |
|
| 58 | - else { |
|
| 59 | - $this->saveWithoutEmailConfirmation($request); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - else { |
|
| 63 | - // set the form values from the session context |
|
| 64 | - $context = WebRequest::getSessionContext('accountReq'); |
|
| 65 | - if ($context !== null && is_array($context)) { |
|
| 66 | - $this->assign('username', $context['username']); |
|
| 67 | - $this->assign('email', $context['email']); |
|
| 68 | - $this->assign('comments', $context['comments']); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // Clear it for a refresh |
|
| 72 | - WebRequest::setSessionContext('accountReq', null); |
|
| 73 | - |
|
| 74 | - $this->setTemplate('request/request-form.tpl'); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @return Request |
|
| 80 | - */ |
|
| 81 | - protected function createNewRequest() |
|
| 82 | - { |
|
| 83 | - $request = new Request(); |
|
| 84 | - $request->setDatabase($this->getDatabase()); |
|
| 85 | - |
|
| 86 | - $request->setName(WebRequest::postString('name')); |
|
| 87 | - $request->setEmail(WebRequest::postEmail('email')); |
|
| 88 | - $request->setComment(WebRequest::postString('comments')); |
|
| 89 | - |
|
| 90 | - $request->setIp(WebRequest::remoteAddress()); |
|
| 91 | - $request->setForwardedIp(WebRequest::forwardedAddress()); |
|
| 92 | - |
|
| 93 | - $request->setUserAgent(WebRequest::userAgent()); |
|
| 94 | - |
|
| 95 | - return $request; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @param Request $request |
|
| 100 | - * |
|
| 101 | - * @return ValidationError[] |
|
| 102 | - */ |
|
| 103 | - protected function validateRequest($request) |
|
| 104 | - { |
|
| 105 | - $validationHelper = new RequestValidationHelper( |
|
| 106 | - new BanHelper($this->getDatabase()), |
|
| 107 | - $request, |
|
| 108 | - WebRequest::postEmail('emailconfirm'), |
|
| 109 | - $this->getDatabase(), |
|
| 110 | - $this->getAntiSpoofProvider(), |
|
| 111 | - $this->getXffTrustProvider(), |
|
| 112 | - $this->getHttpHelper(), |
|
| 113 | - $this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 114 | - $this->getSiteConfiguration()->getTitleBlacklistEnabled(), |
|
| 115 | - $this->getTorExitProvider()); |
|
| 116 | - |
|
| 117 | - // These are arrays of ValidationError. |
|
| 118 | - $nameValidation = $validationHelper->validateName(); |
|
| 119 | - $emailValidation = $validationHelper->validateEmail(); |
|
| 120 | - $otherValidation = $validationHelper->validateOther(); |
|
| 121 | - |
|
| 122 | - $validationErrors = array_merge($nameValidation, $emailValidation, $otherValidation); |
|
| 123 | - |
|
| 124 | - return $validationErrors; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param Request $request |
|
| 129 | - * |
|
| 130 | - * @throws Exception |
|
| 131 | - */ |
|
| 132 | - protected function saveAsEmailConfirmation(Request $request) |
|
| 133 | - { |
|
| 134 | - $request->generateEmailConfirmationHash(); |
|
| 135 | - $request->save(); |
|
| 136 | - |
|
| 137 | - $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
| 138 | - $request->getIp(), |
|
| 139 | - $request->getForwardedIp()); |
|
| 140 | - |
|
| 141 | - $this->assign("ip", $trustedIp); |
|
| 142 | - $this->assign("id", $request->getId()); |
|
| 143 | - $this->assign("hash", $request->getEmailConfirm()); |
|
| 144 | - |
|
| 145 | - // Sends the confirmation email to the user. |
|
| 146 | - $this->getEmailHelper()->sendMail( |
|
| 147 | - $request->getEmail(), |
|
| 148 | - "[ACC #{$request->getId()}] English Wikipedia Account Request", |
|
| 149 | - $this->fetchTemplate('request/confirmation-mail.tpl')); |
|
| 150 | - |
|
| 151 | - $this->redirect('emailConfirmationRequired'); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @param Request $request |
|
| 156 | - * |
|
| 157 | - * @throws Exception |
|
| 158 | - */ |
|
| 159 | - protected function saveWithoutEmailConfirmation(Request $request) |
|
| 160 | - { |
|
| 161 | - $request->setEmailConfirm(0); // fixme Since it can't be null |
|
| 162 | - $request->save(); |
|
| 163 | - |
|
| 164 | - $this->getNotificationHelper()->requestReceived($request); |
|
| 165 | - |
|
| 166 | - $this->redirect('requestSubmitted'); |
|
| 167 | - } |
|
| 22 | + /** |
|
| 23 | + * Main function for this page, when no specific actions are called. |
|
| 24 | + * @return void |
|
| 25 | + */ |
|
| 26 | + protected function main() |
|
| 27 | + { |
|
| 28 | + // dual mode page |
|
| 29 | + if (WebRequest::wasPosted()) { |
|
| 30 | + $request = $this->createNewRequest(); |
|
| 31 | + |
|
| 32 | + $validationErrors = $this->validateRequest($request); |
|
| 33 | + |
|
| 34 | + if (count($validationErrors) > 0) { |
|
| 35 | + foreach ($validationErrors as $validationError) { |
|
| 36 | + SessionAlert::error($validationError->getErrorMessage()); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // Preserve the data after an error |
|
| 40 | + WebRequest::setSessionContext('accountReq', |
|
| 41 | + array( |
|
| 42 | + 'username' => WebRequest::postString('name'), |
|
| 43 | + 'email' => WebRequest::postEmail('email'), |
|
| 44 | + 'comments' => WebRequest::postString('comments'), |
|
| 45 | + ) |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + // Validation error, bomb out early. |
|
| 49 | + $this->redirect(); |
|
| 50 | + |
|
| 51 | + return; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + // actually save the request to the database |
|
| 55 | + if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) { |
|
| 56 | + $this->saveAsEmailConfirmation($request); |
|
| 57 | + } |
|
| 58 | + else { |
|
| 59 | + $this->saveWithoutEmailConfirmation($request); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + else { |
|
| 63 | + // set the form values from the session context |
|
| 64 | + $context = WebRequest::getSessionContext('accountReq'); |
|
| 65 | + if ($context !== null && is_array($context)) { |
|
| 66 | + $this->assign('username', $context['username']); |
|
| 67 | + $this->assign('email', $context['email']); |
|
| 68 | + $this->assign('comments', $context['comments']); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // Clear it for a refresh |
|
| 72 | + WebRequest::setSessionContext('accountReq', null); |
|
| 73 | + |
|
| 74 | + $this->setTemplate('request/request-form.tpl'); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @return Request |
|
| 80 | + */ |
|
| 81 | + protected function createNewRequest() |
|
| 82 | + { |
|
| 83 | + $request = new Request(); |
|
| 84 | + $request->setDatabase($this->getDatabase()); |
|
| 85 | + |
|
| 86 | + $request->setName(WebRequest::postString('name')); |
|
| 87 | + $request->setEmail(WebRequest::postEmail('email')); |
|
| 88 | + $request->setComment(WebRequest::postString('comments')); |
|
| 89 | + |
|
| 90 | + $request->setIp(WebRequest::remoteAddress()); |
|
| 91 | + $request->setForwardedIp(WebRequest::forwardedAddress()); |
|
| 92 | + |
|
| 93 | + $request->setUserAgent(WebRequest::userAgent()); |
|
| 94 | + |
|
| 95 | + return $request; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @param Request $request |
|
| 100 | + * |
|
| 101 | + * @return ValidationError[] |
|
| 102 | + */ |
|
| 103 | + protected function validateRequest($request) |
|
| 104 | + { |
|
| 105 | + $validationHelper = new RequestValidationHelper( |
|
| 106 | + new BanHelper($this->getDatabase()), |
|
| 107 | + $request, |
|
| 108 | + WebRequest::postEmail('emailconfirm'), |
|
| 109 | + $this->getDatabase(), |
|
| 110 | + $this->getAntiSpoofProvider(), |
|
| 111 | + $this->getXffTrustProvider(), |
|
| 112 | + $this->getHttpHelper(), |
|
| 113 | + $this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 114 | + $this->getSiteConfiguration()->getTitleBlacklistEnabled(), |
|
| 115 | + $this->getTorExitProvider()); |
|
| 116 | + |
|
| 117 | + // These are arrays of ValidationError. |
|
| 118 | + $nameValidation = $validationHelper->validateName(); |
|
| 119 | + $emailValidation = $validationHelper->validateEmail(); |
|
| 120 | + $otherValidation = $validationHelper->validateOther(); |
|
| 121 | + |
|
| 122 | + $validationErrors = array_merge($nameValidation, $emailValidation, $otherValidation); |
|
| 123 | + |
|
| 124 | + return $validationErrors; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param Request $request |
|
| 129 | + * |
|
| 130 | + * @throws Exception |
|
| 131 | + */ |
|
| 132 | + protected function saveAsEmailConfirmation(Request $request) |
|
| 133 | + { |
|
| 134 | + $request->generateEmailConfirmationHash(); |
|
| 135 | + $request->save(); |
|
| 136 | + |
|
| 137 | + $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
| 138 | + $request->getIp(), |
|
| 139 | + $request->getForwardedIp()); |
|
| 140 | + |
|
| 141 | + $this->assign("ip", $trustedIp); |
|
| 142 | + $this->assign("id", $request->getId()); |
|
| 143 | + $this->assign("hash", $request->getEmailConfirm()); |
|
| 144 | + |
|
| 145 | + // Sends the confirmation email to the user. |
|
| 146 | + $this->getEmailHelper()->sendMail( |
|
| 147 | + $request->getEmail(), |
|
| 148 | + "[ACC #{$request->getId()}] English Wikipedia Account Request", |
|
| 149 | + $this->fetchTemplate('request/confirmation-mail.tpl')); |
|
| 150 | + |
|
| 151 | + $this->redirect('emailConfirmationRequired'); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @param Request $request |
|
| 156 | + * |
|
| 157 | + * @throws Exception |
|
| 158 | + */ |
|
| 159 | + protected function saveWithoutEmailConfirmation(Request $request) |
|
| 160 | + { |
|
| 161 | + $request->setEmailConfirm(0); // fixme Since it can't be null |
|
| 162 | + $request->save(); |
|
| 163 | + |
|
| 164 | + $this->getNotificationHelper()->requestReceived($request); |
|
| 165 | + |
|
| 166 | + $this->redirect('requestSubmitted'); |
|
| 167 | + } |
|
| 168 | 168 | } |
| 169 | 169 | \ No newline at end of file |
@@ -54,12 +54,10 @@ |
||
| 54 | 54 | // actually save the request to the database |
| 55 | 55 | if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) { |
| 56 | 56 | $this->saveAsEmailConfirmation($request); |
| 57 | - } |
|
| 58 | - else { |
|
| 57 | + } else { |
|
| 59 | 58 | $this->saveWithoutEmailConfirmation($request); |
| 60 | 59 | } |
| 61 | - } |
|
| 62 | - else { |
|
| 60 | + } else { |
|
| 63 | 61 | // set the form values from the session context |
| 64 | 62 | $context = WebRequest::getSessionContext('accountReq'); |
| 65 | 63 | if ($context !== null && is_array($context)) { |
@@ -18,67 +18,67 @@ |
||
| 18 | 18 | |
| 19 | 19 | class PageConfirmEmail extends PublicInterfacePageBase |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Main function for this page, when no specific actions are called. |
|
| 23 | - * @throws ApplicationLogicException |
|
| 24 | - * @throws Exception |
|
| 25 | - */ |
|
| 26 | - protected function main() |
|
| 27 | - { |
|
| 28 | - $id = WebRequest::getInt('id'); |
|
| 29 | - $si = WebRequest::getString('si'); |
|
| 30 | - |
|
| 31 | - if ($id === null || $si === null) { |
|
| 32 | - throw new ApplicationLogicException('Link incomplete - please double check the link you received.'); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** @var Request|false $request */ |
|
| 36 | - $request = Request::getById($id, $this->getDatabase()); |
|
| 37 | - |
|
| 38 | - if ($request === false) { |
|
| 39 | - throw new ApplicationLogicException('Request not found'); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - if ($request->getEmailConfirm() === 'Confirmed') { |
|
| 43 | - // request has already been confirmed. Bomb out silently. |
|
| 44 | - $this->redirect('requestSubmitted'); |
|
| 45 | - |
|
| 46 | - return; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if ($request->getEmailConfirm() === $si) { |
|
| 50 | - $request->setEmailConfirm('Confirmed'); |
|
| 51 | - } |
|
| 52 | - else { |
|
| 53 | - throw new ApplicationLogicException('The confirmation value does not appear to match the expected value'); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - try { |
|
| 57 | - $request->save(); |
|
| 58 | - } |
|
| 59 | - catch (OptimisticLockFailedException $ex) { |
|
| 60 | - // Okay. Someone's edited this in the time between us loading this page and doing the checks, and us getting |
|
| 61 | - // to saving the page. We *do not* want to show an optimistic lock failure, the most likely problem is they |
|
| 62 | - // double-loaded this page (see #255). Let's confirm this, and bomb out with a success message if it's the |
|
| 63 | - // case. |
|
| 64 | - |
|
| 65 | - $request = Request::getById($id, $this->getDatabase()); |
|
| 66 | - if ($request->getEmailConfirm() === 'Confirmed') { |
|
| 67 | - // we've already done the sanity checks above |
|
| 68 | - |
|
| 69 | - $this->redirect('requestSubmitted'); |
|
| 70 | - |
|
| 71 | - // skip the log and notification |
|
| 72 | - return; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // something really weird happened. Another race condition? |
|
| 76 | - throw $ex; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - Logger::emailConfirmed($this->getDatabase(), $request); |
|
| 80 | - $this->getNotificationHelper()->requestReceived($request); |
|
| 81 | - |
|
| 82 | - $this->redirect('requestSubmitted'); |
|
| 83 | - } |
|
| 21 | + /** |
|
| 22 | + * Main function for this page, when no specific actions are called. |
|
| 23 | + * @throws ApplicationLogicException |
|
| 24 | + * @throws Exception |
|
| 25 | + */ |
|
| 26 | + protected function main() |
|
| 27 | + { |
|
| 28 | + $id = WebRequest::getInt('id'); |
|
| 29 | + $si = WebRequest::getString('si'); |
|
| 30 | + |
|
| 31 | + if ($id === null || $si === null) { |
|
| 32 | + throw new ApplicationLogicException('Link incomplete - please double check the link you received.'); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** @var Request|false $request */ |
|
| 36 | + $request = Request::getById($id, $this->getDatabase()); |
|
| 37 | + |
|
| 38 | + if ($request === false) { |
|
| 39 | + throw new ApplicationLogicException('Request not found'); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + if ($request->getEmailConfirm() === 'Confirmed') { |
|
| 43 | + // request has already been confirmed. Bomb out silently. |
|
| 44 | + $this->redirect('requestSubmitted'); |
|
| 45 | + |
|
| 46 | + return; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if ($request->getEmailConfirm() === $si) { |
|
| 50 | + $request->setEmailConfirm('Confirmed'); |
|
| 51 | + } |
|
| 52 | + else { |
|
| 53 | + throw new ApplicationLogicException('The confirmation value does not appear to match the expected value'); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + try { |
|
| 57 | + $request->save(); |
|
| 58 | + } |
|
| 59 | + catch (OptimisticLockFailedException $ex) { |
|
| 60 | + // Okay. Someone's edited this in the time between us loading this page and doing the checks, and us getting |
|
| 61 | + // to saving the page. We *do not* want to show an optimistic lock failure, the most likely problem is they |
|
| 62 | + // double-loaded this page (see #255). Let's confirm this, and bomb out with a success message if it's the |
|
| 63 | + // case. |
|
| 64 | + |
|
| 65 | + $request = Request::getById($id, $this->getDatabase()); |
|
| 66 | + if ($request->getEmailConfirm() === 'Confirmed') { |
|
| 67 | + // we've already done the sanity checks above |
|
| 68 | + |
|
| 69 | + $this->redirect('requestSubmitted'); |
|
| 70 | + |
|
| 71 | + // skip the log and notification |
|
| 72 | + return; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // something really weird happened. Another race condition? |
|
| 76 | + throw $ex; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + Logger::emailConfirmed($this->getDatabase(), $request); |
|
| 80 | + $this->getNotificationHelper()->requestReceived($request); |
|
| 81 | + |
|
| 82 | + $this->redirect('requestSubmitted'); |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | \ No newline at end of file |
@@ -48,8 +48,7 @@ |
||
| 48 | 48 | |
| 49 | 49 | if ($request->getEmailConfirm() === $si) { |
| 50 | 50 | $request->setEmailConfirm('Confirmed'); |
| 51 | - } |
|
| 52 | - else { |
|
| 51 | + } else { |
|
| 53 | 52 | throw new ApplicationLogicException('The confirmation value does not appear to match the expected value'); |
| 54 | 53 | } |
| 55 | 54 | |
@@ -12,12 +12,12 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PageRequestSubmitted extends PublicInterfacePageBase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Main function for this page, when no specific actions are called. |
|
| 17 | - * @return void |
|
| 18 | - */ |
|
| 19 | - protected function main() |
|
| 20 | - { |
|
| 21 | - $this->setTemplate('request/email-confirmed.tpl'); |
|
| 22 | - } |
|
| 15 | + /** |
|
| 16 | + * Main function for this page, when no specific actions are called. |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 19 | + protected function main() |
|
| 20 | + { |
|
| 21 | + $this->setTemplate('request/email-confirmed.tpl'); |
|
| 22 | + } |
|
| 23 | 23 | } |
| 24 | 24 | \ No newline at end of file |
@@ -20,137 +20,137 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class PageLogin extends InternalPageBase |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Main function for this page, when no specific actions are called. |
|
| 25 | - */ |
|
| 26 | - protected function main() |
|
| 27 | - { |
|
| 28 | - // Start by enforcing HTTPS |
|
| 29 | - if ($this->getSiteConfiguration()->getUseStrictTransportSecurity() !== false) { |
|
| 30 | - if (WebRequest::isHttps()) { |
|
| 31 | - // Client can clearly use HTTPS, so let's enforce it for all connections. |
|
| 32 | - if (!headers_sent()) { |
|
| 33 | - header("Strict-Transport-Security: max-age=15768000"); |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - else { |
|
| 37 | - // This is the login form, not the request form. We need protection here. |
|
| 38 | - $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri()); |
|
| 39 | - |
|
| 40 | - return; |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - if (WebRequest::wasPosted()) { |
|
| 45 | - // POST. Do some authentication. |
|
| 46 | - $this->validateCSRFToken(); |
|
| 47 | - |
|
| 48 | - $user = null; |
|
| 49 | - try { |
|
| 50 | - $user = $this->getAuthenticatingUser(); |
|
| 51 | - } |
|
| 52 | - catch (ApplicationLogicException $ex) { |
|
| 53 | - SessionAlert::error($ex->getMessage()); |
|
| 54 | - $this->redirect('login'); |
|
| 55 | - |
|
| 56 | - return; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // Touch force logout |
|
| 60 | - $user->setForceLogout(false); |
|
| 61 | - $user->save(); |
|
| 62 | - |
|
| 63 | - if ($this->getSiteConfiguration()->getEnforceOAuth()) { |
|
| 64 | - if (!$user->isOAuthLinked()) { |
|
| 65 | - $oauthHelper = $this->getOAuthHelper(); |
|
| 66 | - |
|
| 67 | - $requestToken = $oauthHelper->getRequestToken(); |
|
| 68 | - $user->setOAuthRequestToken($requestToken->key); |
|
| 69 | - $user->setOAuthRequestSecret($requestToken->secret); |
|
| 70 | - $user->save(); |
|
| 71 | - |
|
| 72 | - WebRequest::setPartialLogin($user); |
|
| 73 | - $this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key)); |
|
| 74 | - |
|
| 75 | - return; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // User is partially linked to OAuth. This is not allowed. Enforce it for this user. |
|
| 80 | - if ($user->getOnWikiName() === '##OAUTH##') { |
|
| 81 | - $oauthHelper = $this->getOAuthHelper(); |
|
| 82 | - |
|
| 83 | - $requestToken = $oauthHelper->getRequestToken(); |
|
| 84 | - $user->setOAuthRequestToken($requestToken->key); |
|
| 85 | - $user->setOAuthRequestSecret($requestToken->secret); |
|
| 86 | - $user->save(); |
|
| 87 | - |
|
| 88 | - WebRequest::setPartialLogin($user); |
|
| 89 | - $this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key)); |
|
| 90 | - |
|
| 91 | - return; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - WebRequest::setLoggedInUser($user); |
|
| 95 | - |
|
| 96 | - $this->goBackWhenceYouCame($user); |
|
| 97 | - } |
|
| 98 | - else { |
|
| 99 | - // GET. Show the form |
|
| 100 | - $this->assignCSRFToken(); |
|
| 101 | - $this->setTemplate("login.tpl"); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return User |
|
| 107 | - * @throws ApplicationLogicException |
|
| 108 | - */ |
|
| 109 | - private function getAuthenticatingUser() |
|
| 110 | - { |
|
| 111 | - $username = WebRequest::postString("username"); |
|
| 112 | - $password = WebRequest::postString("password"); |
|
| 113 | - |
|
| 114 | - if ($username === null || $password === null || $username === "" || $password === "") { |
|
| 115 | - throw new ApplicationLogicException("No username/password specified"); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** @var User $user */ |
|
| 119 | - $user = User::getByUsername($username, $this->getDatabase()); |
|
| 120 | - |
|
| 121 | - if ($user == false || !$user->authenticate($password)) { |
|
| 122 | - throw new ApplicationLogicException("Authentication failed"); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return $user; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - protected function isProtectedPage() |
|
| 129 | - { |
|
| 130 | - return false; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Redirect the user back to wherever they came from after a successful login |
|
| 135 | - * |
|
| 136 | - * @param User $user |
|
| 137 | - */ |
|
| 138 | - private function goBackWhenceYouCame(User $user) |
|
| 139 | - { |
|
| 140 | - // Redirect to wherever the user came from |
|
| 141 | - $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
| 142 | - if ($redirectDestination !== null) { |
|
| 143 | - $this->redirectUrl($redirectDestination); |
|
| 144 | - } |
|
| 145 | - else { |
|
| 146 | - if ($user->isNewUser()) { |
|
| 147 | - // home page isn't allowed, go to preferences instead |
|
| 148 | - $this->redirect('preferences'); |
|
| 149 | - } |
|
| 150 | - else { |
|
| 151 | - // go to the home page |
|
| 152 | - $this->redirect(''); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 23 | + /** |
|
| 24 | + * Main function for this page, when no specific actions are called. |
|
| 25 | + */ |
|
| 26 | + protected function main() |
|
| 27 | + { |
|
| 28 | + // Start by enforcing HTTPS |
|
| 29 | + if ($this->getSiteConfiguration()->getUseStrictTransportSecurity() !== false) { |
|
| 30 | + if (WebRequest::isHttps()) { |
|
| 31 | + // Client can clearly use HTTPS, so let's enforce it for all connections. |
|
| 32 | + if (!headers_sent()) { |
|
| 33 | + header("Strict-Transport-Security: max-age=15768000"); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + else { |
|
| 37 | + // This is the login form, not the request form. We need protection here. |
|
| 38 | + $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri()); |
|
| 39 | + |
|
| 40 | + return; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + if (WebRequest::wasPosted()) { |
|
| 45 | + // POST. Do some authentication. |
|
| 46 | + $this->validateCSRFToken(); |
|
| 47 | + |
|
| 48 | + $user = null; |
|
| 49 | + try { |
|
| 50 | + $user = $this->getAuthenticatingUser(); |
|
| 51 | + } |
|
| 52 | + catch (ApplicationLogicException $ex) { |
|
| 53 | + SessionAlert::error($ex->getMessage()); |
|
| 54 | + $this->redirect('login'); |
|
| 55 | + |
|
| 56 | + return; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // Touch force logout |
|
| 60 | + $user->setForceLogout(false); |
|
| 61 | + $user->save(); |
|
| 62 | + |
|
| 63 | + if ($this->getSiteConfiguration()->getEnforceOAuth()) { |
|
| 64 | + if (!$user->isOAuthLinked()) { |
|
| 65 | + $oauthHelper = $this->getOAuthHelper(); |
|
| 66 | + |
|
| 67 | + $requestToken = $oauthHelper->getRequestToken(); |
|
| 68 | + $user->setOAuthRequestToken($requestToken->key); |
|
| 69 | + $user->setOAuthRequestSecret($requestToken->secret); |
|
| 70 | + $user->save(); |
|
| 71 | + |
|
| 72 | + WebRequest::setPartialLogin($user); |
|
| 73 | + $this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key)); |
|
| 74 | + |
|
| 75 | + return; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // User is partially linked to OAuth. This is not allowed. Enforce it for this user. |
|
| 80 | + if ($user->getOnWikiName() === '##OAUTH##') { |
|
| 81 | + $oauthHelper = $this->getOAuthHelper(); |
|
| 82 | + |
|
| 83 | + $requestToken = $oauthHelper->getRequestToken(); |
|
| 84 | + $user->setOAuthRequestToken($requestToken->key); |
|
| 85 | + $user->setOAuthRequestSecret($requestToken->secret); |
|
| 86 | + $user->save(); |
|
| 87 | + |
|
| 88 | + WebRequest::setPartialLogin($user); |
|
| 89 | + $this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key)); |
|
| 90 | + |
|
| 91 | + return; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + WebRequest::setLoggedInUser($user); |
|
| 95 | + |
|
| 96 | + $this->goBackWhenceYouCame($user); |
|
| 97 | + } |
|
| 98 | + else { |
|
| 99 | + // GET. Show the form |
|
| 100 | + $this->assignCSRFToken(); |
|
| 101 | + $this->setTemplate("login.tpl"); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return User |
|
| 107 | + * @throws ApplicationLogicException |
|
| 108 | + */ |
|
| 109 | + private function getAuthenticatingUser() |
|
| 110 | + { |
|
| 111 | + $username = WebRequest::postString("username"); |
|
| 112 | + $password = WebRequest::postString("password"); |
|
| 113 | + |
|
| 114 | + if ($username === null || $password === null || $username === "" || $password === "") { |
|
| 115 | + throw new ApplicationLogicException("No username/password specified"); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** @var User $user */ |
|
| 119 | + $user = User::getByUsername($username, $this->getDatabase()); |
|
| 120 | + |
|
| 121 | + if ($user == false || !$user->authenticate($password)) { |
|
| 122 | + throw new ApplicationLogicException("Authentication failed"); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return $user; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + protected function isProtectedPage() |
|
| 129 | + { |
|
| 130 | + return false; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Redirect the user back to wherever they came from after a successful login |
|
| 135 | + * |
|
| 136 | + * @param User $user |
|
| 137 | + */ |
|
| 138 | + private function goBackWhenceYouCame(User $user) |
|
| 139 | + { |
|
| 140 | + // Redirect to wherever the user came from |
|
| 141 | + $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
| 142 | + if ($redirectDestination !== null) { |
|
| 143 | + $this->redirectUrl($redirectDestination); |
|
| 144 | + } |
|
| 145 | + else { |
|
| 146 | + if ($user->isNewUser()) { |
|
| 147 | + // home page isn't allowed, go to preferences instead |
|
| 148 | + $this->redirect('preferences'); |
|
| 149 | + } |
|
| 150 | + else { |
|
| 151 | + // go to the home page |
|
| 152 | + $this->redirect(''); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -32,8 +32,7 @@ discard block |
||
| 32 | 32 | if (!headers_sent()) { |
| 33 | 33 | header("Strict-Transport-Security: max-age=15768000"); |
| 34 | 34 | } |
| 35 | - } |
|
| 36 | - else { |
|
| 35 | + } else { |
|
| 37 | 36 | // This is the login form, not the request form. We need protection here. |
| 38 | 37 | $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri()); |
| 39 | 38 | |
@@ -94,8 +93,7 @@ discard block |
||
| 94 | 93 | WebRequest::setLoggedInUser($user); |
| 95 | 94 | |
| 96 | 95 | $this->goBackWhenceYouCame($user); |
| 97 | - } |
|
| 98 | - else { |
|
| 96 | + } else { |
|
| 99 | 97 | // GET. Show the form |
| 100 | 98 | $this->assignCSRFToken(); |
| 101 | 99 | $this->setTemplate("login.tpl"); |
@@ -141,13 +139,11 @@ discard block |
||
| 141 | 139 | $redirectDestination = WebRequest::clearPostLoginRedirect(); |
| 142 | 140 | if ($redirectDestination !== null) { |
| 143 | 141 | $this->redirectUrl($redirectDestination); |
| 144 | - } |
|
| 145 | - else { |
|
| 142 | + } else { |
|
| 146 | 143 | if ($user->isNewUser()) { |
| 147 | 144 | // home page isn't allowed, go to preferences instead |
| 148 | 145 | $this->redirect('preferences'); |
| 149 | - } |
|
| 150 | - else { |
|
| 146 | + } else { |
|
| 151 | 147 | // go to the home page |
| 152 | 148 | $this->redirect(''); |
| 153 | 149 | } |
@@ -18,77 +18,77 @@ |
||
| 18 | 18 | |
| 19 | 19 | class PageExpandedRequestList extends InternalPageBase |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Main function for this page, when no specific actions are called. |
|
| 23 | - * @return void |
|
| 24 | - * @todo This is very similar to the PageMain code, we could probably generalise this somehow |
|
| 25 | - */ |
|
| 26 | - protected function main() |
|
| 27 | - { |
|
| 28 | - $config = $this->getSiteConfiguration(); |
|
| 21 | + /** |
|
| 22 | + * Main function for this page, when no specific actions are called. |
|
| 23 | + * @return void |
|
| 24 | + * @todo This is very similar to the PageMain code, we could probably generalise this somehow |
|
| 25 | + */ |
|
| 26 | + protected function main() |
|
| 27 | + { |
|
| 28 | + $config = $this->getSiteConfiguration(); |
|
| 29 | 29 | |
| 30 | - $requestedStatus = WebRequest::getString('status'); |
|
| 31 | - $requestStates = $config->getRequestStates(); |
|
| 30 | + $requestedStatus = WebRequest::getString('status'); |
|
| 31 | + $requestStates = $config->getRequestStates(); |
|
| 32 | 32 | |
| 33 | - if ($requestedStatus !== null && isset($requestStates[$requestedStatus])) { |
|
| 33 | + if ($requestedStatus !== null && isset($requestStates[$requestedStatus])) { |
|
| 34 | 34 | |
| 35 | - $this->assignCSRFToken(); |
|
| 35 | + $this->assignCSRFToken(); |
|
| 36 | 36 | |
| 37 | - $database = $this->getDatabase(); |
|
| 37 | + $database = $this->getDatabase(); |
|
| 38 | 38 | |
| 39 | - if ($config->getEmailConfirmationEnabled()) { |
|
| 40 | - $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 41 | - $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 42 | - } |
|
| 43 | - else { |
|
| 44 | - $query = "SELECT * FROM request WHERE status = :type;"; |
|
| 45 | - $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
|
| 46 | - } |
|
| 39 | + if ($config->getEmailConfirmationEnabled()) { |
|
| 40 | + $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 41 | + $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 42 | + } |
|
| 43 | + else { |
|
| 44 | + $query = "SELECT * FROM request WHERE status = :type;"; |
|
| 45 | + $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - $statement = $database->prepare($query); |
|
| 48 | + $statement = $database->prepare($query); |
|
| 49 | 49 | |
| 50 | - $totalRequestsStatement = $database->prepare($totalQuery); |
|
| 50 | + $totalRequestsStatement = $database->prepare($totalQuery); |
|
| 51 | 51 | |
| 52 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 52 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 53 | 53 | |
| 54 | - $type = $requestedStatus; |
|
| 54 | + $type = $requestedStatus; |
|
| 55 | 55 | |
| 56 | - $statement->bindValue(":type", $type); |
|
| 57 | - $statement->execute(); |
|
| 56 | + $statement->bindValue(":type", $type); |
|
| 57 | + $statement->execute(); |
|
| 58 | 58 | |
| 59 | - $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class); |
|
| 59 | + $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class); |
|
| 60 | 60 | |
| 61 | - /** @var Request $req */ |
|
| 62 | - foreach ($requests as $req) { |
|
| 63 | - $req->setDatabase($database); |
|
| 64 | - } |
|
| 61 | + /** @var Request $req */ |
|
| 62 | + foreach ($requests as $req) { |
|
| 63 | + $req->setDatabase($database); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - $this->assign('requests', $requests); |
|
| 67 | - $this->assign('header', $type); |
|
| 66 | + $this->assign('requests', $requests); |
|
| 67 | + $this->assign('header', $type); |
|
| 68 | 68 | |
| 69 | - $totalRequestsStatement->bindValue(':type', $type); |
|
| 70 | - $totalRequestsStatement->execute(); |
|
| 71 | - $totalRequests = $totalRequestsStatement->fetchColumn(); |
|
| 72 | - $totalRequestsStatement->closeCursor(); |
|
| 73 | - $this->assign('totalRequests', $totalRequests); |
|
| 69 | + $totalRequestsStatement->bindValue(':type', $type); |
|
| 70 | + $totalRequestsStatement->execute(); |
|
| 71 | + $totalRequests = $totalRequestsStatement->fetchColumn(); |
|
| 72 | + $totalRequestsStatement->closeCursor(); |
|
| 73 | + $this->assign('totalRequests', $totalRequests); |
|
| 74 | 74 | |
| 75 | - $userIds = array_map( |
|
| 76 | - function(Request $entry) { |
|
| 77 | - return $entry->getReserved(); |
|
| 78 | - }, |
|
| 79 | - $requests |
|
| 80 | - ); |
|
| 75 | + $userIds = array_map( |
|
| 76 | + function(Request $entry) { |
|
| 77 | + return $entry->getReserved(); |
|
| 78 | + }, |
|
| 79 | + $requests |
|
| 80 | + ); |
|
| 81 | 81 | |
| 82 | - $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
| 83 | - $this->assign('userlist', $userList); |
|
| 82 | + $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
| 83 | + $this->assign('userlist', $userList); |
|
| 84 | 84 | |
| 85 | - $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
| 85 | + $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
| 86 | 86 | |
| 87 | - $currentUser = User::getCurrent($database); |
|
| 88 | - $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 89 | - $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
| 87 | + $currentUser = User::getCurrent($database); |
|
| 88 | + $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 89 | + $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
| 90 | 90 | |
| 91 | - $this->setTemplate('mainpage/expandedrequestlist.tpl'); |
|
| 92 | - } |
|
| 93 | - } |
|
| 91 | + $this->setTemplate('mainpage/expandedrequestlist.tpl'); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -39,8 +39,7 @@ discard block |
||
| 39 | 39 | if ($config->getEmailConfirmationEnabled()) { |
| 40 | 40 | $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
| 41 | 41 | $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
| 42 | - } |
|
| 43 | - else { |
|
| 42 | + } else { |
|
| 44 | 43 | $query = "SELECT * FROM request WHERE status = :type;"; |
| 45 | 44 | $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
| 46 | 45 | } |
@@ -73,7 +72,8 @@ discard block |
||
| 73 | 72 | $this->assign('totalRequests', $totalRequests); |
| 74 | 73 | |
| 75 | 74 | $userIds = array_map( |
| 76 | - function(Request $entry) { |
|
| 75 | + function(Request $entry) |
|
| 76 | + { |
|
| 77 | 77 | return $entry->getReserved(); |
| 78 | 78 | }, |
| 79 | 79 | $requests |
@@ -13,17 +13,17 @@ |
||
| 13 | 13 | |
| 14 | 14 | class PageLogout extends InternalPageBase |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Main function for this page, when no specific actions are called. |
|
| 18 | - */ |
|
| 19 | - protected function main() |
|
| 20 | - { |
|
| 21 | - Session::destroy(); |
|
| 22 | - $this->redirect("login"); |
|
| 23 | - } |
|
| 16 | + /** |
|
| 17 | + * Main function for this page, when no specific actions are called. |
|
| 18 | + */ |
|
| 19 | + protected function main() |
|
| 20 | + { |
|
| 21 | + Session::destroy(); |
|
| 22 | + $this->redirect("login"); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - protected function isProtectedPage() |
|
| 26 | - { |
|
| 27 | - return false; |
|
| 28 | - } |
|
| 25 | + protected function isProtectedPage() |
|
| 26 | + { |
|
| 27 | + return false; |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -24,213 +24,213 @@ |
||
| 24 | 24 | |
| 25 | 25 | class PageViewRequest extends InternalPageBase |
| 26 | 26 | { |
| 27 | - use RequestData; |
|
| 28 | - const STATUS_SYMBOL_OPEN = '☐'; |
|
| 29 | - const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
| 30 | - const STATUS_SYMBOL_REJECTED = '☒'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Main function for this page, when no specific actions are called. |
|
| 34 | - * @throws ApplicationLogicException |
|
| 35 | - */ |
|
| 36 | - protected function main() |
|
| 37 | - { |
|
| 38 | - // set up csrf protection |
|
| 39 | - $this->assignCSRFToken(); |
|
| 40 | - |
|
| 41 | - // get some useful objects |
|
| 42 | - $database = $this->getDatabase(); |
|
| 43 | - $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
| 44 | - $config = $this->getSiteConfiguration(); |
|
| 45 | - $currentUser = User::getCurrent($database); |
|
| 46 | - |
|
| 47 | - // Test we should be able to look at this request |
|
| 48 | - if ($config->getEmailConfirmationEnabled()) { |
|
| 49 | - if ($request->getEmailConfirm() !== 'Confirmed') { |
|
| 50 | - // Not allowed to look at this yet. |
|
| 51 | - throw new ApplicationLogicException('The email address has not yet been confirmed for this request.'); |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - $this->setupBasicData($request, $config); |
|
| 56 | - |
|
| 57 | - $this->setupUsernameData($request); |
|
| 58 | - |
|
| 59 | - $this->setupTitle($request); |
|
| 60 | - |
|
| 61 | - $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 62 | - $this->setupGeneralData($database); |
|
| 63 | - |
|
| 64 | - $this->assign('requestDataCleared', false); |
|
| 65 | - if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 66 | - $this->assign('requestDataCleared', true); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 70 | - |
|
| 71 | - $this->setupLogData($request, $database); |
|
| 72 | - |
|
| 73 | - if ($allowedPrivateData) { |
|
| 74 | - $this->setTemplate('view-request/main-with-data.tpl'); |
|
| 75 | - $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
| 76 | - |
|
| 77 | - $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 78 | - $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')); |
|
| 79 | - |
|
| 80 | - if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
| 81 | - $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
| 82 | - $this->setupCheckUserData($request); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - else { |
|
| 86 | - $this->setTemplate('view-request/main.tpl'); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param Request $request |
|
| 92 | - */ |
|
| 93 | - protected function setupTitle(Request $request) |
|
| 94 | - { |
|
| 95 | - $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
| 96 | - if ($request->getStatus() === 'Closed') { |
|
| 97 | - if ($request->getWasCreated()) { |
|
| 98 | - $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
| 99 | - } |
|
| 100 | - else { |
|
| 101 | - $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Sets up data unrelated to the request, such as the email template information |
|
| 110 | - * |
|
| 111 | - * @param PdoDatabase $database |
|
| 112 | - */ |
|
| 113 | - protected function setupGeneralData(PdoDatabase $database) |
|
| 114 | - { |
|
| 115 | - $config = $this->getSiteConfiguration(); |
|
| 116 | - |
|
| 117 | - $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
| 118 | - |
|
| 119 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 120 | - |
|
| 121 | - $this->assign('requestStates', $config->getRequestStates()); |
|
| 122 | - |
|
| 123 | - /** @var EmailTemplate $createdTemplate */ |
|
| 124 | - $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database); |
|
| 125 | - |
|
| 126 | - $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
| 127 | - $this->assign('createdJsQuestion', $createdTemplate->getJsquestion()); |
|
| 128 | - $this->assign('createdId', $createdTemplate->getId()); |
|
| 129 | - $this->assign('createdName', $createdTemplate->getName()); |
|
| 130 | - |
|
| 131 | - $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 132 | - $this->assign("createReasons", $createReasons); |
|
| 133 | - $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 134 | - $this->assign("declineReasons", $declineReasons); |
|
| 135 | - |
|
| 136 | - $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 137 | - $this->assign("allCreateReasons", $allCreateReasons); |
|
| 138 | - $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 139 | - $this->assign("allDeclineReasons", $allDeclineReasons); |
|
| 140 | - $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
|
| 141 | - $this->assign("allOtherReasons", $allOtherReasons); |
|
| 142 | - |
|
| 143 | - $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
| 144 | - return UserSearchHelper::get($database)->byStatus('Active')->fetchColumn('username'); |
|
| 145 | - }); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - private function setupLogData(Request $request, PdoDatabase $database) |
|
| 149 | - { |
|
| 150 | - $currentUser = User::getCurrent($database); |
|
| 151 | - |
|
| 152 | - $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
| 153 | - $requestLogs = array(); |
|
| 154 | - |
|
| 155 | - if (trim($request->getComment()) !== "") { |
|
| 156 | - $requestLogs[] = array( |
|
| 157 | - 'type' => 'comment', |
|
| 158 | - 'security' => 'user', |
|
| 159 | - 'userid' => null, |
|
| 160 | - 'user' => $request->getName(), |
|
| 161 | - 'entry' => null, |
|
| 162 | - 'time' => $request->getDate(), |
|
| 163 | - 'canedit' => false, |
|
| 164 | - 'id' => $request->getId(), |
|
| 165 | - 'comment' => $request->getComment(), |
|
| 166 | - ); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** @var User[] $nameCache */ |
|
| 170 | - $nameCache = array(); |
|
| 171 | - |
|
| 172 | - $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
| 173 | - |
|
| 174 | - /** @var Log|Comment $entry */ |
|
| 175 | - foreach ($logs as $entry) { |
|
| 176 | - // both log and comment have a 'user' field |
|
| 177 | - if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
| 178 | - $entryUser = User::getById($entry->getUser(), $database); |
|
| 179 | - $nameCache[$entry->getUser()] = $entryUser; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if ($entry instanceof Comment) { |
|
| 183 | - $requestLogs[] = array( |
|
| 184 | - 'type' => 'comment', |
|
| 185 | - 'security' => $entry->getVisibility(), |
|
| 186 | - 'user' => $nameCache[$entry->getUser()]->getUsername(), |
|
| 187 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 188 | - 'entry' => null, |
|
| 189 | - 'time' => $entry->getTime(), |
|
| 190 | - 'canedit' => ($editableComments || $entry->getUser() == $currentUser->getId()), |
|
| 191 | - 'id' => $entry->getId(), |
|
| 192 | - 'comment' => $entry->getComment(), |
|
| 193 | - ); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if ($entry instanceof Log) { |
|
| 197 | - $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
| 198 | - $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
| 199 | - |
|
| 200 | - $requestLogs[] = array( |
|
| 201 | - 'type' => 'log', |
|
| 202 | - 'security' => 'user', |
|
| 203 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 204 | - 'user' => $entryUser->getUsername(), |
|
| 205 | - 'entry' => LogHelper::getLogDescription($entry), |
|
| 206 | - 'time' => $entry->getTimestamp(), |
|
| 207 | - 'canedit' => false, |
|
| 208 | - 'id' => $entry->getId(), |
|
| 209 | - 'comment' => $entry->getComment(), |
|
| 210 | - ); |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $this->assign("requestLogs", $requestLogs); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * @param Request $request |
|
| 219 | - */ |
|
| 220 | - protected function setupUsernameData(Request $request) |
|
| 221 | - { |
|
| 222 | - $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
| 223 | - |
|
| 224 | - $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
| 225 | - $this->assign('requestBlacklist', $blacklistData); |
|
| 226 | - |
|
| 227 | - try { |
|
| 228 | - $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
| 229 | - } |
|
| 230 | - catch (Exception $ex) { |
|
| 231 | - $spoofs = $ex->getMessage(); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $this->assign("spoofs", $spoofs); |
|
| 235 | - } |
|
| 27 | + use RequestData; |
|
| 28 | + const STATUS_SYMBOL_OPEN = '☐'; |
|
| 29 | + const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
| 30 | + const STATUS_SYMBOL_REJECTED = '☒'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Main function for this page, when no specific actions are called. |
|
| 34 | + * @throws ApplicationLogicException |
|
| 35 | + */ |
|
| 36 | + protected function main() |
|
| 37 | + { |
|
| 38 | + // set up csrf protection |
|
| 39 | + $this->assignCSRFToken(); |
|
| 40 | + |
|
| 41 | + // get some useful objects |
|
| 42 | + $database = $this->getDatabase(); |
|
| 43 | + $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
| 44 | + $config = $this->getSiteConfiguration(); |
|
| 45 | + $currentUser = User::getCurrent($database); |
|
| 46 | + |
|
| 47 | + // Test we should be able to look at this request |
|
| 48 | + if ($config->getEmailConfirmationEnabled()) { |
|
| 49 | + if ($request->getEmailConfirm() !== 'Confirmed') { |
|
| 50 | + // Not allowed to look at this yet. |
|
| 51 | + throw new ApplicationLogicException('The email address has not yet been confirmed for this request.'); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + $this->setupBasicData($request, $config); |
|
| 56 | + |
|
| 57 | + $this->setupUsernameData($request); |
|
| 58 | + |
|
| 59 | + $this->setupTitle($request); |
|
| 60 | + |
|
| 61 | + $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 62 | + $this->setupGeneralData($database); |
|
| 63 | + |
|
| 64 | + $this->assign('requestDataCleared', false); |
|
| 65 | + if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 66 | + $this->assign('requestDataCleared', true); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 70 | + |
|
| 71 | + $this->setupLogData($request, $database); |
|
| 72 | + |
|
| 73 | + if ($allowedPrivateData) { |
|
| 74 | + $this->setTemplate('view-request/main-with-data.tpl'); |
|
| 75 | + $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
| 76 | + |
|
| 77 | + $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 78 | + $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')); |
|
| 79 | + |
|
| 80 | + if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
| 81 | + $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
| 82 | + $this->setupCheckUserData($request); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + else { |
|
| 86 | + $this->setTemplate('view-request/main.tpl'); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param Request $request |
|
| 92 | + */ |
|
| 93 | + protected function setupTitle(Request $request) |
|
| 94 | + { |
|
| 95 | + $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
| 96 | + if ($request->getStatus() === 'Closed') { |
|
| 97 | + if ($request->getWasCreated()) { |
|
| 98 | + $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
| 99 | + } |
|
| 100 | + else { |
|
| 101 | + $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Sets up data unrelated to the request, such as the email template information |
|
| 110 | + * |
|
| 111 | + * @param PdoDatabase $database |
|
| 112 | + */ |
|
| 113 | + protected function setupGeneralData(PdoDatabase $database) |
|
| 114 | + { |
|
| 115 | + $config = $this->getSiteConfiguration(); |
|
| 116 | + |
|
| 117 | + $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
| 118 | + |
|
| 119 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 120 | + |
|
| 121 | + $this->assign('requestStates', $config->getRequestStates()); |
|
| 122 | + |
|
| 123 | + /** @var EmailTemplate $createdTemplate */ |
|
| 124 | + $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database); |
|
| 125 | + |
|
| 126 | + $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
| 127 | + $this->assign('createdJsQuestion', $createdTemplate->getJsquestion()); |
|
| 128 | + $this->assign('createdId', $createdTemplate->getId()); |
|
| 129 | + $this->assign('createdName', $createdTemplate->getName()); |
|
| 130 | + |
|
| 131 | + $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 132 | + $this->assign("createReasons", $createReasons); |
|
| 133 | + $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 134 | + $this->assign("declineReasons", $declineReasons); |
|
| 135 | + |
|
| 136 | + $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 137 | + $this->assign("allCreateReasons", $allCreateReasons); |
|
| 138 | + $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 139 | + $this->assign("allDeclineReasons", $allDeclineReasons); |
|
| 140 | + $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
|
| 141 | + $this->assign("allOtherReasons", $allOtherReasons); |
|
| 142 | + |
|
| 143 | + $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
| 144 | + return UserSearchHelper::get($database)->byStatus('Active')->fetchColumn('username'); |
|
| 145 | + }); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + private function setupLogData(Request $request, PdoDatabase $database) |
|
| 149 | + { |
|
| 150 | + $currentUser = User::getCurrent($database); |
|
| 151 | + |
|
| 152 | + $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
| 153 | + $requestLogs = array(); |
|
| 154 | + |
|
| 155 | + if (trim($request->getComment()) !== "") { |
|
| 156 | + $requestLogs[] = array( |
|
| 157 | + 'type' => 'comment', |
|
| 158 | + 'security' => 'user', |
|
| 159 | + 'userid' => null, |
|
| 160 | + 'user' => $request->getName(), |
|
| 161 | + 'entry' => null, |
|
| 162 | + 'time' => $request->getDate(), |
|
| 163 | + 'canedit' => false, |
|
| 164 | + 'id' => $request->getId(), |
|
| 165 | + 'comment' => $request->getComment(), |
|
| 166 | + ); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** @var User[] $nameCache */ |
|
| 170 | + $nameCache = array(); |
|
| 171 | + |
|
| 172 | + $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
| 173 | + |
|
| 174 | + /** @var Log|Comment $entry */ |
|
| 175 | + foreach ($logs as $entry) { |
|
| 176 | + // both log and comment have a 'user' field |
|
| 177 | + if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
| 178 | + $entryUser = User::getById($entry->getUser(), $database); |
|
| 179 | + $nameCache[$entry->getUser()] = $entryUser; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if ($entry instanceof Comment) { |
|
| 183 | + $requestLogs[] = array( |
|
| 184 | + 'type' => 'comment', |
|
| 185 | + 'security' => $entry->getVisibility(), |
|
| 186 | + 'user' => $nameCache[$entry->getUser()]->getUsername(), |
|
| 187 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 188 | + 'entry' => null, |
|
| 189 | + 'time' => $entry->getTime(), |
|
| 190 | + 'canedit' => ($editableComments || $entry->getUser() == $currentUser->getId()), |
|
| 191 | + 'id' => $entry->getId(), |
|
| 192 | + 'comment' => $entry->getComment(), |
|
| 193 | + ); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if ($entry instanceof Log) { |
|
| 197 | + $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
| 198 | + $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
| 199 | + |
|
| 200 | + $requestLogs[] = array( |
|
| 201 | + 'type' => 'log', |
|
| 202 | + 'security' => 'user', |
|
| 203 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 204 | + 'user' => $entryUser->getUsername(), |
|
| 205 | + 'entry' => LogHelper::getLogDescription($entry), |
|
| 206 | + 'time' => $entry->getTimestamp(), |
|
| 207 | + 'canedit' => false, |
|
| 208 | + 'id' => $entry->getId(), |
|
| 209 | + 'comment' => $entry->getComment(), |
|
| 210 | + ); |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $this->assign("requestLogs", $requestLogs); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * @param Request $request |
|
| 219 | + */ |
|
| 220 | + protected function setupUsernameData(Request $request) |
|
| 221 | + { |
|
| 222 | + $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
| 223 | + |
|
| 224 | + $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
| 225 | + $this->assign('requestBlacklist', $blacklistData); |
|
| 226 | + |
|
| 227 | + try { |
|
| 228 | + $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
| 229 | + } |
|
| 230 | + catch (Exception $ex) { |
|
| 231 | + $spoofs = $ex->getMessage(); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $this->assign("spoofs", $spoofs); |
|
| 235 | + } |
|
| 236 | 236 | } |
@@ -81,8 +81,7 @@ discard block |
||
| 81 | 81 | $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
| 82 | 82 | $this->setupCheckUserData($request); |
| 83 | 83 | } |
| 84 | - } |
|
| 85 | - else { |
|
| 84 | + } else { |
|
| 86 | 85 | $this->setTemplate('view-request/main.tpl'); |
| 87 | 86 | } |
| 88 | 87 | } |
@@ -96,8 +95,7 @@ discard block |
||
| 96 | 95 | if ($request->getStatus() === 'Closed') { |
| 97 | 96 | if ($request->getWasCreated()) { |
| 98 | 97 | $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
| 99 | - } |
|
| 100 | - else { |
|
| 98 | + } else { |
|
| 101 | 99 | $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
| 102 | 100 | } |
| 103 | 101 | } |
@@ -140,7 +138,8 @@ discard block |
||
| 140 | 138 | $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
| 141 | 139 | $this->assign("allOtherReasons", $allOtherReasons); |
| 142 | 140 | |
| 143 | - $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
| 141 | + $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) |
|
| 142 | + { |
|
| 144 | 143 | return UserSearchHelper::get($database)->byStatus('Active')->fetchColumn('username'); |
| 145 | 144 | }); |
| 146 | 145 | } |
@@ -16,99 +16,99 @@ |
||
| 16 | 16 | |
| 17 | 17 | class PagePreferences extends InternalPageBase |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Main function for this page, when no specific actions are called. |
|
| 21 | - * @return void |
|
| 22 | - */ |
|
| 23 | - protected function main() |
|
| 24 | - { |
|
| 25 | - $this->setHtmlTitle('Preferences'); |
|
| 26 | - |
|
| 27 | - $enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth(); |
|
| 28 | - |
|
| 29 | - // Dual mode |
|
| 30 | - if (WebRequest::wasPosted()) { |
|
| 31 | - $this->validateCSRFToken(); |
|
| 32 | - $user = User::getCurrent($this->getDatabase()); |
|
| 33 | - $user->setWelcomeSig(WebRequest::postString('sig')); |
|
| 34 | - $user->setEmailSig(WebRequest::postString('emailsig')); |
|
| 35 | - $user->setAbortPref(WebRequest::getBoolean('sig') ? 1 : 0); |
|
| 36 | - |
|
| 37 | - $email = WebRequest::postEmail('email'); |
|
| 38 | - if ($email !== null) { |
|
| 39 | - $user->setEmail($email); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - $user->save(); |
|
| 43 | - SessionAlert::success("Preferences updated!"); |
|
| 44 | - |
|
| 45 | - $this->redirect(''); |
|
| 46 | - } |
|
| 47 | - else { |
|
| 48 | - $this->assignCSRFToken(); |
|
| 49 | - $this->setTemplate('preferences/prefs.tpl'); |
|
| 50 | - $this->assign("enforceOAuth", $enforceOAuth); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - protected function changePassword() |
|
| 55 | - { |
|
| 56 | - $this->setHtmlTitle('Change Password'); |
|
| 57 | - |
|
| 58 | - if (WebRequest::wasPosted()) { |
|
| 59 | - $this->validateCSRFToken(); |
|
| 60 | - try { |
|
| 61 | - $oldPassword = WebRequest::postString('oldpassword'); |
|
| 62 | - $newPassword = WebRequest::postString('newpassword'); |
|
| 63 | - $newPasswordConfirmation = WebRequest::postString('newpasswordconfirm'); |
|
| 64 | - |
|
| 65 | - $user = User::getCurrent($this->getDatabase()); |
|
| 66 | - if (!$user instanceof User) { |
|
| 67 | - throw new ApplicationLogicException('User not found'); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $this->validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, $user); |
|
| 71 | - } |
|
| 72 | - catch (ApplicationLogicException $ex) { |
|
| 73 | - SessionAlert::error($ex->getMessage()); |
|
| 74 | - $this->redirect('preferences', 'changePassword'); |
|
| 75 | - |
|
| 76 | - return; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - $user->setPassword($newPassword); |
|
| 80 | - $user->save(); |
|
| 81 | - |
|
| 82 | - SessionAlert::success('Password changed successfully!'); |
|
| 83 | - |
|
| 84 | - $this->redirect('preferences'); |
|
| 85 | - } |
|
| 86 | - else { |
|
| 87 | - // not allowed to GET this. |
|
| 88 | - $this->redirect('preferences'); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param string $oldPassword |
|
| 94 | - * @param string $newPassword |
|
| 95 | - * @param string $newPasswordConfirmation |
|
| 96 | - * @param User $user |
|
| 97 | - * |
|
| 98 | - * @throws ApplicationLogicException |
|
| 99 | - */ |
|
| 100 | - protected function validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, User $user) |
|
| 101 | - { |
|
| 102 | - if ($oldPassword === null || $newPassword === null || $newPasswordConfirmation === null) { |
|
| 103 | - throw new ApplicationLogicException('All three fields must be completed to change your password'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ($newPassword !== $newPasswordConfirmation) { |
|
| 107 | - throw new ApplicationLogicException('Your new passwords did not match!'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if (!$user->authenticate($oldPassword)) { |
|
| 111 | - throw new ApplicationLogicException('The password you entered was incorrect.'); |
|
| 112 | - } |
|
| 113 | - } |
|
| 19 | + /** |
|
| 20 | + * Main function for this page, when no specific actions are called. |
|
| 21 | + * @return void |
|
| 22 | + */ |
|
| 23 | + protected function main() |
|
| 24 | + { |
|
| 25 | + $this->setHtmlTitle('Preferences'); |
|
| 26 | + |
|
| 27 | + $enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth(); |
|
| 28 | + |
|
| 29 | + // Dual mode |
|
| 30 | + if (WebRequest::wasPosted()) { |
|
| 31 | + $this->validateCSRFToken(); |
|
| 32 | + $user = User::getCurrent($this->getDatabase()); |
|
| 33 | + $user->setWelcomeSig(WebRequest::postString('sig')); |
|
| 34 | + $user->setEmailSig(WebRequest::postString('emailsig')); |
|
| 35 | + $user->setAbortPref(WebRequest::getBoolean('sig') ? 1 : 0); |
|
| 36 | + |
|
| 37 | + $email = WebRequest::postEmail('email'); |
|
| 38 | + if ($email !== null) { |
|
| 39 | + $user->setEmail($email); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + $user->save(); |
|
| 43 | + SessionAlert::success("Preferences updated!"); |
|
| 44 | + |
|
| 45 | + $this->redirect(''); |
|
| 46 | + } |
|
| 47 | + else { |
|
| 48 | + $this->assignCSRFToken(); |
|
| 49 | + $this->setTemplate('preferences/prefs.tpl'); |
|
| 50 | + $this->assign("enforceOAuth", $enforceOAuth); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + protected function changePassword() |
|
| 55 | + { |
|
| 56 | + $this->setHtmlTitle('Change Password'); |
|
| 57 | + |
|
| 58 | + if (WebRequest::wasPosted()) { |
|
| 59 | + $this->validateCSRFToken(); |
|
| 60 | + try { |
|
| 61 | + $oldPassword = WebRequest::postString('oldpassword'); |
|
| 62 | + $newPassword = WebRequest::postString('newpassword'); |
|
| 63 | + $newPasswordConfirmation = WebRequest::postString('newpasswordconfirm'); |
|
| 64 | + |
|
| 65 | + $user = User::getCurrent($this->getDatabase()); |
|
| 66 | + if (!$user instanceof User) { |
|
| 67 | + throw new ApplicationLogicException('User not found'); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $this->validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, $user); |
|
| 71 | + } |
|
| 72 | + catch (ApplicationLogicException $ex) { |
|
| 73 | + SessionAlert::error($ex->getMessage()); |
|
| 74 | + $this->redirect('preferences', 'changePassword'); |
|
| 75 | + |
|
| 76 | + return; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + $user->setPassword($newPassword); |
|
| 80 | + $user->save(); |
|
| 81 | + |
|
| 82 | + SessionAlert::success('Password changed successfully!'); |
|
| 83 | + |
|
| 84 | + $this->redirect('preferences'); |
|
| 85 | + } |
|
| 86 | + else { |
|
| 87 | + // not allowed to GET this. |
|
| 88 | + $this->redirect('preferences'); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param string $oldPassword |
|
| 94 | + * @param string $newPassword |
|
| 95 | + * @param string $newPasswordConfirmation |
|
| 96 | + * @param User $user |
|
| 97 | + * |
|
| 98 | + * @throws ApplicationLogicException |
|
| 99 | + */ |
|
| 100 | + protected function validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, User $user) |
|
| 101 | + { |
|
| 102 | + if ($oldPassword === null || $newPassword === null || $newPasswordConfirmation === null) { |
|
| 103 | + throw new ApplicationLogicException('All three fields must be completed to change your password'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ($newPassword !== $newPasswordConfirmation) { |
|
| 107 | + throw new ApplicationLogicException('Your new passwords did not match!'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if (!$user->authenticate($oldPassword)) { |
|
| 111 | + throw new ApplicationLogicException('The password you entered was incorrect.'); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | 114 | } |
@@ -43,8 +43,7 @@ discard block |
||
| 43 | 43 | SessionAlert::success("Preferences updated!"); |
| 44 | 44 | |
| 45 | 45 | $this->redirect(''); |
| 46 | - } |
|
| 47 | - else { |
|
| 46 | + } else { |
|
| 48 | 47 | $this->assignCSRFToken(); |
| 49 | 48 | $this->setTemplate('preferences/prefs.tpl'); |
| 50 | 49 | $this->assign("enforceOAuth", $enforceOAuth); |
@@ -82,8 +81,7 @@ discard block |
||
| 82 | 81 | SessionAlert::success('Password changed successfully!'); |
| 83 | 82 | |
| 84 | 83 | $this->redirect('preferences'); |
| 85 | - } |
|
| 86 | - else { |
|
| 84 | + } else { |
|
| 87 | 85 | // not allowed to GET this. |
| 88 | 86 | $this->redirect('preferences'); |
| 89 | 87 | } |
@@ -21,310 +21,310 @@ |
||
| 21 | 21 | |
| 22 | 22 | class PageBan extends InternalPageBase |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Main function for this page, when no specific actions are called. |
|
| 26 | - */ |
|
| 27 | - protected function main() |
|
| 28 | - { |
|
| 29 | - $this->assignCSRFToken(); |
|
| 30 | - |
|
| 31 | - $this->setHtmlTitle('Bans'); |
|
| 32 | - |
|
| 33 | - $bans = Ban::getActiveBans(null, $this->getDatabase()); |
|
| 34 | - |
|
| 35 | - $userIds = array_map( |
|
| 36 | - function(Ban $entry) { |
|
| 37 | - return $entry->getUser(); |
|
| 38 | - }, |
|
| 39 | - $bans); |
|
| 40 | - $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
| 41 | - |
|
| 42 | - $user = User::getCurrent($this->getDatabase()); |
|
| 43 | - $this->assign('canSet', $this->barrierTest('set', $user)); |
|
| 44 | - $this->assign('canRemove', $this->barrierTest('remove', $user)); |
|
| 45 | - |
|
| 46 | - $this->assign('usernames', $userList); |
|
| 47 | - $this->assign('activebans', $bans); |
|
| 48 | - $this->setTemplate('bans/banlist.tpl'); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Entry point for the ban set action |
|
| 53 | - */ |
|
| 54 | - protected function set() |
|
| 55 | - { |
|
| 56 | - $this->setHtmlTitle('Bans'); |
|
| 57 | - |
|
| 58 | - // dual-mode action |
|
| 59 | - if (WebRequest::wasPosted()) { |
|
| 60 | - try { |
|
| 61 | - $this->handlePostMethodForSetBan(); |
|
| 62 | - } |
|
| 63 | - catch (ApplicationLogicException $ex) { |
|
| 64 | - SessionAlert::error($ex->getMessage()); |
|
| 65 | - $this->redirect("bans", "set"); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - else { |
|
| 69 | - $this->handleGetMethodForSetBan(); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Entry point for the ban remove action |
|
| 75 | - */ |
|
| 76 | - protected function remove() |
|
| 77 | - { |
|
| 78 | - $this->setHtmlTitle('Bans'); |
|
| 79 | - |
|
| 80 | - $ban = $this->getBanForUnban(); |
|
| 81 | - |
|
| 82 | - // dual mode |
|
| 83 | - if (WebRequest::wasPosted()) { |
|
| 84 | - $this->validateCSRFToken(); |
|
| 85 | - $unbanReason = WebRequest::postString('unbanreason'); |
|
| 86 | - |
|
| 87 | - if ($unbanReason === null || trim($unbanReason) === "") { |
|
| 88 | - SessionAlert::error('No unban reason specified'); |
|
| 89 | - $this->redirect("bans", "remove", array('id' => $ban->getId())); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // set optimistic locking from delete form page load |
|
| 93 | - $updateVersion = WebRequest::postInt('updateversion'); |
|
| 94 | - $ban->setUpdateVersion($updateVersion); |
|
| 95 | - |
|
| 96 | - $database = $this->getDatabase(); |
|
| 97 | - $ban->setActive(false); |
|
| 98 | - $ban->save(); |
|
| 99 | - |
|
| 100 | - Logger::unbanned($database, $ban, $unbanReason); |
|
| 101 | - |
|
| 102 | - SessionAlert::quick('Disabled ban.'); |
|
| 103 | - $this->getNotificationHelper()->unbanned($ban, $unbanReason); |
|
| 104 | - |
|
| 105 | - $this->redirect('bans'); |
|
| 106 | - } |
|
| 107 | - else { |
|
| 108 | - $this->assignCSRFToken(); |
|
| 109 | - $this->assign('ban', $ban); |
|
| 110 | - $this->setTemplate('bans/unban.tpl'); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @throws ApplicationLogicException |
|
| 116 | - */ |
|
| 117 | - private function getBanDuration() |
|
| 118 | - { |
|
| 119 | - $duration = WebRequest::postString('duration'); |
|
| 120 | - if ($duration === "other") { |
|
| 121 | - $duration = strtotime(WebRequest::postString('otherduration')); |
|
| 122 | - |
|
| 123 | - if (!$duration) { |
|
| 124 | - throw new ApplicationLogicException('Invalid ban time'); |
|
| 125 | - } |
|
| 126 | - elseif (time() > $duration) { |
|
| 127 | - throw new ApplicationLogicException('Ban time has already expired!'); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - return $duration; |
|
| 131 | - } |
|
| 132 | - elseif ($duration === "-1") { |
|
| 133 | - $duration = -1; |
|
| 134 | - |
|
| 135 | - return $duration; |
|
| 136 | - } |
|
| 137 | - else { |
|
| 138 | - $duration = WebRequest::postInt('duration') + time(); |
|
| 139 | - |
|
| 140 | - return $duration; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param string $type |
|
| 146 | - * @param string $target |
|
| 147 | - * |
|
| 148 | - * @throws ApplicationLogicException |
|
| 149 | - */ |
|
| 150 | - private function validateBanType($type, $target) |
|
| 151 | - { |
|
| 152 | - switch ($type) { |
|
| 153 | - case 'IP': |
|
| 154 | - $this->validateIpBan($target); |
|
| 155 | - |
|
| 156 | - return; |
|
| 157 | - case 'Name': |
|
| 158 | - // No validation needed here. |
|
| 159 | - return; |
|
| 160 | - case 'EMail': |
|
| 161 | - $this->validateEmailBanTarget($target); |
|
| 162 | - |
|
| 163 | - return; |
|
| 164 | - default: |
|
| 165 | - throw new ApplicationLogicException("Unknown ban type"); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Handles the POST method on the set action |
|
| 171 | - * |
|
| 172 | - * @throws ApplicationLogicException |
|
| 173 | - * @throws Exception |
|
| 174 | - */ |
|
| 175 | - private function handlePostMethodForSetBan() |
|
| 176 | - { |
|
| 177 | - $this->validateCSRFToken(); |
|
| 178 | - $reason = WebRequest::postString('banreason'); |
|
| 179 | - $target = WebRequest::postString('target'); |
|
| 180 | - |
|
| 181 | - // Checks whether there is a reason entered for ban. |
|
| 182 | - if ($reason === null || trim($reason) === "") { |
|
| 183 | - throw new ApplicationLogicException('You must specify a ban reason'); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // Checks whether there is a target entered to ban. |
|
| 187 | - if ($target === null || trim($target) === "") { |
|
| 188 | - throw new ApplicationLogicException('You must specify a target to be banned'); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Validate ban duration |
|
| 192 | - $duration = $this->getBanDuration(); |
|
| 193 | - |
|
| 194 | - // Validate ban type & target for that type |
|
| 195 | - $type = WebRequest::postString('type'); |
|
| 196 | - $this->validateBanType($type, $target); |
|
| 197 | - |
|
| 198 | - $database = $this->getDatabase(); |
|
| 199 | - |
|
| 200 | - if (count(Ban::getActiveBans($target, $database)) > 0) { |
|
| 201 | - throw new ApplicationLogicException('This target is already banned!'); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $ban = new Ban(); |
|
| 205 | - $ban->setDatabase($database); |
|
| 206 | - $ban->setActive(true); |
|
| 207 | - $ban->setType($type); |
|
| 208 | - $ban->setTarget($target); |
|
| 209 | - $ban->setUser(User::getCurrent($database)->getId()); |
|
| 210 | - $ban->setReason($reason); |
|
| 211 | - $ban->setDuration($duration); |
|
| 212 | - |
|
| 213 | - $ban->save(); |
|
| 214 | - |
|
| 215 | - Logger::banned($database, $ban, $reason); |
|
| 216 | - |
|
| 217 | - $this->getNotificationHelper()->banned($ban); |
|
| 218 | - SessionAlert::quick('Ban has been set.'); |
|
| 219 | - |
|
| 220 | - $this->redirect('bans'); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Handles the GET method on the set action |
|
| 225 | - */ |
|
| 226 | - protected function handleGetMethodForSetBan() |
|
| 227 | - { |
|
| 228 | - $this->setTemplate('bans/banform.tpl'); |
|
| 229 | - $this->assignCSRFToken(); |
|
| 230 | - |
|
| 231 | - $banType = WebRequest::getString('type'); |
|
| 232 | - $banTarget = WebRequest::getInt('request'); |
|
| 233 | - |
|
| 234 | - $database = $this->getDatabase(); |
|
| 235 | - |
|
| 236 | - // if the parameters are null, skip loading a request. |
|
| 237 | - if ($banType === null |
|
| 238 | - || !in_array($banType, array('IP', 'Name', 'EMail')) |
|
| 239 | - || $banTarget === null |
|
| 240 | - || $banTarget === 0 |
|
| 241 | - ) { |
|
| 242 | - $this->assign('bantarget', ''); |
|
| 243 | - $this->assign('bantype', ''); |
|
| 244 | - |
|
| 245 | - return; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // Set the ban type, which the user has indicated. |
|
| 249 | - $this->assign('bantype', $banType); |
|
| 250 | - |
|
| 251 | - // Attempt to resolve the correct target |
|
| 252 | - /** @var Request $request */ |
|
| 253 | - $request = Request::getById($banTarget, $database); |
|
| 254 | - if ($request === false) { |
|
| 255 | - $this->assign('bantarget', ''); |
|
| 256 | - |
|
| 257 | - return; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - $realTarget = ''; |
|
| 261 | - switch ($banType) { |
|
| 262 | - case 'EMail': |
|
| 263 | - $realTarget = $request->getEmail(); |
|
| 264 | - break; |
|
| 265 | - case 'IP': |
|
| 266 | - $xffProvider = $this->getXffTrustProvider(); |
|
| 267 | - $realTarget = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 268 | - break; |
|
| 269 | - case 'Name': |
|
| 270 | - $realTarget = $request->getName(); |
|
| 271 | - break; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - $this->assign('bantarget', $realTarget); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Validates an IP ban target |
|
| 279 | - * |
|
| 280 | - * @param string $target |
|
| 281 | - * |
|
| 282 | - * @throws ApplicationLogicException |
|
| 283 | - */ |
|
| 284 | - private function validateIpBan($target) |
|
| 285 | - { |
|
| 286 | - $squidIpList = $this->getSiteConfiguration()->getSquidList(); |
|
| 287 | - |
|
| 288 | - if (filter_var($target, FILTER_VALIDATE_IP) === false) { |
|
| 289 | - throw new ApplicationLogicException('Invalid target - IP address expected.'); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if (in_array($target, $squidIpList)) { |
|
| 293 | - throw new ApplicationLogicException("This IP address is on the protected list of proxies, and cannot be banned."); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Validates an email address as a ban target |
|
| 299 | - * |
|
| 300 | - * @param string $target |
|
| 301 | - * |
|
| 302 | - * @throws ApplicationLogicException |
|
| 303 | - */ |
|
| 304 | - private function validateEmailBanTarget($target) |
|
| 305 | - { |
|
| 306 | - if (filter_var($target, FILTER_VALIDATE_EMAIL) !== $target) { |
|
| 307 | - throw new ApplicationLogicException('Invalid target - email address expected.'); |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * @return Ban |
|
| 313 | - * @throws ApplicationLogicException |
|
| 314 | - */ |
|
| 315 | - private function getBanForUnban() |
|
| 316 | - { |
|
| 317 | - $banId = WebRequest::getInt('id'); |
|
| 318 | - if ($banId === null || $banId === 0) { |
|
| 319 | - throw new ApplicationLogicException("The ban ID appears to be missing. This is probably a bug."); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - $ban = Ban::getActiveId($banId, $this->getDatabase()); |
|
| 323 | - |
|
| 324 | - if ($ban === false) { |
|
| 325 | - throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist."); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - return $ban; |
|
| 329 | - } |
|
| 24 | + /** |
|
| 25 | + * Main function for this page, when no specific actions are called. |
|
| 26 | + */ |
|
| 27 | + protected function main() |
|
| 28 | + { |
|
| 29 | + $this->assignCSRFToken(); |
|
| 30 | + |
|
| 31 | + $this->setHtmlTitle('Bans'); |
|
| 32 | + |
|
| 33 | + $bans = Ban::getActiveBans(null, $this->getDatabase()); |
|
| 34 | + |
|
| 35 | + $userIds = array_map( |
|
| 36 | + function(Ban $entry) { |
|
| 37 | + return $entry->getUser(); |
|
| 38 | + }, |
|
| 39 | + $bans); |
|
| 40 | + $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
| 41 | + |
|
| 42 | + $user = User::getCurrent($this->getDatabase()); |
|
| 43 | + $this->assign('canSet', $this->barrierTest('set', $user)); |
|
| 44 | + $this->assign('canRemove', $this->barrierTest('remove', $user)); |
|
| 45 | + |
|
| 46 | + $this->assign('usernames', $userList); |
|
| 47 | + $this->assign('activebans', $bans); |
|
| 48 | + $this->setTemplate('bans/banlist.tpl'); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Entry point for the ban set action |
|
| 53 | + */ |
|
| 54 | + protected function set() |
|
| 55 | + { |
|
| 56 | + $this->setHtmlTitle('Bans'); |
|
| 57 | + |
|
| 58 | + // dual-mode action |
|
| 59 | + if (WebRequest::wasPosted()) { |
|
| 60 | + try { |
|
| 61 | + $this->handlePostMethodForSetBan(); |
|
| 62 | + } |
|
| 63 | + catch (ApplicationLogicException $ex) { |
|
| 64 | + SessionAlert::error($ex->getMessage()); |
|
| 65 | + $this->redirect("bans", "set"); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + else { |
|
| 69 | + $this->handleGetMethodForSetBan(); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Entry point for the ban remove action |
|
| 75 | + */ |
|
| 76 | + protected function remove() |
|
| 77 | + { |
|
| 78 | + $this->setHtmlTitle('Bans'); |
|
| 79 | + |
|
| 80 | + $ban = $this->getBanForUnban(); |
|
| 81 | + |
|
| 82 | + // dual mode |
|
| 83 | + if (WebRequest::wasPosted()) { |
|
| 84 | + $this->validateCSRFToken(); |
|
| 85 | + $unbanReason = WebRequest::postString('unbanreason'); |
|
| 86 | + |
|
| 87 | + if ($unbanReason === null || trim($unbanReason) === "") { |
|
| 88 | + SessionAlert::error('No unban reason specified'); |
|
| 89 | + $this->redirect("bans", "remove", array('id' => $ban->getId())); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // set optimistic locking from delete form page load |
|
| 93 | + $updateVersion = WebRequest::postInt('updateversion'); |
|
| 94 | + $ban->setUpdateVersion($updateVersion); |
|
| 95 | + |
|
| 96 | + $database = $this->getDatabase(); |
|
| 97 | + $ban->setActive(false); |
|
| 98 | + $ban->save(); |
|
| 99 | + |
|
| 100 | + Logger::unbanned($database, $ban, $unbanReason); |
|
| 101 | + |
|
| 102 | + SessionAlert::quick('Disabled ban.'); |
|
| 103 | + $this->getNotificationHelper()->unbanned($ban, $unbanReason); |
|
| 104 | + |
|
| 105 | + $this->redirect('bans'); |
|
| 106 | + } |
|
| 107 | + else { |
|
| 108 | + $this->assignCSRFToken(); |
|
| 109 | + $this->assign('ban', $ban); |
|
| 110 | + $this->setTemplate('bans/unban.tpl'); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @throws ApplicationLogicException |
|
| 116 | + */ |
|
| 117 | + private function getBanDuration() |
|
| 118 | + { |
|
| 119 | + $duration = WebRequest::postString('duration'); |
|
| 120 | + if ($duration === "other") { |
|
| 121 | + $duration = strtotime(WebRequest::postString('otherduration')); |
|
| 122 | + |
|
| 123 | + if (!$duration) { |
|
| 124 | + throw new ApplicationLogicException('Invalid ban time'); |
|
| 125 | + } |
|
| 126 | + elseif (time() > $duration) { |
|
| 127 | + throw new ApplicationLogicException('Ban time has already expired!'); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + return $duration; |
|
| 131 | + } |
|
| 132 | + elseif ($duration === "-1") { |
|
| 133 | + $duration = -1; |
|
| 134 | + |
|
| 135 | + return $duration; |
|
| 136 | + } |
|
| 137 | + else { |
|
| 138 | + $duration = WebRequest::postInt('duration') + time(); |
|
| 139 | + |
|
| 140 | + return $duration; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param string $type |
|
| 146 | + * @param string $target |
|
| 147 | + * |
|
| 148 | + * @throws ApplicationLogicException |
|
| 149 | + */ |
|
| 150 | + private function validateBanType($type, $target) |
|
| 151 | + { |
|
| 152 | + switch ($type) { |
|
| 153 | + case 'IP': |
|
| 154 | + $this->validateIpBan($target); |
|
| 155 | + |
|
| 156 | + return; |
|
| 157 | + case 'Name': |
|
| 158 | + // No validation needed here. |
|
| 159 | + return; |
|
| 160 | + case 'EMail': |
|
| 161 | + $this->validateEmailBanTarget($target); |
|
| 162 | + |
|
| 163 | + return; |
|
| 164 | + default: |
|
| 165 | + throw new ApplicationLogicException("Unknown ban type"); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Handles the POST method on the set action |
|
| 171 | + * |
|
| 172 | + * @throws ApplicationLogicException |
|
| 173 | + * @throws Exception |
|
| 174 | + */ |
|
| 175 | + private function handlePostMethodForSetBan() |
|
| 176 | + { |
|
| 177 | + $this->validateCSRFToken(); |
|
| 178 | + $reason = WebRequest::postString('banreason'); |
|
| 179 | + $target = WebRequest::postString('target'); |
|
| 180 | + |
|
| 181 | + // Checks whether there is a reason entered for ban. |
|
| 182 | + if ($reason === null || trim($reason) === "") { |
|
| 183 | + throw new ApplicationLogicException('You must specify a ban reason'); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // Checks whether there is a target entered to ban. |
|
| 187 | + if ($target === null || trim($target) === "") { |
|
| 188 | + throw new ApplicationLogicException('You must specify a target to be banned'); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Validate ban duration |
|
| 192 | + $duration = $this->getBanDuration(); |
|
| 193 | + |
|
| 194 | + // Validate ban type & target for that type |
|
| 195 | + $type = WebRequest::postString('type'); |
|
| 196 | + $this->validateBanType($type, $target); |
|
| 197 | + |
|
| 198 | + $database = $this->getDatabase(); |
|
| 199 | + |
|
| 200 | + if (count(Ban::getActiveBans($target, $database)) > 0) { |
|
| 201 | + throw new ApplicationLogicException('This target is already banned!'); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $ban = new Ban(); |
|
| 205 | + $ban->setDatabase($database); |
|
| 206 | + $ban->setActive(true); |
|
| 207 | + $ban->setType($type); |
|
| 208 | + $ban->setTarget($target); |
|
| 209 | + $ban->setUser(User::getCurrent($database)->getId()); |
|
| 210 | + $ban->setReason($reason); |
|
| 211 | + $ban->setDuration($duration); |
|
| 212 | + |
|
| 213 | + $ban->save(); |
|
| 214 | + |
|
| 215 | + Logger::banned($database, $ban, $reason); |
|
| 216 | + |
|
| 217 | + $this->getNotificationHelper()->banned($ban); |
|
| 218 | + SessionAlert::quick('Ban has been set.'); |
|
| 219 | + |
|
| 220 | + $this->redirect('bans'); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Handles the GET method on the set action |
|
| 225 | + */ |
|
| 226 | + protected function handleGetMethodForSetBan() |
|
| 227 | + { |
|
| 228 | + $this->setTemplate('bans/banform.tpl'); |
|
| 229 | + $this->assignCSRFToken(); |
|
| 230 | + |
|
| 231 | + $banType = WebRequest::getString('type'); |
|
| 232 | + $banTarget = WebRequest::getInt('request'); |
|
| 233 | + |
|
| 234 | + $database = $this->getDatabase(); |
|
| 235 | + |
|
| 236 | + // if the parameters are null, skip loading a request. |
|
| 237 | + if ($banType === null |
|
| 238 | + || !in_array($banType, array('IP', 'Name', 'EMail')) |
|
| 239 | + || $banTarget === null |
|
| 240 | + || $banTarget === 0 |
|
| 241 | + ) { |
|
| 242 | + $this->assign('bantarget', ''); |
|
| 243 | + $this->assign('bantype', ''); |
|
| 244 | + |
|
| 245 | + return; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // Set the ban type, which the user has indicated. |
|
| 249 | + $this->assign('bantype', $banType); |
|
| 250 | + |
|
| 251 | + // Attempt to resolve the correct target |
|
| 252 | + /** @var Request $request */ |
|
| 253 | + $request = Request::getById($banTarget, $database); |
|
| 254 | + if ($request === false) { |
|
| 255 | + $this->assign('bantarget', ''); |
|
| 256 | + |
|
| 257 | + return; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + $realTarget = ''; |
|
| 261 | + switch ($banType) { |
|
| 262 | + case 'EMail': |
|
| 263 | + $realTarget = $request->getEmail(); |
|
| 264 | + break; |
|
| 265 | + case 'IP': |
|
| 266 | + $xffProvider = $this->getXffTrustProvider(); |
|
| 267 | + $realTarget = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 268 | + break; |
|
| 269 | + case 'Name': |
|
| 270 | + $realTarget = $request->getName(); |
|
| 271 | + break; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + $this->assign('bantarget', $realTarget); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Validates an IP ban target |
|
| 279 | + * |
|
| 280 | + * @param string $target |
|
| 281 | + * |
|
| 282 | + * @throws ApplicationLogicException |
|
| 283 | + */ |
|
| 284 | + private function validateIpBan($target) |
|
| 285 | + { |
|
| 286 | + $squidIpList = $this->getSiteConfiguration()->getSquidList(); |
|
| 287 | + |
|
| 288 | + if (filter_var($target, FILTER_VALIDATE_IP) === false) { |
|
| 289 | + throw new ApplicationLogicException('Invalid target - IP address expected.'); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if (in_array($target, $squidIpList)) { |
|
| 293 | + throw new ApplicationLogicException("This IP address is on the protected list of proxies, and cannot be banned."); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Validates an email address as a ban target |
|
| 299 | + * |
|
| 300 | + * @param string $target |
|
| 301 | + * |
|
| 302 | + * @throws ApplicationLogicException |
|
| 303 | + */ |
|
| 304 | + private function validateEmailBanTarget($target) |
|
| 305 | + { |
|
| 306 | + if (filter_var($target, FILTER_VALIDATE_EMAIL) !== $target) { |
|
| 307 | + throw new ApplicationLogicException('Invalid target - email address expected.'); |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * @return Ban |
|
| 313 | + * @throws ApplicationLogicException |
|
| 314 | + */ |
|
| 315 | + private function getBanForUnban() |
|
| 316 | + { |
|
| 317 | + $banId = WebRequest::getInt('id'); |
|
| 318 | + if ($banId === null || $banId === 0) { |
|
| 319 | + throw new ApplicationLogicException("The ban ID appears to be missing. This is probably a bug."); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + $ban = Ban::getActiveId($banId, $this->getDatabase()); |
|
| 323 | + |
|
| 324 | + if ($ban === false) { |
|
| 325 | + throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist."); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + return $ban; |
|
| 329 | + } |
|
| 330 | 330 | } |
@@ -33,7 +33,8 @@ discard block |
||
| 33 | 33 | $bans = Ban::getActiveBans(null, $this->getDatabase()); |
| 34 | 34 | |
| 35 | 35 | $userIds = array_map( |
| 36 | - function(Ban $entry) { |
|
| 36 | + function(Ban $entry) |
|
| 37 | + { |
|
| 37 | 38 | return $entry->getUser(); |
| 38 | 39 | }, |
| 39 | 40 | $bans); |
@@ -64,8 +65,7 @@ discard block |
||
| 64 | 65 | SessionAlert::error($ex->getMessage()); |
| 65 | 66 | $this->redirect("bans", "set"); |
| 66 | 67 | } |
| 67 | - } |
|
| 68 | - else { |
|
| 68 | + } else { |
|
| 69 | 69 | $this->handleGetMethodForSetBan(); |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -103,8 +103,7 @@ discard block |
||
| 103 | 103 | $this->getNotificationHelper()->unbanned($ban, $unbanReason); |
| 104 | 104 | |
| 105 | 105 | $this->redirect('bans'); |
| 106 | - } |
|
| 107 | - else { |
|
| 106 | + } else { |
|
| 108 | 107 | $this->assignCSRFToken(); |
| 109 | 108 | $this->assign('ban', $ban); |
| 110 | 109 | $this->setTemplate('bans/unban.tpl'); |
@@ -122,19 +121,16 @@ discard block |
||
| 122 | 121 | |
| 123 | 122 | if (!$duration) { |
| 124 | 123 | throw new ApplicationLogicException('Invalid ban time'); |
| 125 | - } |
|
| 126 | - elseif (time() > $duration) { |
|
| 124 | + } elseif (time() > $duration) { |
|
| 127 | 125 | throw new ApplicationLogicException('Ban time has already expired!'); |
| 128 | 126 | } |
| 129 | 127 | |
| 130 | 128 | return $duration; |
| 131 | - } |
|
| 132 | - elseif ($duration === "-1") { |
|
| 129 | + } elseif ($duration === "-1") { |
|
| 133 | 130 | $duration = -1; |
| 134 | 131 | |
| 135 | 132 | return $duration; |
| 136 | - } |
|
| 137 | - else { |
|
| 133 | + } else { |
|
| 138 | 134 | $duration = WebRequest::postInt('duration') + time(); |
| 139 | 135 | |
| 140 | 136 | return $duration; |