@@ -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 | } |
@@ -12,17 +12,17 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PageRegisterOption extends InternalPageBase |
| 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('registration/option.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('registration/option.tpl'); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - protected function isProtectedPage() |
|
| 25 | - { |
|
| 26 | - return false; |
|
| 27 | - } |
|
| 24 | + protected function isProtectedPage() |
|
| 25 | + { |
|
| 26 | + return false; |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -18,202 +18,202 @@ |
||
| 18 | 18 | |
| 19 | 19 | abstract class PageRegisterBase extends InternalPageBase |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Main function for this page, when no specific actions are called. |
|
| 23 | - */ |
|
| 24 | - protected function main() |
|
| 25 | - { |
|
| 26 | - $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup(); |
|
| 27 | - |
|
| 28 | - // Dual-mode page |
|
| 29 | - if (WebRequest::wasPosted()) { |
|
| 30 | - $this->validateCSRFToken(); |
|
| 31 | - |
|
| 32 | - try { |
|
| 33 | - $this->handlePost($useOAuthSignup); |
|
| 34 | - } |
|
| 35 | - catch (ApplicationLogicException $ex) { |
|
| 36 | - SessionAlert::error($ex->getMessage()); |
|
| 37 | - $this->redirect('register'); |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - else { |
|
| 41 | - $this->assignCSRFToken(); |
|
| 42 | - $this->assign("useOAuthSignup", $useOAuthSignup); |
|
| 43 | - $this->setTemplate($this->getRegistrationTemplate()); |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - protected abstract function getRegistrationTemplate(); |
|
| 48 | - |
|
| 49 | - protected function isProtectedPage() |
|
| 50 | - { |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @param string $emailAddress |
|
| 56 | - * |
|
| 57 | - * @throws ApplicationLogicException |
|
| 58 | - */ |
|
| 59 | - protected function validateUniqueEmail($emailAddress) |
|
| 60 | - { |
|
| 61 | - $query = 'SELECT COUNT(id) FROM user WHERE email = :email'; |
|
| 62 | - $statement = $this->getDatabase()->prepare($query); |
|
| 63 | - $statement->execute(array(':email' => $emailAddress)); |
|
| 64 | - |
|
| 65 | - if ($statement->fetchColumn() > 0) { |
|
| 66 | - throw new ApplicationLogicException('That email address is already in use on this system.'); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - $statement->closeCursor(); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param $emailAddress |
|
| 74 | - * @param $password |
|
| 75 | - * @param $username |
|
| 76 | - * @param $useOAuthSignup |
|
| 77 | - * @param $confirmationId |
|
| 78 | - * @param $onwikiUsername |
|
| 79 | - * |
|
| 80 | - * @throws ApplicationLogicException |
|
| 81 | - */ |
|
| 82 | - protected function validateRequest( |
|
| 83 | - $emailAddress, |
|
| 84 | - $password, |
|
| 85 | - $username, |
|
| 86 | - $useOAuthSignup, |
|
| 87 | - $confirmationId, |
|
| 88 | - $onwikiUsername |
|
| 89 | - ) { |
|
| 90 | - if (!WebRequest::postBoolean('guidelines')) { |
|
| 91 | - throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $this->validateGeneralInformation($emailAddress, $password, $username); |
|
| 95 | - $this->validateUniqueEmail($emailAddress); |
|
| 96 | - $this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param $useOAuthSignup |
|
| 101 | - * @param $confirmationId |
|
| 102 | - * @param $onwikiUsername |
|
| 103 | - * |
|
| 104 | - * @throws ApplicationLogicException |
|
| 105 | - */ |
|
| 106 | - protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername) |
|
| 107 | - { |
|
| 108 | - if (!$useOAuthSignup) { |
|
| 109 | - if ($confirmationId === null || $confirmationId <= 0) { |
|
| 110 | - throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.'); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - if ($onwikiUsername === null) { |
|
| 114 | - throw new ApplicationLogicException('Please specify your on-wiki username.'); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @param $emailAddress |
|
| 121 | - * @param $password |
|
| 122 | - * @param $username |
|
| 123 | - * |
|
| 124 | - * @throws ApplicationLogicException |
|
| 125 | - */ |
|
| 126 | - protected function validateGeneralInformation($emailAddress, $password, $username) |
|
| 127 | - { |
|
| 128 | - if ($emailAddress === null) { |
|
| 129 | - throw new ApplicationLogicException('Your email address appears to be invalid!'); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if ($password !== WebRequest::postString('pass2')) { |
|
| 133 | - throw new ApplicationLogicException('Your passwords did not match, please try again.'); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - if (User::getByUsername($username, $this->getDatabase()) !== false) { |
|
| 137 | - throw new ApplicationLogicException('That username is already in use on this system.'); |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param $useOAuthSignup |
|
| 143 | - * |
|
| 144 | - * @throws ApplicationLogicException |
|
| 145 | - * @throws \Exception |
|
| 146 | - */ |
|
| 147 | - protected function handlePost($useOAuthSignup) |
|
| 148 | - { |
|
| 149 | - // Get the data |
|
| 150 | - $emailAddress = WebRequest::postEmail('email'); |
|
| 151 | - $password = WebRequest::postString('pass'); |
|
| 152 | - $username = WebRequest::postString('name'); |
|
| 153 | - |
|
| 154 | - // Only set if OAuth is disabled |
|
| 155 | - $confirmationId = WebRequest::postInt('conf_revid'); |
|
| 156 | - $onwikiUsername = WebRequest::postString('wname'); |
|
| 157 | - |
|
| 158 | - // Do some validation |
|
| 159 | - $this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId, |
|
| 160 | - $onwikiUsername); |
|
| 161 | - |
|
| 162 | - $database = $this->getDatabase(); |
|
| 163 | - |
|
| 164 | - $user = new User(); |
|
| 165 | - $user->setDatabase($database); |
|
| 166 | - |
|
| 167 | - $user->setUsername($username); |
|
| 168 | - $user->setPassword($password); |
|
| 169 | - $user->setEmail($emailAddress); |
|
| 170 | - |
|
| 171 | - if (!$useOAuthSignup) { |
|
| 172 | - $user->setOnWikiName($onwikiUsername); |
|
| 173 | - $user->setConfirmationDiff($confirmationId); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $user->save(); |
|
| 177 | - |
|
| 178 | - $defaultRole = $this->getDefaultRole(); |
|
| 179 | - |
|
| 180 | - $role = new UserRole(); |
|
| 181 | - $role->setDatabase($database); |
|
| 182 | - $role->setUser($user->getId()); |
|
| 183 | - $role->setRole($defaultRole); |
|
| 184 | - $role->save(); |
|
| 185 | - |
|
| 186 | - // Log now to get the signup date. |
|
| 187 | - Logger::newUser($database, $user); |
|
| 188 | - Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array()); |
|
| 189 | - |
|
| 190 | - if ($useOAuthSignup) { |
|
| 191 | - $oauthHelper = $this->getOAuthHelper(); |
|
| 192 | - |
|
| 193 | - $requestToken = $oauthHelper->getRequestToken(); |
|
| 194 | - $user->setOAuthRequestToken($requestToken->key); |
|
| 195 | - $user->setOAuthRequestSecret($requestToken->secret); |
|
| 196 | - $user->save(); |
|
| 197 | - |
|
| 198 | - WebRequest::setPartialLogin($user); |
|
| 199 | - |
|
| 200 | - $this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key)); |
|
| 201 | - } |
|
| 202 | - else { |
|
| 203 | - // only notify if we're not using the oauth signup. |
|
| 204 | - $this->getNotificationHelper()->userNew($user); |
|
| 205 | - WebRequest::setLoggedInUser($user); |
|
| 206 | - $this->redirect('preferences'); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - protected abstract function getDefaultRole(); |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Entry point for registration complete |
|
| 214 | - */ |
|
| 215 | - protected function done() |
|
| 216 | - { |
|
| 217 | - $this->setTemplate('registration/alert-registrationcomplete.tpl'); |
|
| 218 | - } |
|
| 21 | + /** |
|
| 22 | + * Main function for this page, when no specific actions are called. |
|
| 23 | + */ |
|
| 24 | + protected function main() |
|
| 25 | + { |
|
| 26 | + $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup(); |
|
| 27 | + |
|
| 28 | + // Dual-mode page |
|
| 29 | + if (WebRequest::wasPosted()) { |
|
| 30 | + $this->validateCSRFToken(); |
|
| 31 | + |
|
| 32 | + try { |
|
| 33 | + $this->handlePost($useOAuthSignup); |
|
| 34 | + } |
|
| 35 | + catch (ApplicationLogicException $ex) { |
|
| 36 | + SessionAlert::error($ex->getMessage()); |
|
| 37 | + $this->redirect('register'); |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + else { |
|
| 41 | + $this->assignCSRFToken(); |
|
| 42 | + $this->assign("useOAuthSignup", $useOAuthSignup); |
|
| 43 | + $this->setTemplate($this->getRegistrationTemplate()); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + protected abstract function getRegistrationTemplate(); |
|
| 48 | + |
|
| 49 | + protected function isProtectedPage() |
|
| 50 | + { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @param string $emailAddress |
|
| 56 | + * |
|
| 57 | + * @throws ApplicationLogicException |
|
| 58 | + */ |
|
| 59 | + protected function validateUniqueEmail($emailAddress) |
|
| 60 | + { |
|
| 61 | + $query = 'SELECT COUNT(id) FROM user WHERE email = :email'; |
|
| 62 | + $statement = $this->getDatabase()->prepare($query); |
|
| 63 | + $statement->execute(array(':email' => $emailAddress)); |
|
| 64 | + |
|
| 65 | + if ($statement->fetchColumn() > 0) { |
|
| 66 | + throw new ApplicationLogicException('That email address is already in use on this system.'); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + $statement->closeCursor(); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param $emailAddress |
|
| 74 | + * @param $password |
|
| 75 | + * @param $username |
|
| 76 | + * @param $useOAuthSignup |
|
| 77 | + * @param $confirmationId |
|
| 78 | + * @param $onwikiUsername |
|
| 79 | + * |
|
| 80 | + * @throws ApplicationLogicException |
|
| 81 | + */ |
|
| 82 | + protected function validateRequest( |
|
| 83 | + $emailAddress, |
|
| 84 | + $password, |
|
| 85 | + $username, |
|
| 86 | + $useOAuthSignup, |
|
| 87 | + $confirmationId, |
|
| 88 | + $onwikiUsername |
|
| 89 | + ) { |
|
| 90 | + if (!WebRequest::postBoolean('guidelines')) { |
|
| 91 | + throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $this->validateGeneralInformation($emailAddress, $password, $username); |
|
| 95 | + $this->validateUniqueEmail($emailAddress); |
|
| 96 | + $this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param $useOAuthSignup |
|
| 101 | + * @param $confirmationId |
|
| 102 | + * @param $onwikiUsername |
|
| 103 | + * |
|
| 104 | + * @throws ApplicationLogicException |
|
| 105 | + */ |
|
| 106 | + protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername) |
|
| 107 | + { |
|
| 108 | + if (!$useOAuthSignup) { |
|
| 109 | + if ($confirmationId === null || $confirmationId <= 0) { |
|
| 110 | + throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.'); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + if ($onwikiUsername === null) { |
|
| 114 | + throw new ApplicationLogicException('Please specify your on-wiki username.'); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @param $emailAddress |
|
| 121 | + * @param $password |
|
| 122 | + * @param $username |
|
| 123 | + * |
|
| 124 | + * @throws ApplicationLogicException |
|
| 125 | + */ |
|
| 126 | + protected function validateGeneralInformation($emailAddress, $password, $username) |
|
| 127 | + { |
|
| 128 | + if ($emailAddress === null) { |
|
| 129 | + throw new ApplicationLogicException('Your email address appears to be invalid!'); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if ($password !== WebRequest::postString('pass2')) { |
|
| 133 | + throw new ApplicationLogicException('Your passwords did not match, please try again.'); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + if (User::getByUsername($username, $this->getDatabase()) !== false) { |
|
| 137 | + throw new ApplicationLogicException('That username is already in use on this system.'); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param $useOAuthSignup |
|
| 143 | + * |
|
| 144 | + * @throws ApplicationLogicException |
|
| 145 | + * @throws \Exception |
|
| 146 | + */ |
|
| 147 | + protected function handlePost($useOAuthSignup) |
|
| 148 | + { |
|
| 149 | + // Get the data |
|
| 150 | + $emailAddress = WebRequest::postEmail('email'); |
|
| 151 | + $password = WebRequest::postString('pass'); |
|
| 152 | + $username = WebRequest::postString('name'); |
|
| 153 | + |
|
| 154 | + // Only set if OAuth is disabled |
|
| 155 | + $confirmationId = WebRequest::postInt('conf_revid'); |
|
| 156 | + $onwikiUsername = WebRequest::postString('wname'); |
|
| 157 | + |
|
| 158 | + // Do some validation |
|
| 159 | + $this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId, |
|
| 160 | + $onwikiUsername); |
|
| 161 | + |
|
| 162 | + $database = $this->getDatabase(); |
|
| 163 | + |
|
| 164 | + $user = new User(); |
|
| 165 | + $user->setDatabase($database); |
|
| 166 | + |
|
| 167 | + $user->setUsername($username); |
|
| 168 | + $user->setPassword($password); |
|
| 169 | + $user->setEmail($emailAddress); |
|
| 170 | + |
|
| 171 | + if (!$useOAuthSignup) { |
|
| 172 | + $user->setOnWikiName($onwikiUsername); |
|
| 173 | + $user->setConfirmationDiff($confirmationId); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $user->save(); |
|
| 177 | + |
|
| 178 | + $defaultRole = $this->getDefaultRole(); |
|
| 179 | + |
|
| 180 | + $role = new UserRole(); |
|
| 181 | + $role->setDatabase($database); |
|
| 182 | + $role->setUser($user->getId()); |
|
| 183 | + $role->setRole($defaultRole); |
|
| 184 | + $role->save(); |
|
| 185 | + |
|
| 186 | + // Log now to get the signup date. |
|
| 187 | + Logger::newUser($database, $user); |
|
| 188 | + Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array()); |
|
| 189 | + |
|
| 190 | + if ($useOAuthSignup) { |
|
| 191 | + $oauthHelper = $this->getOAuthHelper(); |
|
| 192 | + |
|
| 193 | + $requestToken = $oauthHelper->getRequestToken(); |
|
| 194 | + $user->setOAuthRequestToken($requestToken->key); |
|
| 195 | + $user->setOAuthRequestSecret($requestToken->secret); |
|
| 196 | + $user->save(); |
|
| 197 | + |
|
| 198 | + WebRequest::setPartialLogin($user); |
|
| 199 | + |
|
| 200 | + $this->redirectUrl($oauthHelper->getAuthoriseUrl($requestToken->key)); |
|
| 201 | + } |
|
| 202 | + else { |
|
| 203 | + // only notify if we're not using the oauth signup. |
|
| 204 | + $this->getNotificationHelper()->userNew($user); |
|
| 205 | + WebRequest::setLoggedInUser($user); |
|
| 206 | + $this->redirect('preferences'); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + protected abstract function getDefaultRole(); |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Entry point for registration complete |
|
| 214 | + */ |
|
| 215 | + protected function done() |
|
| 216 | + { |
|
| 217 | + $this->setTemplate('registration/alert-registrationcomplete.tpl'); |
|
| 218 | + } |
|
| 219 | 219 | } |
@@ -10,19 +10,19 @@ |
||
| 10 | 10 | |
| 11 | 11 | class PageRegisterStandard extends PageRegisterBase |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @return string |
|
| 15 | - */ |
|
| 16 | - protected function getRegistrationTemplate() |
|
| 17 | - { |
|
| 18 | - return "registration/register.tpl"; |
|
| 19 | - } |
|
| 13 | + /** |
|
| 14 | + * @return string |
|
| 15 | + */ |
|
| 16 | + protected function getRegistrationTemplate() |
|
| 17 | + { |
|
| 18 | + return "registration/register.tpl"; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @return string |
|
| 23 | - */ |
|
| 24 | - protected function getDefaultRole() |
|
| 25 | - { |
|
| 26 | - return 'user'; |
|
| 27 | - } |
|
| 21 | + /** |
|
| 22 | + * @return string |
|
| 23 | + */ |
|
| 24 | + protected function getDefaultRole() |
|
| 25 | + { |
|
| 26 | + return 'user'; |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -15,37 +15,37 @@ |
||
| 15 | 15 | |
| 16 | 16 | class PageSiteNotice extends InternalPageBase |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Main function for this page, when no specific actions are called. |
|
| 20 | - * @return void |
|
| 21 | - */ |
|
| 22 | - protected function main() |
|
| 23 | - { |
|
| 24 | - $this->setHtmlTitle('Site Notice'); |
|
| 25 | - |
|
| 26 | - $database = $this->getDatabase(); |
|
| 27 | - |
|
| 28 | - /** @var SiteNotice $siteNoticeMessage */ |
|
| 29 | - $siteNoticeMessage = SiteNotice::getById(1, $database); |
|
| 30 | - |
|
| 31 | - // Dual-mode |
|
| 32 | - if (WebRequest::wasPosted()) { |
|
| 33 | - $this->validateCSRFToken(); |
|
| 34 | - |
|
| 35 | - $siteNoticeMessage->setContent(WebRequest::postString('mailtext')); |
|
| 36 | - $siteNoticeMessage->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 37 | - $siteNoticeMessage->save(); |
|
| 38 | - |
|
| 39 | - Logger::siteNoticeEdited($database, $siteNoticeMessage); |
|
| 40 | - $this->getNotificationHelper()->siteNoticeEdited(); |
|
| 41 | - |
|
| 42 | - $this->redirect(); |
|
| 43 | - } |
|
| 44 | - else { |
|
| 45 | - $this->assignCSRFToken(); |
|
| 46 | - |
|
| 47 | - $this->setTemplate('site-notice/edit-form.tpl'); |
|
| 48 | - $this->assign('message', $siteNoticeMessage); |
|
| 49 | - } |
|
| 50 | - } |
|
| 18 | + /** |
|
| 19 | + * Main function for this page, when no specific actions are called. |
|
| 20 | + * @return void |
|
| 21 | + */ |
|
| 22 | + protected function main() |
|
| 23 | + { |
|
| 24 | + $this->setHtmlTitle('Site Notice'); |
|
| 25 | + |
|
| 26 | + $database = $this->getDatabase(); |
|
| 27 | + |
|
| 28 | + /** @var SiteNotice $siteNoticeMessage */ |
|
| 29 | + $siteNoticeMessage = SiteNotice::getById(1, $database); |
|
| 30 | + |
|
| 31 | + // Dual-mode |
|
| 32 | + if (WebRequest::wasPosted()) { |
|
| 33 | + $this->validateCSRFToken(); |
|
| 34 | + |
|
| 35 | + $siteNoticeMessage->setContent(WebRequest::postString('mailtext')); |
|
| 36 | + $siteNoticeMessage->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 37 | + $siteNoticeMessage->save(); |
|
| 38 | + |
|
| 39 | + Logger::siteNoticeEdited($database, $siteNoticeMessage); |
|
| 40 | + $this->getNotificationHelper()->siteNoticeEdited(); |
|
| 41 | + |
|
| 42 | + $this->redirect(); |
|
| 43 | + } |
|
| 44 | + else { |
|
| 45 | + $this->assignCSRFToken(); |
|
| 46 | + |
|
| 47 | + $this->setTemplate('site-notice/edit-form.tpl'); |
|
| 48 | + $this->assign('message', $siteNoticeMessage); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -18,113 +18,113 @@ |
||
| 18 | 18 | |
| 19 | 19 | class PageLog extends InternalPageBase |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Main function for this page, when no specific actions are called. |
|
| 23 | - */ |
|
| 24 | - protected function main() |
|
| 25 | - { |
|
| 26 | - $this->setHtmlTitle('Logs'); |
|
| 27 | - |
|
| 28 | - $filterUser = WebRequest::getString('filterUser'); |
|
| 29 | - $filterAction = WebRequest::getString('filterAction'); |
|
| 30 | - |
|
| 31 | - $database = $this->getDatabase(); |
|
| 32 | - |
|
| 33 | - $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
| 34 | - return UserSearchHelper::get($database)->fetchColumn('username'); |
|
| 35 | - }); |
|
| 36 | - |
|
| 37 | - $limit = WebRequest::getInt('limit'); |
|
| 38 | - if ($limit === null) { |
|
| 39 | - $limit = 100; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - $page = WebRequest::getInt('page'); |
|
| 43 | - if ($page === null) { |
|
| 44 | - $page = 1; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - $offset = ($page - 1) * $limit; |
|
| 48 | - |
|
| 49 | - $logSearch = LogSearchHelper::get($database)->limit($limit, $offset); |
|
| 50 | - if ($filterUser !== null) { |
|
| 51 | - $logSearch->byUser(User::getByUsername($filterUser, $database)->getId()); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if ($filterAction !== null) { |
|
| 55 | - $logSearch->byAction($filterAction); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** @var Log[] $logs */ |
|
| 59 | - $logs = $logSearch->getRecordCount($count)->fetch(); |
|
| 60 | - |
|
| 61 | - if ($count === 0) { |
|
| 62 | - $this->assign('logs', array()); |
|
| 63 | - $this->setTemplate('logs/main.tpl'); |
|
| 64 | - |
|
| 65 | - return; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
| 69 | - |
|
| 70 | - $this->setupPageData($page, $limit, $count); |
|
| 71 | - |
|
| 72 | - $this->assign("logs", $logData); |
|
| 73 | - $this->assign("users", $users); |
|
| 74 | - |
|
| 75 | - $this->assign("filterUser", $filterUser); |
|
| 76 | - $this->assign("filterAction", $filterAction); |
|
| 77 | - |
|
| 78 | - $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase())); |
|
| 79 | - |
|
| 80 | - $this->setTemplate("logs/main.tpl"); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @param int $page |
|
| 85 | - * @param int $limit |
|
| 86 | - * @param int $count |
|
| 87 | - */ |
|
| 88 | - protected function setupPageData($page, $limit, $count) |
|
| 89 | - { |
|
| 90 | - // The number of pages on the pager to show. Must be odd |
|
| 91 | - $pageLimit = 9; |
|
| 92 | - |
|
| 93 | - $pageData = array( |
|
| 94 | - // Can the user go to the previous page? |
|
| 95 | - 'canprev' => $page != 1, |
|
| 96 | - // Can the user go to the next page? |
|
| 97 | - 'cannext' => ($page * $limit) < $count, |
|
| 98 | - // Maximum page number |
|
| 99 | - 'maxpage' => ceil($count / $limit), |
|
| 100 | - // Limit to the number of pages to display |
|
| 101 | - 'pagelimit' => $pageLimit, |
|
| 102 | - ); |
|
| 103 | - |
|
| 104 | - // number of pages either side of the current to show |
|
| 105 | - $pageMargin = (($pageLimit - 1) / 2); |
|
| 106 | - |
|
| 107 | - // Calculate the number of pages either side to show - this is for situations like: |
|
| 108 | - // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
| 109 | - $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
| 110 | - $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
| 111 | - $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
| 112 | - |
|
| 113 | - if ($pageCount < $pageLimit) { |
|
| 114 | - if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
| 115 | - $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
| 116 | - } |
|
| 117 | - elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
| 118 | - $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // Put the range of pages into the page data |
|
| 123 | - $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
| 124 | - |
|
| 125 | - $this->assign("pagedata", $pageData); |
|
| 126 | - |
|
| 127 | - $this->assign("limit", $limit); |
|
| 128 | - $this->assign("page", $page); |
|
| 129 | - } |
|
| 21 | + /** |
|
| 22 | + * Main function for this page, when no specific actions are called. |
|
| 23 | + */ |
|
| 24 | + protected function main() |
|
| 25 | + { |
|
| 26 | + $this->setHtmlTitle('Logs'); |
|
| 27 | + |
|
| 28 | + $filterUser = WebRequest::getString('filterUser'); |
|
| 29 | + $filterAction = WebRequest::getString('filterAction'); |
|
| 30 | + |
|
| 31 | + $database = $this->getDatabase(); |
|
| 32 | + |
|
| 33 | + $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) { |
|
| 34 | + return UserSearchHelper::get($database)->fetchColumn('username'); |
|
| 35 | + }); |
|
| 36 | + |
|
| 37 | + $limit = WebRequest::getInt('limit'); |
|
| 38 | + if ($limit === null) { |
|
| 39 | + $limit = 100; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + $page = WebRequest::getInt('page'); |
|
| 43 | + if ($page === null) { |
|
| 44 | + $page = 1; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + $offset = ($page - 1) * $limit; |
|
| 48 | + |
|
| 49 | + $logSearch = LogSearchHelper::get($database)->limit($limit, $offset); |
|
| 50 | + if ($filterUser !== null) { |
|
| 51 | + $logSearch->byUser(User::getByUsername($filterUser, $database)->getId()); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if ($filterAction !== null) { |
|
| 55 | + $logSearch->byAction($filterAction); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** @var Log[] $logs */ |
|
| 59 | + $logs = $logSearch->getRecordCount($count)->fetch(); |
|
| 60 | + |
|
| 61 | + if ($count === 0) { |
|
| 62 | + $this->assign('logs', array()); |
|
| 63 | + $this->setTemplate('logs/main.tpl'); |
|
| 64 | + |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
| 69 | + |
|
| 70 | + $this->setupPageData($page, $limit, $count); |
|
| 71 | + |
|
| 72 | + $this->assign("logs", $logData); |
|
| 73 | + $this->assign("users", $users); |
|
| 74 | + |
|
| 75 | + $this->assign("filterUser", $filterUser); |
|
| 76 | + $this->assign("filterAction", $filterAction); |
|
| 77 | + |
|
| 78 | + $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase())); |
|
| 79 | + |
|
| 80 | + $this->setTemplate("logs/main.tpl"); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @param int $page |
|
| 85 | + * @param int $limit |
|
| 86 | + * @param int $count |
|
| 87 | + */ |
|
| 88 | + protected function setupPageData($page, $limit, $count) |
|
| 89 | + { |
|
| 90 | + // The number of pages on the pager to show. Must be odd |
|
| 91 | + $pageLimit = 9; |
|
| 92 | + |
|
| 93 | + $pageData = array( |
|
| 94 | + // Can the user go to the previous page? |
|
| 95 | + 'canprev' => $page != 1, |
|
| 96 | + // Can the user go to the next page? |
|
| 97 | + 'cannext' => ($page * $limit) < $count, |
|
| 98 | + // Maximum page number |
|
| 99 | + 'maxpage' => ceil($count / $limit), |
|
| 100 | + // Limit to the number of pages to display |
|
| 101 | + 'pagelimit' => $pageLimit, |
|
| 102 | + ); |
|
| 103 | + |
|
| 104 | + // number of pages either side of the current to show |
|
| 105 | + $pageMargin = (($pageLimit - 1) / 2); |
|
| 106 | + |
|
| 107 | + // Calculate the number of pages either side to show - this is for situations like: |
|
| 108 | + // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
| 109 | + $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
| 110 | + $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
| 111 | + $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
| 112 | + |
|
| 113 | + if ($pageCount < $pageLimit) { |
|
| 114 | + if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
| 115 | + $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
| 116 | + } |
|
| 117 | + elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
| 118 | + $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // Put the range of pages into the page data |
|
| 123 | + $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
| 124 | + |
|
| 125 | + $this->assign("pagedata", $pageData); |
|
| 126 | + |
|
| 127 | + $this->assign("limit", $limit); |
|
| 128 | + $this->assign("page", $page); |
|
| 129 | + } |
|
| 130 | 130 | } |
@@ -12,20 +12,20 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Page404 extends InternalPageBase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Main function for this page, when no actions are called. |
|
| 17 | - */ |
|
| 18 | - protected function main() |
|
| 19 | - { |
|
| 20 | - if (!headers_sent()) { |
|
| 21 | - header("HTTP/1.1 404 Not Found"); |
|
| 22 | - } |
|
| 15 | + /** |
|
| 16 | + * Main function for this page, when no actions are called. |
|
| 17 | + */ |
|
| 18 | + protected function main() |
|
| 19 | + { |
|
| 20 | + if (!headers_sent()) { |
|
| 21 | + header("HTTP/1.1 404 Not Found"); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - $this->setTemplate("404.tpl"); |
|
| 25 | - } |
|
| 24 | + $this->setTemplate("404.tpl"); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - protected function isProtectedPage() |
|
| 28 | - { |
|
| 29 | - return false; |
|
| 30 | - } |
|
| 27 | + protected function isProtectedPage() |
|
| 28 | + { |
|
| 29 | + return false; |
|
| 30 | + } |
|
| 31 | 31 | } |
@@ -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 | } |
@@ -17,71 +17,71 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | class PageMain extends InternalPageBase |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Main function for this page, when no actions are called. |
|
| 22 | - */ |
|
| 23 | - protected function main() |
|
| 24 | - { |
|
| 25 | - $this->assignCSRFToken(); |
|
| 26 | - |
|
| 27 | - $config = $this->getSiteConfiguration(); |
|
| 28 | - |
|
| 29 | - $database = $this->getDatabase(); |
|
| 30 | - |
|
| 31 | - $requestSectionData = array(); |
|
| 32 | - |
|
| 33 | - if ($config->getEmailConfirmationEnabled()) { |
|
| 34 | - $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed' LIMIT :lim;"; |
|
| 35 | - $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 36 | - } |
|
| 37 | - else { |
|
| 38 | - $query = "SELECT * FROM request WHERE status = :type LIMIT :lim;"; |
|
| 39 | - $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - $statement = $database->prepare($query); |
|
| 43 | - $statement->bindValue(':lim', $config->getMiserModeLimit(), PDO::PARAM_INT); |
|
| 44 | - |
|
| 45 | - $totalRequestsStatement = $database->prepare($totalQuery); |
|
| 46 | - |
|
| 47 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 48 | - |
|
| 49 | - foreach ($config->getRequestStates() as $type => $v) { |
|
| 50 | - $statement->bindValue(":type", $type); |
|
| 51 | - $statement->execute(); |
|
| 52 | - |
|
| 53 | - $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class); |
|
| 54 | - |
|
| 55 | - /** @var Request $req */ |
|
| 56 | - foreach ($requests as $req) { |
|
| 57 | - $req->setDatabase($database); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - $totalRequestsStatement->bindValue(':type', $type); |
|
| 61 | - $totalRequestsStatement->execute(); |
|
| 62 | - $totalRequests = $totalRequestsStatement->fetchColumn(); |
|
| 63 | - $totalRequestsStatement->closeCursor(); |
|
| 64 | - |
|
| 65 | - $userIds = array_map( |
|
| 66 | - function(Request $entry) { |
|
| 67 | - return $entry->getReserved(); |
|
| 68 | - }, |
|
| 69 | - $requests); |
|
| 70 | - $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
| 71 | - $this->assign('userlist', $userList); |
|
| 72 | - |
|
| 73 | - $requestSectionData[$v['header']] = array( |
|
| 74 | - 'requests' => $requests, |
|
| 75 | - 'total' => $totalRequests, |
|
| 76 | - 'api' => $v['api'], |
|
| 77 | - 'type' => $type, |
|
| 78 | - 'userlist' => $userList, |
|
| 79 | - ); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
| 83 | - |
|
| 84 | - $query = <<<SQL |
|
| 20 | + /** |
|
| 21 | + * Main function for this page, when no actions are called. |
|
| 22 | + */ |
|
| 23 | + protected function main() |
|
| 24 | + { |
|
| 25 | + $this->assignCSRFToken(); |
|
| 26 | + |
|
| 27 | + $config = $this->getSiteConfiguration(); |
|
| 28 | + |
|
| 29 | + $database = $this->getDatabase(); |
|
| 30 | + |
|
| 31 | + $requestSectionData = array(); |
|
| 32 | + |
|
| 33 | + if ($config->getEmailConfirmationEnabled()) { |
|
| 34 | + $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed' LIMIT :lim;"; |
|
| 35 | + $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 36 | + } |
|
| 37 | + else { |
|
| 38 | + $query = "SELECT * FROM request WHERE status = :type LIMIT :lim;"; |
|
| 39 | + $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + $statement = $database->prepare($query); |
|
| 43 | + $statement->bindValue(':lim', $config->getMiserModeLimit(), PDO::PARAM_INT); |
|
| 44 | + |
|
| 45 | + $totalRequestsStatement = $database->prepare($totalQuery); |
|
| 46 | + |
|
| 47 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 48 | + |
|
| 49 | + foreach ($config->getRequestStates() as $type => $v) { |
|
| 50 | + $statement->bindValue(":type", $type); |
|
| 51 | + $statement->execute(); |
|
| 52 | + |
|
| 53 | + $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class); |
|
| 54 | + |
|
| 55 | + /** @var Request $req */ |
|
| 56 | + foreach ($requests as $req) { |
|
| 57 | + $req->setDatabase($database); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + $totalRequestsStatement->bindValue(':type', $type); |
|
| 61 | + $totalRequestsStatement->execute(); |
|
| 62 | + $totalRequests = $totalRequestsStatement->fetchColumn(); |
|
| 63 | + $totalRequestsStatement->closeCursor(); |
|
| 64 | + |
|
| 65 | + $userIds = array_map( |
|
| 66 | + function(Request $entry) { |
|
| 67 | + return $entry->getReserved(); |
|
| 68 | + }, |
|
| 69 | + $requests); |
|
| 70 | + $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
| 71 | + $this->assign('userlist', $userList); |
|
| 72 | + |
|
| 73 | + $requestSectionData[$v['header']] = array( |
|
| 74 | + 'requests' => $requests, |
|
| 75 | + 'total' => $totalRequests, |
|
| 76 | + 'api' => $v['api'], |
|
| 77 | + 'type' => $type, |
|
| 78 | + 'userlist' => $userList, |
|
| 79 | + ); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
| 83 | + |
|
| 84 | + $query = <<<SQL |
|
| 85 | 85 | SELECT request.id, request.name, request.updateversion |
| 86 | 86 | FROM request /* PageMain::main() */ |
| 87 | 87 | JOIN log ON log.objectid = request.id AND log.objecttype = 'Request' |
@@ -90,18 +90,18 @@ discard block |
||
| 90 | 90 | LIMIT 5; |
| 91 | 91 | SQL; |
| 92 | 92 | |
| 93 | - $statement = $database->prepare($query); |
|
| 94 | - $statement->execute(); |
|
| 93 | + $statement = $database->prepare($query); |
|
| 94 | + $statement->execute(); |
|
| 95 | 95 | |
| 96 | - $last5result = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 96 | + $last5result = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 97 | 97 | |
| 98 | - $this->assign('lastFive', $last5result); |
|
| 99 | - $this->assign('requestSectionData', $requestSectionData); |
|
| 98 | + $this->assign('lastFive', $last5result); |
|
| 99 | + $this->assign('requestSectionData', $requestSectionData); |
|
| 100 | 100 | |
| 101 | - $currentUser = User::getCurrent($database); |
|
| 102 | - $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 103 | - $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
| 101 | + $currentUser = User::getCurrent($database); |
|
| 102 | + $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 103 | + $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
| 104 | 104 | |
| 105 | - $this->setTemplate('mainpage/mainpage.tpl'); |
|
| 106 | - } |
|
| 105 | + $this->setTemplate('mainpage/mainpage.tpl'); |
|
| 106 | + } |
|
| 107 | 107 | } |