@@ -12,102 +12,102 @@ |
||
| 12 | 12 | |
| 13 | 13 | class ValidationError |
| 14 | 14 | { |
| 15 | - const NAME_EMPTY = "name_empty"; |
|
| 16 | - const NAME_TOO_LONG = "name_too_long"; |
|
| 17 | - const NAME_EXISTS = "name_exists"; |
|
| 18 | - const NAME_EXISTS_SUL = "name_exists_sul"; |
|
| 19 | - const NAME_NUMONLY = "name_numonly"; |
|
| 20 | - const NAME_INVALIDCHAR = "name_invalidchar"; |
|
| 21 | - const NAME_SANITISED = "name_sanitised"; |
|
| 22 | - const NAME_IP = "name_ip"; |
|
| 23 | - const EMAIL_EMPTY = "email_empty"; |
|
| 24 | - const EMAIL_WIKIMEDIA = "email_wikimedia"; |
|
| 25 | - const EMAIL_INVALID = "email_invalid"; |
|
| 26 | - const EMAIL_MISMATCH = "email_mismatch"; |
|
| 27 | - const OPEN_REQUEST_NAME = "open_request_name"; |
|
| 28 | - const BANNED = "banned"; |
|
| 29 | - const BANNED_TOR = "banned_tor"; |
|
| 30 | - /** |
|
| 31 | - * @var array Error text for the above |
|
| 32 | - */ |
|
| 33 | - private static $errorText = array( |
|
| 34 | - self::NAME_EMPTY => 'You\'ve not chosen a username!', |
|
| 35 | - self::NAME_TOO_LONG => 'Your chosen username is too long. Please choose a shorter one.', |
|
| 36 | - self::NAME_EXISTS => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
| 37 | - . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
| 38 | - . '[[User:example]] would become [[User:Example]].', |
|
| 39 | - self::NAME_EXISTS_SUL => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
| 40 | - . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
| 41 | - . '[[User:example]] would become [[User:Example]].', |
|
| 42 | - self::NAME_NUMONLY => 'The username you chose is invalid: it consists entirely of numbers. Please retry ' |
|
| 43 | - . 'with a valid username.', |
|
| 44 | - self::NAME_INVALIDCHAR => 'There appears to be an invalid character in your username. Please note that the ' |
|
| 45 | - . 'following characters are not allowed: <code># @ / < > [ ] | { }</code>', |
|
| 46 | - self::NAME_SANITISED => 'Your requested username has been automatically adjusted due to technical ' |
|
| 47 | - . 'restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.', |
|
| 48 | - self::NAME_IP => 'The username you chose is invalid: it cannot be an IP address', |
|
| 49 | - self::EMAIL_EMPTY => 'You need to supply an email address.', |
|
| 50 | - self::EMAIL_WIKIMEDIA => 'Please provide your email address here.', |
|
| 51 | - self::EMAIL_INVALID => 'Invalid E-mail address supplied. Please check you entered it correctly.', |
|
| 52 | - self::EMAIL_MISMATCH => 'The email addresses you entered do not match. Please try again.', |
|
| 53 | - self::OPEN_REQUEST_NAME => 'There is already an open request with this name in this system.', |
|
| 54 | - self::BANNED => 'Sorry, you are currently banned from requesting accounts using this tool.', |
|
| 55 | - self::BANNED_TOR => 'Tor exit nodes are currently banned from using this tool due to excessive abuse. ' |
|
| 56 | - . 'Please note that Tor is also currently banned from editing Wikipedia.', |
|
| 57 | - ); |
|
| 58 | - /** |
|
| 59 | - * Summary of $errorCode |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 62 | - private $errorCode; |
|
| 63 | - /** |
|
| 64 | - * Summary of $isError |
|
| 65 | - * @var bool |
|
| 66 | - */ |
|
| 67 | - private $isError; |
|
| 15 | + const NAME_EMPTY = "name_empty"; |
|
| 16 | + const NAME_TOO_LONG = "name_too_long"; |
|
| 17 | + const NAME_EXISTS = "name_exists"; |
|
| 18 | + const NAME_EXISTS_SUL = "name_exists_sul"; |
|
| 19 | + const NAME_NUMONLY = "name_numonly"; |
|
| 20 | + const NAME_INVALIDCHAR = "name_invalidchar"; |
|
| 21 | + const NAME_SANITISED = "name_sanitised"; |
|
| 22 | + const NAME_IP = "name_ip"; |
|
| 23 | + const EMAIL_EMPTY = "email_empty"; |
|
| 24 | + const EMAIL_WIKIMEDIA = "email_wikimedia"; |
|
| 25 | + const EMAIL_INVALID = "email_invalid"; |
|
| 26 | + const EMAIL_MISMATCH = "email_mismatch"; |
|
| 27 | + const OPEN_REQUEST_NAME = "open_request_name"; |
|
| 28 | + const BANNED = "banned"; |
|
| 29 | + const BANNED_TOR = "banned_tor"; |
|
| 30 | + /** |
|
| 31 | + * @var array Error text for the above |
|
| 32 | + */ |
|
| 33 | + private static $errorText = array( |
|
| 34 | + self::NAME_EMPTY => 'You\'ve not chosen a username!', |
|
| 35 | + self::NAME_TOO_LONG => 'Your chosen username is too long. Please choose a shorter one.', |
|
| 36 | + self::NAME_EXISTS => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
| 37 | + . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
| 38 | + . '[[User:example]] would become [[User:Example]].', |
|
| 39 | + self::NAME_EXISTS_SUL => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
| 40 | + . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
| 41 | + . '[[User:example]] would become [[User:Example]].', |
|
| 42 | + self::NAME_NUMONLY => 'The username you chose is invalid: it consists entirely of numbers. Please retry ' |
|
| 43 | + . 'with a valid username.', |
|
| 44 | + self::NAME_INVALIDCHAR => 'There appears to be an invalid character in your username. Please note that the ' |
|
| 45 | + . 'following characters are not allowed: <code># @ / < > [ ] | { }</code>', |
|
| 46 | + self::NAME_SANITISED => 'Your requested username has been automatically adjusted due to technical ' |
|
| 47 | + . 'restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.', |
|
| 48 | + self::NAME_IP => 'The username you chose is invalid: it cannot be an IP address', |
|
| 49 | + self::EMAIL_EMPTY => 'You need to supply an email address.', |
|
| 50 | + self::EMAIL_WIKIMEDIA => 'Please provide your email address here.', |
|
| 51 | + self::EMAIL_INVALID => 'Invalid E-mail address supplied. Please check you entered it correctly.', |
|
| 52 | + self::EMAIL_MISMATCH => 'The email addresses you entered do not match. Please try again.', |
|
| 53 | + self::OPEN_REQUEST_NAME => 'There is already an open request with this name in this system.', |
|
| 54 | + self::BANNED => 'Sorry, you are currently banned from requesting accounts using this tool.', |
|
| 55 | + self::BANNED_TOR => 'Tor exit nodes are currently banned from using this tool due to excessive abuse. ' |
|
| 56 | + . 'Please note that Tor is also currently banned from editing Wikipedia.', |
|
| 57 | + ); |
|
| 58 | + /** |
|
| 59 | + * Summary of $errorCode |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | + private $errorCode; |
|
| 63 | + /** |
|
| 64 | + * Summary of $isError |
|
| 65 | + * @var bool |
|
| 66 | + */ |
|
| 67 | + private $isError; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Summary of __construct |
|
| 71 | - * |
|
| 72 | - * @param string $errorCode |
|
| 73 | - * @param bool $isError |
|
| 74 | - */ |
|
| 75 | - public function __construct($errorCode, $isError = true) |
|
| 76 | - { |
|
| 77 | - $this->errorCode = $errorCode; |
|
| 78 | - $this->isError = $isError; |
|
| 79 | - } |
|
| 69 | + /** |
|
| 70 | + * Summary of __construct |
|
| 71 | + * |
|
| 72 | + * @param string $errorCode |
|
| 73 | + * @param bool $isError |
|
| 74 | + */ |
|
| 75 | + public function __construct($errorCode, $isError = true) |
|
| 76 | + { |
|
| 77 | + $this->errorCode = $errorCode; |
|
| 78 | + $this->isError = $isError; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Summary of getErrorCode |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public function getErrorCode() |
|
| 86 | - { |
|
| 87 | - return $this->errorCode; |
|
| 88 | - } |
|
| 81 | + /** |
|
| 82 | + * Summary of getErrorCode |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public function getErrorCode() |
|
| 86 | + { |
|
| 87 | + return $this->errorCode; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * @return string |
|
| 92 | - * @throws Exception |
|
| 93 | - */ |
|
| 94 | - public function getErrorMessage() |
|
| 95 | - { |
|
| 96 | - $text = self::$errorText[$this->errorCode]; |
|
| 90 | + /** |
|
| 91 | + * @return string |
|
| 92 | + * @throws Exception |
|
| 93 | + */ |
|
| 94 | + public function getErrorMessage() |
|
| 95 | + { |
|
| 96 | + $text = self::$errorText[$this->errorCode]; |
|
| 97 | 97 | |
| 98 | - if ($text == null) { |
|
| 99 | - throw new Exception('Unknown validation error'); |
|
| 100 | - } |
|
| 98 | + if ($text == null) { |
|
| 99 | + throw new Exception('Unknown validation error'); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - return $text; |
|
| 103 | - } |
|
| 102 | + return $text; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Summary of isError |
|
| 107 | - * @return bool |
|
| 108 | - */ |
|
| 109 | - public function isError() |
|
| 110 | - { |
|
| 111 | - return $this->isError; |
|
| 112 | - } |
|
| 105 | + /** |
|
| 106 | + * Summary of isError |
|
| 107 | + * @return bool |
|
| 108 | + */ |
|
| 109 | + public function isError() |
|
| 110 | + { |
|
| 111 | + return $this->isError; |
|
| 112 | + } |
|
| 113 | 113 | } |
@@ -22,258 +22,258 @@ |
||
| 22 | 22 | |
| 23 | 23 | class PageWelcomeTemplateManagement extends InternalPageBase |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * Main function for this page, when no specific actions are called. |
|
| 27 | - * @return void |
|
| 28 | - */ |
|
| 29 | - protected function main() |
|
| 30 | - { |
|
| 31 | - $database = $this->getDatabase(); |
|
| 32 | - $templateList = WelcomeTemplate::getAll($database, 1); // FIXME: domains |
|
| 33 | - $preferenceManager = PreferenceManager::getForCurrent($database); |
|
| 25 | + /** |
|
| 26 | + * Main function for this page, when no specific actions are called. |
|
| 27 | + * @return void |
|
| 28 | + */ |
|
| 29 | + protected function main() |
|
| 30 | + { |
|
| 31 | + $database = $this->getDatabase(); |
|
| 32 | + $templateList = WelcomeTemplate::getAll($database, 1); // FIXME: domains |
|
| 33 | + $preferenceManager = PreferenceManager::getForCurrent($database); |
|
| 34 | 34 | |
| 35 | - $this->setHtmlTitle('Welcome Templates'); |
|
| 35 | + $this->setHtmlTitle('Welcome Templates'); |
|
| 36 | 36 | |
| 37 | - $this->assignCSRFToken(); |
|
| 37 | + $this->assignCSRFToken(); |
|
| 38 | 38 | |
| 39 | - $user = User::getCurrent($database); |
|
| 39 | + $user = User::getCurrent($database); |
|
| 40 | 40 | |
| 41 | - $currentTemplate = $preferenceManager->getPreference(PreferenceManager::PREF_WELCOMETEMPLATE); |
|
| 42 | - $this->assign('currentTemplate', $currentTemplate); |
|
| 41 | + $currentTemplate = $preferenceManager->getPreference(PreferenceManager::PREF_WELCOMETEMPLATE); |
|
| 42 | + $this->assign('currentTemplate', $currentTemplate); |
|
| 43 | 43 | |
| 44 | - $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
| 45 | - $this->assign('canAdd', $this->barrierTest('add', $user)); |
|
| 46 | - $this->assign('canSelect', $this->barrierTest('select', $user)); |
|
| 44 | + $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
| 45 | + $this->assign('canAdd', $this->barrierTest('add', $user)); |
|
| 46 | + $this->assign('canSelect', $this->barrierTest('select', $user)); |
|
| 47 | 47 | |
| 48 | - $this->assign('templateList', $templateList); |
|
| 49 | - $this->setTemplate('welcome-template/list.tpl'); |
|
| 50 | - } |
|
| 48 | + $this->assign('templateList', $templateList); |
|
| 49 | + $this->setTemplate('welcome-template/list.tpl'); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Handles the requests for selecting a template to use. |
|
| 54 | - * |
|
| 55 | - * @throws ApplicationLogicException |
|
| 56 | - */ |
|
| 57 | - protected function select() |
|
| 58 | - { |
|
| 59 | - // get rid of GETs |
|
| 60 | - if (!WebRequest::wasPosted()) { |
|
| 61 | - $this->redirect('welcomeTemplates'); |
|
| 62 | - } |
|
| 52 | + /** |
|
| 53 | + * Handles the requests for selecting a template to use. |
|
| 54 | + * |
|
| 55 | + * @throws ApplicationLogicException |
|
| 56 | + */ |
|
| 57 | + protected function select() |
|
| 58 | + { |
|
| 59 | + // get rid of GETs |
|
| 60 | + if (!WebRequest::wasPosted()) { |
|
| 61 | + $this->redirect('welcomeTemplates'); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - $this->validateCSRFToken(); |
|
| 64 | + $this->validateCSRFToken(); |
|
| 65 | 65 | |
| 66 | - $database = $this->getDatabase(); |
|
| 67 | - $user = User::getCurrent($database); |
|
| 68 | - $preferenceManager = PreferenceManager::getForCurrent($database); |
|
| 66 | + $database = $this->getDatabase(); |
|
| 67 | + $user = User::getCurrent($database); |
|
| 68 | + $preferenceManager = PreferenceManager::getForCurrent($database); |
|
| 69 | 69 | |
| 70 | - if (WebRequest::postBoolean('disable')) { |
|
| 71 | - $preferenceManager->setLocalPreference(PreferenceManager::PREF_WELCOMETEMPLATE, null); |
|
| 70 | + if (WebRequest::postBoolean('disable')) { |
|
| 71 | + $preferenceManager->setLocalPreference(PreferenceManager::PREF_WELCOMETEMPLATE, null); |
|
| 72 | 72 | |
| 73 | - SessionAlert::success('Disabled automatic user welcoming.'); |
|
| 74 | - $this->redirect('welcomeTemplates'); |
|
| 73 | + SessionAlert::success('Disabled automatic user welcoming.'); |
|
| 74 | + $this->redirect('welcomeTemplates'); |
|
| 75 | 75 | |
| 76 | - return; |
|
| 77 | - } |
|
| 76 | + return; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - $templateId = WebRequest::postInt('template'); |
|
| 80 | - /** @var false|WelcomeTemplate $template */ |
|
| 81 | - $template = WelcomeTemplate::getById($templateId, $database); |
|
| 79 | + $templateId = WebRequest::postInt('template'); |
|
| 80 | + /** @var false|WelcomeTemplate $template */ |
|
| 81 | + $template = WelcomeTemplate::getById($templateId, $database); |
|
| 82 | 82 | |
| 83 | - if ($template === false || $template->isDeleted()) { |
|
| 84 | - throw new ApplicationLogicException('Unknown template'); |
|
| 85 | - } |
|
| 83 | + if ($template === false || $template->isDeleted()) { |
|
| 84 | + throw new ApplicationLogicException('Unknown template'); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - $preferenceManager->setLocalPreference(PreferenceManager::PREF_WELCOMETEMPLATE, $template->getId()); |
|
| 87 | + $preferenceManager->setLocalPreference(PreferenceManager::PREF_WELCOMETEMPLATE, $template->getId()); |
|
| 88 | 88 | |
| 89 | - SessionAlert::success("Updated selected welcome template for automatic welcoming."); |
|
| 89 | + SessionAlert::success("Updated selected welcome template for automatic welcoming."); |
|
| 90 | 90 | |
| 91 | - $this->redirect('welcomeTemplates'); |
|
| 92 | - } |
|
| 91 | + $this->redirect('welcomeTemplates'); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Handles the requests for viewing a template. |
|
| 96 | - * |
|
| 97 | - * @throws ApplicationLogicException |
|
| 98 | - */ |
|
| 99 | - protected function view() |
|
| 100 | - { |
|
| 101 | - $this->setHtmlTitle('View Welcome Template'); |
|
| 94 | + /** |
|
| 95 | + * Handles the requests for viewing a template. |
|
| 96 | + * |
|
| 97 | + * @throws ApplicationLogicException |
|
| 98 | + */ |
|
| 99 | + protected function view() |
|
| 100 | + { |
|
| 101 | + $this->setHtmlTitle('View Welcome Template'); |
|
| 102 | 102 | |
| 103 | - $database = $this->getDatabase(); |
|
| 103 | + $database = $this->getDatabase(); |
|
| 104 | 104 | |
| 105 | - $templateId = WebRequest::getInt('template'); |
|
| 105 | + $templateId = WebRequest::getInt('template'); |
|
| 106 | 106 | |
| 107 | - /** @var false|WelcomeTemplate $template */ |
|
| 108 | - $template = WelcomeTemplate::getById($templateId, $database); |
|
| 107 | + /** @var false|WelcomeTemplate $template */ |
|
| 108 | + $template = WelcomeTemplate::getById($templateId, $database); |
|
| 109 | 109 | |
| 110 | - if ($template === false) { |
|
| 111 | - throw new ApplicationLogicException('Cannot find requested template'); |
|
| 112 | - } |
|
| 110 | + if ($template === false) { |
|
| 111 | + throw new ApplicationLogicException('Cannot find requested template'); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - $currentUser = User::getCurrent($database); |
|
| 114 | + $currentUser = User::getCurrent($database); |
|
| 115 | 115 | |
| 116 | - // This includes a section header, because we use the "new section" API call. |
|
| 117 | - $wikiText = "== " . $template->getSectionHeader() . "==\n" . $template->getBotCodeForWikiSave('Example User', $currentUser->getOnWikiName()); |
|
| 116 | + // This includes a section header, because we use the "new section" API call. |
|
| 117 | + $wikiText = "== " . $template->getSectionHeader() . "==\n" . $template->getBotCodeForWikiSave('Example User', $currentUser->getOnWikiName()); |
|
| 118 | 118 | |
| 119 | - $oauth = new OAuthUserHelper($currentUser, $database, $this->getOauthProtocolHelper(), |
|
| 120 | - $this->getSiteConfiguration()); |
|
| 121 | - $mediaWikiHelper = new MediaWikiHelper($oauth, $this->getSiteConfiguration()); |
|
| 119 | + $oauth = new OAuthUserHelper($currentUser, $database, $this->getOauthProtocolHelper(), |
|
| 120 | + $this->getSiteConfiguration()); |
|
| 121 | + $mediaWikiHelper = new MediaWikiHelper($oauth, $this->getSiteConfiguration()); |
|
| 122 | 122 | |
| 123 | - $templateHtml = $mediaWikiHelper->getHtmlForWikiText($wikiText); |
|
| 123 | + $templateHtml = $mediaWikiHelper->getHtmlForWikiText($wikiText); |
|
| 124 | 124 | |
| 125 | - // Add site to relevant links, since the MediaWiki parser returns, eg, `/wiki/Help:Introduction` |
|
| 126 | - // and we want to link to <https://en.wikipedia.org/wiki/Help:Introduction> rather than |
|
| 127 | - // <https://accounts.wmflabs.org/wiki/Help:Introduction> |
|
| 128 | - // The code currently assumes that the template was parsed for enwiki, and will need to be |
|
| 129 | - // updated once other wikis are supported. |
|
| 130 | - $templateHtml = preg_replace('/(<a href=")(\/wiki\/)/', '$1//en.wikipedia.org$2', $templateHtml); |
|
| 131 | - |
|
| 132 | - $this->assign('templateHtml', $templateHtml); |
|
| 133 | - $this->assign('template', $template); |
|
| 134 | - $this->setTemplate('welcome-template/view.tpl'); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Handler for the add action to create a new welcome template |
|
| 139 | - * |
|
| 140 | - * @throws Exception |
|
| 141 | - */ |
|
| 142 | - protected function add() |
|
| 143 | - { |
|
| 144 | - $this->assign('createmode', true); |
|
| 125 | + // Add site to relevant links, since the MediaWiki parser returns, eg, `/wiki/Help:Introduction` |
|
| 126 | + // and we want to link to <https://en.wikipedia.org/wiki/Help:Introduction> rather than |
|
| 127 | + // <https://accounts.wmflabs.org/wiki/Help:Introduction> |
|
| 128 | + // The code currently assumes that the template was parsed for enwiki, and will need to be |
|
| 129 | + // updated once other wikis are supported. |
|
| 130 | + $templateHtml = preg_replace('/(<a href=")(\/wiki\/)/', '$1//en.wikipedia.org$2', $templateHtml); |
|
| 131 | + |
|
| 132 | + $this->assign('templateHtml', $templateHtml); |
|
| 133 | + $this->assign('template', $template); |
|
| 134 | + $this->setTemplate('welcome-template/view.tpl'); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Handler for the add action to create a new welcome template |
|
| 139 | + * |
|
| 140 | + * @throws Exception |
|
| 141 | + */ |
|
| 142 | + protected function add() |
|
| 143 | + { |
|
| 144 | + $this->assign('createmode', true); |
|
| 145 | 145 | |
| 146 | - if (WebRequest::wasPosted()) { |
|
| 147 | - $this->validateCSRFToken(); |
|
| 148 | - $database = $this->getDatabase(); |
|
| 146 | + if (WebRequest::wasPosted()) { |
|
| 147 | + $this->validateCSRFToken(); |
|
| 148 | + $database = $this->getDatabase(); |
|
| 149 | 149 | |
| 150 | - $userCode = WebRequest::postString('usercode'); |
|
| 151 | - $botCode = WebRequest::postString('botcode'); |
|
| 150 | + $userCode = WebRequest::postString('usercode'); |
|
| 151 | + $botCode = WebRequest::postString('botcode'); |
|
| 152 | 152 | |
| 153 | - $this->validate($userCode, $botCode); |
|
| 153 | + $this->validate($userCode, $botCode); |
|
| 154 | 154 | |
| 155 | - $template = new WelcomeTemplate(); |
|
| 156 | - $template->setDatabase($database); |
|
| 157 | - $template->setUserCode($userCode); |
|
| 158 | - $template->setBotCode($botCode); |
|
| 159 | - $template->setDomain(1); // FIXME: domains! |
|
| 160 | - $template->save(); |
|
| 155 | + $template = new WelcomeTemplate(); |
|
| 156 | + $template->setDatabase($database); |
|
| 157 | + $template->setUserCode($userCode); |
|
| 158 | + $template->setBotCode($botCode); |
|
| 159 | + $template->setDomain(1); // FIXME: domains! |
|
| 160 | + $template->save(); |
|
| 161 | 161 | |
| 162 | - Logger::welcomeTemplateCreated($database, $template); |
|
| 162 | + Logger::welcomeTemplateCreated($database, $template); |
|
| 163 | 163 | |
| 164 | - $this->getNotificationHelper()->welcomeTemplateCreated($template); |
|
| 164 | + $this->getNotificationHelper()->welcomeTemplateCreated($template); |
|
| 165 | 165 | |
| 166 | - SessionAlert::success("Template successfully created."); |
|
| 166 | + SessionAlert::success("Template successfully created."); |
|
| 167 | 167 | |
| 168 | - $this->redirect('welcomeTemplates'); |
|
| 169 | - } |
|
| 170 | - else { |
|
| 171 | - $this->assignCSRFToken(); |
|
| 172 | - $this->assign('template', new WelcomeTemplate()); |
|
| 173 | - $this->setTemplate("welcome-template/edit.tpl"); |
|
| 174 | - } |
|
| 175 | - } |
|
| 168 | + $this->redirect('welcomeTemplates'); |
|
| 169 | + } |
|
| 170 | + else { |
|
| 171 | + $this->assignCSRFToken(); |
|
| 172 | + $this->assign('template', new WelcomeTemplate()); |
|
| 173 | + $this->setTemplate("welcome-template/edit.tpl"); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Handler for editing templates |
|
| 179 | - */ |
|
| 180 | - protected function edit() |
|
| 181 | - { |
|
| 182 | - $database = $this->getDatabase(); |
|
| 177 | + /** |
|
| 178 | + * Handler for editing templates |
|
| 179 | + */ |
|
| 180 | + protected function edit() |
|
| 181 | + { |
|
| 182 | + $database = $this->getDatabase(); |
|
| 183 | 183 | |
| 184 | - $templateId = WebRequest::getInt('template'); |
|
| 184 | + $templateId = WebRequest::getInt('template'); |
|
| 185 | 185 | |
| 186 | - /** @var false|WelcomeTemplate $template */ |
|
| 187 | - $template = WelcomeTemplate::getById($templateId, $database); |
|
| 186 | + /** @var false|WelcomeTemplate $template */ |
|
| 187 | + $template = WelcomeTemplate::getById($templateId, $database); |
|
| 188 | 188 | |
| 189 | - if ($template === false) { |
|
| 190 | - throw new ApplicationLogicException('Cannot find requested template'); |
|
| 191 | - } |
|
| 189 | + if ($template === false) { |
|
| 190 | + throw new ApplicationLogicException('Cannot find requested template'); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - if ($template->isDeleted()) { |
|
| 194 | - throw new ApplicationLogicException('The specified template has been deleted'); |
|
| 195 | - } |
|
| 193 | + if ($template->isDeleted()) { |
|
| 194 | + throw new ApplicationLogicException('The specified template has been deleted'); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - $this->assign('createmode', false); |
|
| 197 | + $this->assign('createmode', false); |
|
| 198 | 198 | |
| 199 | - if (WebRequest::wasPosted()) { |
|
| 200 | - $this->validateCSRFToken(); |
|
| 199 | + if (WebRequest::wasPosted()) { |
|
| 200 | + $this->validateCSRFToken(); |
|
| 201 | 201 | |
| 202 | - $userCode = WebRequest::postString('usercode'); |
|
| 203 | - $botCode = WebRequest::postString('botcode'); |
|
| 202 | + $userCode = WebRequest::postString('usercode'); |
|
| 203 | + $botCode = WebRequest::postString('botcode'); |
|
| 204 | 204 | |
| 205 | - $this->validate($userCode, $botCode); |
|
| 205 | + $this->validate($userCode, $botCode); |
|
| 206 | 206 | |
| 207 | - $template->setUserCode($userCode); |
|
| 208 | - $template->setBotCode($botCode); |
|
| 209 | - $template->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 210 | - $template->save(); |
|
| 207 | + $template->setUserCode($userCode); |
|
| 208 | + $template->setBotCode($botCode); |
|
| 209 | + $template->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 210 | + $template->save(); |
|
| 211 | 211 | |
| 212 | - Logger::welcomeTemplateEdited($database, $template); |
|
| 212 | + Logger::welcomeTemplateEdited($database, $template); |
|
| 213 | 213 | |
| 214 | - SessionAlert::success("Template updated."); |
|
| 214 | + SessionAlert::success("Template updated."); |
|
| 215 | 215 | |
| 216 | - $this->getNotificationHelper()->welcomeTemplateEdited($template); |
|
| 216 | + $this->getNotificationHelper()->welcomeTemplateEdited($template); |
|
| 217 | 217 | |
| 218 | - $this->redirect('welcomeTemplates'); |
|
| 219 | - } |
|
| 220 | - else { |
|
| 221 | - $this->assignCSRFToken(); |
|
| 222 | - $this->assign('template', $template); |
|
| 223 | - $this->setTemplate('welcome-template/edit.tpl'); |
|
| 224 | - } |
|
| 225 | - } |
|
| 218 | + $this->redirect('welcomeTemplates'); |
|
| 219 | + } |
|
| 220 | + else { |
|
| 221 | + $this->assignCSRFToken(); |
|
| 222 | + $this->assign('template', $template); |
|
| 223 | + $this->setTemplate('welcome-template/edit.tpl'); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - protected function delete() |
|
| 228 | - { |
|
| 229 | - if (!WebRequest::wasPosted()) { |
|
| 230 | - $this->redirect('welcomeTemplates'); |
|
| 231 | - return; |
|
| 232 | - } |
|
| 227 | + protected function delete() |
|
| 228 | + { |
|
| 229 | + if (!WebRequest::wasPosted()) { |
|
| 230 | + $this->redirect('welcomeTemplates'); |
|
| 231 | + return; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - $this->validateCSRFToken(); |
|
| 234 | + $this->validateCSRFToken(); |
|
| 235 | 235 | |
| 236 | - $database = $this->getDatabase(); |
|
| 236 | + $database = $this->getDatabase(); |
|
| 237 | 237 | |
| 238 | - $templateId = WebRequest::postInt('template'); |
|
| 239 | - $updateVersion = WebRequest::postInt('updateversion'); |
|
| 238 | + $templateId = WebRequest::postInt('template'); |
|
| 239 | + $updateVersion = WebRequest::postInt('updateversion'); |
|
| 240 | 240 | |
| 241 | - /** @var false|WelcomeTemplate $template */ |
|
| 242 | - $template = WelcomeTemplate::getById($templateId, $database); |
|
| 241 | + /** @var false|WelcomeTemplate $template */ |
|
| 242 | + $template = WelcomeTemplate::getById($templateId, $database); |
|
| 243 | 243 | |
| 244 | - if ($template === false || $template->isDeleted()) { |
|
| 245 | - throw new ApplicationLogicException('Cannot find requested template'); |
|
| 246 | - } |
|
| 244 | + if ($template === false || $template->isDeleted()) { |
|
| 245 | + throw new ApplicationLogicException('Cannot find requested template'); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - // set the update version to the version sent by the client (optimisticly lock from initial page load) |
|
| 249 | - $template->setUpdateVersion($updateVersion); |
|
| 248 | + // set the update version to the version sent by the client (optimisticly lock from initial page load) |
|
| 249 | + $template->setUpdateVersion($updateVersion); |
|
| 250 | 250 | |
| 251 | - $database |
|
| 252 | - ->prepare("UPDATE userpreference SET value = NULL, updateversion = updateversion + 1 WHERE preference = :pref and value = :id;") |
|
| 253 | - ->execute([ |
|
| 254 | - ':id' => $templateId, |
|
| 255 | - ':pref' => PreferenceManager::PREF_WELCOMETEMPLATE |
|
| 256 | - ]); |
|
| 251 | + $database |
|
| 252 | + ->prepare("UPDATE userpreference SET value = NULL, updateversion = updateversion + 1 WHERE preference = :pref and value = :id;") |
|
| 253 | + ->execute([ |
|
| 254 | + ':id' => $templateId, |
|
| 255 | + ':pref' => PreferenceManager::PREF_WELCOMETEMPLATE |
|
| 256 | + ]); |
|
| 257 | 257 | |
| 258 | - Logger::welcomeTemplateDeleted($database, $template); |
|
| 258 | + Logger::welcomeTemplateDeleted($database, $template); |
|
| 259 | 259 | |
| 260 | - $template->delete(); |
|
| 260 | + $template->delete(); |
|
| 261 | 261 | |
| 262 | - $this->redirect('welcomeTemplates'); |
|
| 262 | + $this->redirect('welcomeTemplates'); |
|
| 263 | 263 | |
| 264 | - SessionAlert::success( |
|
| 265 | - "Template deleted. Any users who were using this template have had automatic welcoming disabled."); |
|
| 266 | - $this->getNotificationHelper()->welcomeTemplateDeleted($templateId); |
|
| 267 | - } |
|
| 264 | + SessionAlert::success( |
|
| 265 | + "Template deleted. Any users who were using this template have had automatic welcoming disabled."); |
|
| 266 | + $this->getNotificationHelper()->welcomeTemplateDeleted($templateId); |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - private function validate($userCode, $botCode) |
|
| 270 | - { |
|
| 271 | - if ($userCode === null) { |
|
| 272 | - throw new ApplicationLogicException('User code cannot be null'); |
|
| 273 | - } |
|
| 269 | + private function validate($userCode, $botCode) |
|
| 270 | + { |
|
| 271 | + if ($userCode === null) { |
|
| 272 | + throw new ApplicationLogicException('User code cannot be null'); |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - if ($botCode === null) { |
|
| 276 | - throw new ApplicationLogicException('Bot code cannot be null'); |
|
| 277 | - } |
|
| 278 | - } |
|
| 275 | + if ($botCode === null) { |
|
| 276 | + throw new ApplicationLogicException('Bot code cannot be null'); |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | 279 | } |
@@ -13,136 +13,136 @@ |
||
| 13 | 13 | |
| 14 | 14 | class PageXffDemo extends InternalPageBase |
| 15 | 15 | { |
| 16 | - use RequestData; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * @inheritDoc |
|
| 20 | - */ |
|
| 21 | - protected function main() |
|
| 22 | - { |
|
| 23 | - $this->setTemplate('xffdemo.tpl'); |
|
| 24 | - |
|
| 25 | - // requestHasForwardedIp == false |
|
| 26 | - // requestProxyData |
|
| 27 | - // requestRealIp == proxy |
|
| 28 | - // requestForwardedIp == xff header |
|
| 29 | - // forwardedOrigin == top of the chain, assuming xff is trusted |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - $this->assign('demo2', [ |
|
| 33 | - [ |
|
| 34 | - 'trust' => true, |
|
| 35 | - 'trustedlink' => true, |
|
| 36 | - 'ip' => '172.16.0.164', |
|
| 37 | - 'routable' => false, |
|
| 38 | - |
|
| 39 | - ], [ |
|
| 40 | - 'trust' => true, |
|
| 41 | - 'ip' => '198.51.100.123', |
|
| 42 | - 'routable' => true, |
|
| 43 | - 'rdns' => 'trustedproxy.example.com', |
|
| 44 | - |
|
| 45 | - ], [ |
|
| 46 | - 'trust' => true, |
|
| 47 | - 'ip' => '192.0.2.1', |
|
| 48 | - 'routable' => true, |
|
| 49 | - 'rdns' => 'client.users.example.org', |
|
| 50 | - 'location' => [ |
|
| 51 | - 'cityName' => 'San Francisco', |
|
| 52 | - 'regionName' => 'California', |
|
| 53 | - 'countryName' => 'United States' |
|
| 54 | - ], |
|
| 55 | - 'showlinks' => true |
|
| 56 | - ] |
|
| 57 | - ]); |
|
| 58 | - |
|
| 59 | - $this->assign('demo3', [ |
|
| 60 | - [ |
|
| 61 | - 'trust' => true, |
|
| 62 | - 'trustedlink' => true, |
|
| 63 | - 'ip' => '172.16.0.164', |
|
| 64 | - 'routable' => false, |
|
| 65 | - |
|
| 66 | - ], [ |
|
| 67 | - 'trust' => false, |
|
| 68 | - 'ip' => '198.51.100.234', |
|
| 69 | - 'routable' => true, |
|
| 70 | - 'rdns' => 'sketchyproxy.example.com', |
|
| 71 | - 'showlinks' => true |
|
| 72 | - |
|
| 73 | - ], [ |
|
| 74 | - 'trust' => false, |
|
| 75 | - 'ip' => '192.0.2.1', |
|
| 76 | - 'routable' => true, |
|
| 77 | - 'rdns' => 'client.users.example.org', |
|
| 78 | - 'location' => [ |
|
| 79 | - 'cityName' => 'San Francisco', |
|
| 80 | - 'regionName' => 'California', |
|
| 81 | - 'countryName' => 'United States' |
|
| 82 | - ], |
|
| 83 | - 'showlinks' => true |
|
| 84 | - ] |
|
| 85 | - ]); |
|
| 86 | - |
|
| 87 | - $this->assign('demo4', [ |
|
| 88 | - [ |
|
| 89 | - 'trust' => true, |
|
| 90 | - 'trustedlink' => true, |
|
| 91 | - 'ip' => '172.16.0.164', |
|
| 92 | - 'routable' => false, |
|
| 93 | - |
|
| 94 | - ], [ |
|
| 95 | - 'trust' => true, |
|
| 96 | - 'ip' => '198.51.100.123', |
|
| 97 | - 'routable' => true, |
|
| 98 | - 'rdns' => 'trustedproxy.example.com', |
|
| 99 | - ], [ |
|
| 100 | - 'trust' => false, |
|
| 101 | - 'ip' => '198.51.100.234', |
|
| 102 | - 'routable' => true, |
|
| 103 | - 'rdns' => 'sketchyproxy.example.com', |
|
| 104 | - 'showlinks' => true |
|
| 105 | - ], [ |
|
| 106 | - 'trust' => false, |
|
| 107 | - 'trustedlink' => true, |
|
| 108 | - 'ip' => '198.51.100.124', |
|
| 109 | - 'routable' => true, |
|
| 110 | - 'rdns' => 'trustedproxy2.example.com', |
|
| 111 | - 'showlinks' => true |
|
| 112 | - ], [ |
|
| 113 | - 'trust' => false, |
|
| 114 | - 'ip' => '192.0.2.1', |
|
| 115 | - 'routable' => true, |
|
| 116 | - 'rdns' => 'client.users.example.org', |
|
| 117 | - 'location' => [ |
|
| 118 | - 'cityName' => 'San Francisco', |
|
| 119 | - 'regionName' => 'California', |
|
| 120 | - 'countryName' => 'United States' |
|
| 121 | - ], |
|
| 122 | - 'showlinks' => true |
|
| 123 | - ] |
|
| 124 | - ]); |
|
| 125 | - |
|
| 126 | - $this->assign('demo1', [ |
|
| 127 | - [ |
|
| 128 | - 'trust' => true, |
|
| 129 | - 'trustedlink' => true, |
|
| 130 | - 'ip' => '172.16.0.164', |
|
| 131 | - 'routable' => false, |
|
| 132 | - |
|
| 133 | - ], [ |
|
| 134 | - 'trust' => true, |
|
| 135 | - 'trustedlink' => true, |
|
| 136 | - 'ip' => '192.0.2.1', |
|
| 137 | - 'routable' => true, |
|
| 138 | - 'rdns' => 'client.users.example.org', |
|
| 139 | - 'location' => [ |
|
| 140 | - 'cityName' => 'San Francisco', |
|
| 141 | - 'regionName' => 'California', |
|
| 142 | - 'countryName' => 'United States' |
|
| 143 | - ], |
|
| 144 | - 'showlinks' => true |
|
| 145 | - ] |
|
| 146 | - ]); |
|
| 147 | - } |
|
| 16 | + use RequestData; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * @inheritDoc |
|
| 20 | + */ |
|
| 21 | + protected function main() |
|
| 22 | + { |
|
| 23 | + $this->setTemplate('xffdemo.tpl'); |
|
| 24 | + |
|
| 25 | + // requestHasForwardedIp == false |
|
| 26 | + // requestProxyData |
|
| 27 | + // requestRealIp == proxy |
|
| 28 | + // requestForwardedIp == xff header |
|
| 29 | + // forwardedOrigin == top of the chain, assuming xff is trusted |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + $this->assign('demo2', [ |
|
| 33 | + [ |
|
| 34 | + 'trust' => true, |
|
| 35 | + 'trustedlink' => true, |
|
| 36 | + 'ip' => '172.16.0.164', |
|
| 37 | + 'routable' => false, |
|
| 38 | + |
|
| 39 | + ], [ |
|
| 40 | + 'trust' => true, |
|
| 41 | + 'ip' => '198.51.100.123', |
|
| 42 | + 'routable' => true, |
|
| 43 | + 'rdns' => 'trustedproxy.example.com', |
|
| 44 | + |
|
| 45 | + ], [ |
|
| 46 | + 'trust' => true, |
|
| 47 | + 'ip' => '192.0.2.1', |
|
| 48 | + 'routable' => true, |
|
| 49 | + 'rdns' => 'client.users.example.org', |
|
| 50 | + 'location' => [ |
|
| 51 | + 'cityName' => 'San Francisco', |
|
| 52 | + 'regionName' => 'California', |
|
| 53 | + 'countryName' => 'United States' |
|
| 54 | + ], |
|
| 55 | + 'showlinks' => true |
|
| 56 | + ] |
|
| 57 | + ]); |
|
| 58 | + |
|
| 59 | + $this->assign('demo3', [ |
|
| 60 | + [ |
|
| 61 | + 'trust' => true, |
|
| 62 | + 'trustedlink' => true, |
|
| 63 | + 'ip' => '172.16.0.164', |
|
| 64 | + 'routable' => false, |
|
| 65 | + |
|
| 66 | + ], [ |
|
| 67 | + 'trust' => false, |
|
| 68 | + 'ip' => '198.51.100.234', |
|
| 69 | + 'routable' => true, |
|
| 70 | + 'rdns' => 'sketchyproxy.example.com', |
|
| 71 | + 'showlinks' => true |
|
| 72 | + |
|
| 73 | + ], [ |
|
| 74 | + 'trust' => false, |
|
| 75 | + 'ip' => '192.0.2.1', |
|
| 76 | + 'routable' => true, |
|
| 77 | + 'rdns' => 'client.users.example.org', |
|
| 78 | + 'location' => [ |
|
| 79 | + 'cityName' => 'San Francisco', |
|
| 80 | + 'regionName' => 'California', |
|
| 81 | + 'countryName' => 'United States' |
|
| 82 | + ], |
|
| 83 | + 'showlinks' => true |
|
| 84 | + ] |
|
| 85 | + ]); |
|
| 86 | + |
|
| 87 | + $this->assign('demo4', [ |
|
| 88 | + [ |
|
| 89 | + 'trust' => true, |
|
| 90 | + 'trustedlink' => true, |
|
| 91 | + 'ip' => '172.16.0.164', |
|
| 92 | + 'routable' => false, |
|
| 93 | + |
|
| 94 | + ], [ |
|
| 95 | + 'trust' => true, |
|
| 96 | + 'ip' => '198.51.100.123', |
|
| 97 | + 'routable' => true, |
|
| 98 | + 'rdns' => 'trustedproxy.example.com', |
|
| 99 | + ], [ |
|
| 100 | + 'trust' => false, |
|
| 101 | + 'ip' => '198.51.100.234', |
|
| 102 | + 'routable' => true, |
|
| 103 | + 'rdns' => 'sketchyproxy.example.com', |
|
| 104 | + 'showlinks' => true |
|
| 105 | + ], [ |
|
| 106 | + 'trust' => false, |
|
| 107 | + 'trustedlink' => true, |
|
| 108 | + 'ip' => '198.51.100.124', |
|
| 109 | + 'routable' => true, |
|
| 110 | + 'rdns' => 'trustedproxy2.example.com', |
|
| 111 | + 'showlinks' => true |
|
| 112 | + ], [ |
|
| 113 | + 'trust' => false, |
|
| 114 | + 'ip' => '192.0.2.1', |
|
| 115 | + 'routable' => true, |
|
| 116 | + 'rdns' => 'client.users.example.org', |
|
| 117 | + 'location' => [ |
|
| 118 | + 'cityName' => 'San Francisco', |
|
| 119 | + 'regionName' => 'California', |
|
| 120 | + 'countryName' => 'United States' |
|
| 121 | + ], |
|
| 122 | + 'showlinks' => true |
|
| 123 | + ] |
|
| 124 | + ]); |
|
| 125 | + |
|
| 126 | + $this->assign('demo1', [ |
|
| 127 | + [ |
|
| 128 | + 'trust' => true, |
|
| 129 | + 'trustedlink' => true, |
|
| 130 | + 'ip' => '172.16.0.164', |
|
| 131 | + 'routable' => false, |
|
| 132 | + |
|
| 133 | + ], [ |
|
| 134 | + 'trust' => true, |
|
| 135 | + 'trustedlink' => true, |
|
| 136 | + 'ip' => '192.0.2.1', |
|
| 137 | + 'routable' => true, |
|
| 138 | + 'rdns' => 'client.users.example.org', |
|
| 139 | + 'location' => [ |
|
| 140 | + 'cityName' => 'San Francisco', |
|
| 141 | + 'regionName' => 'California', |
|
| 142 | + 'countryName' => 'United States' |
|
| 143 | + ], |
|
| 144 | + 'showlinks' => true |
|
| 145 | + ] |
|
| 146 | + ]); |
|
| 147 | + } |
|
| 148 | 148 | } |
@@ -14,127 +14,127 @@ |
||
| 14 | 14 | |
| 15 | 15 | class PageErrorLogViewer extends InternalPageBase |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @inheritDoc |
|
| 19 | - */ |
|
| 20 | - protected function main() |
|
| 21 | - { |
|
| 22 | - $this->setHtmlTitle('Exception viewer'); |
|
| 23 | - |
|
| 24 | - $user = User::getCurrent($this->getDatabase()); |
|
| 25 | - $this->assign('canView', $this->barrierTest('view', $user)); |
|
| 26 | - $this->assign('canRemove', $this->barrierTest('remove', $user)); |
|
| 27 | - |
|
| 28 | - // Get the list of exception logs from the error log directory |
|
| 29 | - $errorLogDirectory = $this->getSiteConfiguration()->getErrorLog(); |
|
| 30 | - $files = scandir($errorLogDirectory); |
|
| 31 | - |
|
| 32 | - // Exclude the files we know should be there |
|
| 33 | - $filteredFiles = array_filter($files, function($file) { |
|
| 34 | - return !in_array($file, ['.', '..', 'README.md']); |
|
| 35 | - }); |
|
| 36 | - |
|
| 37 | - $exceptionDetails = array_map(function($item) use ($errorLogDirectory) { |
|
| 38 | - $filename = realpath($errorLogDirectory) . DIRECTORY_SEPARATOR . $item; |
|
| 39 | - |
|
| 40 | - return [ |
|
| 41 | - 'id' => str_replace('.log', '', $item), |
|
| 42 | - 'date' => date('Y-m-d H:i:s', filemtime($filename)), |
|
| 43 | - 'data' => str_replace($this->getSiteConfiguration()->getFilePath(), '.', |
|
| 44 | - unserialize(file_get_contents($filename))), |
|
| 45 | - ]; |
|
| 46 | - }, $filteredFiles); |
|
| 47 | - |
|
| 48 | - $this->assign('exceptionEntries', $exceptionDetails); |
|
| 49 | - $this->setTemplate('errorlog/main.tpl'); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - protected function view() |
|
| 53 | - { |
|
| 54 | - $this->setHtmlTitle('Exception viewer'); |
|
| 55 | - |
|
| 56 | - $requestedErrorId = WebRequest::getString('id'); |
|
| 57 | - $safeFilename = $this->safetyCheck($requestedErrorId); |
|
| 58 | - |
|
| 59 | - if ($safeFilename === false) { |
|
| 60 | - $this->redirect('errorLog'); |
|
| 61 | - |
|
| 62 | - return; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - // note: at this point we've done sufficient sanity checks that we can be confident this value is safe to echo |
|
| 66 | - // back to the user. |
|
| 67 | - $this->assign('id', $requestedErrorId); |
|
| 68 | - $this->assign('date', date('Y-m-d H:i:s', filemtime($safeFilename))); |
|
| 69 | - |
|
| 70 | - $data = unserialize(file_get_contents($safeFilename)); |
|
| 71 | - $this->assign('server', $data['server']); |
|
| 72 | - $this->assign('get', $data['get']); |
|
| 73 | - $this->assign('post', $data['post']); |
|
| 74 | - |
|
| 75 | - $this->assign('globalHandler', $data['globalHandler']); |
|
| 76 | - |
|
| 77 | - $exceptionList = []; |
|
| 78 | - $current = $data; |
|
| 79 | - do { |
|
| 80 | - $ex = [ |
|
| 81 | - 'exception' => $current['exception'], |
|
| 82 | - 'message' => str_replace($this->getSiteConfiguration()->getFilePath(), '.', $current['message']), |
|
| 83 | - 'stack' => str_replace($this->getSiteConfiguration()->getFilePath(), '.', $current['stack']), |
|
| 84 | - ]; |
|
| 85 | - $exceptionList[] = $ex; |
|
| 86 | - |
|
| 87 | - $current = $current['previous']; |
|
| 88 | - } |
|
| 89 | - while ($current !== null); |
|
| 90 | - |
|
| 91 | - $this->assign('exceptionList', $exceptionList); |
|
| 92 | - |
|
| 93 | - $this->setTemplate('errorlog/details.tpl'); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - public function remove() |
|
| 97 | - { |
|
| 98 | - $safeFilename = $this->safetyCheck(WebRequest::getString('id')); |
|
| 99 | - |
|
| 100 | - if ($safeFilename === false) { |
|
| 101 | - $this->redirect('errorLog'); |
|
| 102 | - |
|
| 103 | - return; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - unlink($safeFilename); |
|
| 107 | - |
|
| 108 | - $this->redirect('errorLog'); |
|
| 109 | - |
|
| 110 | - return; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @param string|null $requestedErrorId |
|
| 115 | - * |
|
| 116 | - * @return bool|string |
|
| 117 | - */ |
|
| 118 | - protected function safetyCheck(?string $requestedErrorId) |
|
| 119 | - { |
|
| 120 | - if ($requestedErrorId === null) { |
|
| 121 | - return false; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // security - only allow hex-encoded filenames, as this is what is generated. |
|
| 125 | - // This is prefixed with the configured directory. Path traversal is protected against due to . and / not being |
|
| 126 | - // part of the hex character set. |
|
| 127 | - if (!preg_match('/^[a-f0-9]{40}$/', $requestedErrorId)) { |
|
| 128 | - return false; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $errorLogDirectory = $this->getSiteConfiguration()->getErrorLog(); |
|
| 132 | - $filename = realpath($errorLogDirectory) . DIRECTORY_SEPARATOR . $requestedErrorId . '.log'; |
|
| 133 | - |
|
| 134 | - if (!file_exists($filename)) { |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $filename; |
|
| 139 | - } |
|
| 17 | + /** |
|
| 18 | + * @inheritDoc |
|
| 19 | + */ |
|
| 20 | + protected function main() |
|
| 21 | + { |
|
| 22 | + $this->setHtmlTitle('Exception viewer'); |
|
| 23 | + |
|
| 24 | + $user = User::getCurrent($this->getDatabase()); |
|
| 25 | + $this->assign('canView', $this->barrierTest('view', $user)); |
|
| 26 | + $this->assign('canRemove', $this->barrierTest('remove', $user)); |
|
| 27 | + |
|
| 28 | + // Get the list of exception logs from the error log directory |
|
| 29 | + $errorLogDirectory = $this->getSiteConfiguration()->getErrorLog(); |
|
| 30 | + $files = scandir($errorLogDirectory); |
|
| 31 | + |
|
| 32 | + // Exclude the files we know should be there |
|
| 33 | + $filteredFiles = array_filter($files, function($file) { |
|
| 34 | + return !in_array($file, ['.', '..', 'README.md']); |
|
| 35 | + }); |
|
| 36 | + |
|
| 37 | + $exceptionDetails = array_map(function($item) use ($errorLogDirectory) { |
|
| 38 | + $filename = realpath($errorLogDirectory) . DIRECTORY_SEPARATOR . $item; |
|
| 39 | + |
|
| 40 | + return [ |
|
| 41 | + 'id' => str_replace('.log', '', $item), |
|
| 42 | + 'date' => date('Y-m-d H:i:s', filemtime($filename)), |
|
| 43 | + 'data' => str_replace($this->getSiteConfiguration()->getFilePath(), '.', |
|
| 44 | + unserialize(file_get_contents($filename))), |
|
| 45 | + ]; |
|
| 46 | + }, $filteredFiles); |
|
| 47 | + |
|
| 48 | + $this->assign('exceptionEntries', $exceptionDetails); |
|
| 49 | + $this->setTemplate('errorlog/main.tpl'); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + protected function view() |
|
| 53 | + { |
|
| 54 | + $this->setHtmlTitle('Exception viewer'); |
|
| 55 | + |
|
| 56 | + $requestedErrorId = WebRequest::getString('id'); |
|
| 57 | + $safeFilename = $this->safetyCheck($requestedErrorId); |
|
| 58 | + |
|
| 59 | + if ($safeFilename === false) { |
|
| 60 | + $this->redirect('errorLog'); |
|
| 61 | + |
|
| 62 | + return; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + // note: at this point we've done sufficient sanity checks that we can be confident this value is safe to echo |
|
| 66 | + // back to the user. |
|
| 67 | + $this->assign('id', $requestedErrorId); |
|
| 68 | + $this->assign('date', date('Y-m-d H:i:s', filemtime($safeFilename))); |
|
| 69 | + |
|
| 70 | + $data = unserialize(file_get_contents($safeFilename)); |
|
| 71 | + $this->assign('server', $data['server']); |
|
| 72 | + $this->assign('get', $data['get']); |
|
| 73 | + $this->assign('post', $data['post']); |
|
| 74 | + |
|
| 75 | + $this->assign('globalHandler', $data['globalHandler']); |
|
| 76 | + |
|
| 77 | + $exceptionList = []; |
|
| 78 | + $current = $data; |
|
| 79 | + do { |
|
| 80 | + $ex = [ |
|
| 81 | + 'exception' => $current['exception'], |
|
| 82 | + 'message' => str_replace($this->getSiteConfiguration()->getFilePath(), '.', $current['message']), |
|
| 83 | + 'stack' => str_replace($this->getSiteConfiguration()->getFilePath(), '.', $current['stack']), |
|
| 84 | + ]; |
|
| 85 | + $exceptionList[] = $ex; |
|
| 86 | + |
|
| 87 | + $current = $current['previous']; |
|
| 88 | + } |
|
| 89 | + while ($current !== null); |
|
| 90 | + |
|
| 91 | + $this->assign('exceptionList', $exceptionList); |
|
| 92 | + |
|
| 93 | + $this->setTemplate('errorlog/details.tpl'); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + public function remove() |
|
| 97 | + { |
|
| 98 | + $safeFilename = $this->safetyCheck(WebRequest::getString('id')); |
|
| 99 | + |
|
| 100 | + if ($safeFilename === false) { |
|
| 101 | + $this->redirect('errorLog'); |
|
| 102 | + |
|
| 103 | + return; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + unlink($safeFilename); |
|
| 107 | + |
|
| 108 | + $this->redirect('errorLog'); |
|
| 109 | + |
|
| 110 | + return; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @param string|null $requestedErrorId |
|
| 115 | + * |
|
| 116 | + * @return bool|string |
|
| 117 | + */ |
|
| 118 | + protected function safetyCheck(?string $requestedErrorId) |
|
| 119 | + { |
|
| 120 | + if ($requestedErrorId === null) { |
|
| 121 | + return false; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // security - only allow hex-encoded filenames, as this is what is generated. |
|
| 125 | + // This is prefixed with the configured directory. Path traversal is protected against due to . and / not being |
|
| 126 | + // part of the hex character set. |
|
| 127 | + if (!preg_match('/^[a-f0-9]{40}$/', $requestedErrorId)) { |
|
| 128 | + return false; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $errorLogDirectory = $this->getSiteConfiguration()->getErrorLog(); |
|
| 132 | + $filename = realpath($errorLogDirectory) . DIRECTORY_SEPARATOR . $requestedErrorId . '.log'; |
|
| 133 | + |
|
| 134 | + if (!file_exists($filename)) { |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $filename; |
|
| 139 | + } |
|
| 140 | 140 | } |
| 141 | 141 | \ No newline at end of file |
@@ -18,59 +18,59 @@ |
||
| 18 | 18 | |
| 19 | 19 | class PageExpandedRequestList extends InternalPageBase |
| 20 | 20 | { |
| 21 | - use RequestListData; |
|
| 21 | + use RequestListData; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Main function for this page, when no specific actions are called. |
|
| 25 | - * @return void |
|
| 26 | - * @todo This is very similar to the PageMain code, we could probably generalise this somehow |
|
| 27 | - */ |
|
| 28 | - protected function main() |
|
| 29 | - { |
|
| 30 | - if (WebRequest::getString('queue') === null) { |
|
| 31 | - $this->redirect(''); |
|
| 32 | - return; |
|
| 33 | - } |
|
| 23 | + /** |
|
| 24 | + * Main function for this page, when no specific actions are called. |
|
| 25 | + * @return void |
|
| 26 | + * @todo This is very similar to the PageMain code, we could probably generalise this somehow |
|
| 27 | + */ |
|
| 28 | + protected function main() |
|
| 29 | + { |
|
| 30 | + if (WebRequest::getString('queue') === null) { |
|
| 31 | + $this->redirect(''); |
|
| 32 | + return; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - $database = $this->getDatabase(); |
|
| 35 | + $database = $this->getDatabase(); |
|
| 36 | 36 | |
| 37 | - // FIXME: domains |
|
| 38 | - $queue = RequestQueue::getByApiName($database, WebRequest::getString('queue'), 1); |
|
| 37 | + // FIXME: domains |
|
| 38 | + $queue = RequestQueue::getByApiName($database, WebRequest::getString('queue'), 1); |
|
| 39 | 39 | |
| 40 | - if ($queue === false) { |
|
| 41 | - $this->redirect(''); |
|
| 42 | - return; |
|
| 43 | - } |
|
| 40 | + if ($queue === false) { |
|
| 41 | + $this->redirect(''); |
|
| 42 | + return; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** @var SiteConfiguration $config */ |
|
| 46 | - $config = $this->getSiteConfiguration(); |
|
| 45 | + /** @var SiteConfiguration $config */ |
|
| 46 | + $config = $this->getSiteConfiguration(); |
|
| 47 | 47 | |
| 48 | - $this->assignCSRFToken(); |
|
| 48 | + $this->assignCSRFToken(); |
|
| 49 | 49 | |
| 50 | - $this->assign('queuehelp', $queue->getHelp()); |
|
| 50 | + $this->assign('queuehelp', $queue->getHelp()); |
|
| 51 | 51 | |
| 52 | - // FIXME: domains |
|
| 53 | - $search = RequestSearchHelper::get($database, 1); |
|
| 54 | - $search->byStatus(RequestStatus::OPEN); |
|
| 52 | + // FIXME: domains |
|
| 53 | + $search = RequestSearchHelper::get($database, 1); |
|
| 54 | + $search->byStatus(RequestStatus::OPEN); |
|
| 55 | 55 | |
| 56 | - list($defaultSort, $defaultSortDirection) = WebRequest::requestListDefaultSort(); |
|
| 57 | - $this->assign('defaultSort', $defaultSort); |
|
| 58 | - $this->assign('defaultSortDirection', $defaultSortDirection); |
|
| 56 | + list($defaultSort, $defaultSortDirection) = WebRequest::requestListDefaultSort(); |
|
| 57 | + $this->assign('defaultSort', $defaultSort); |
|
| 58 | + $this->assign('defaultSortDirection', $defaultSortDirection); |
|
| 59 | 59 | |
| 60 | - if ($config->getEmailConfirmationEnabled()) { |
|
| 61 | - $search->withConfirmedEmail(); |
|
| 62 | - } |
|
| 60 | + if ($config->getEmailConfirmationEnabled()) { |
|
| 61 | + $search->withConfirmedEmail(); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - $queuesById = [$queue->getId() => $queue]; |
|
| 65 | - $requestsByQueue = $search->fetchByQueue(array_keys($queuesById)); |
|
| 66 | - $requestData = $requestsByQueue[$queue->getId()]; |
|
| 64 | + $queuesById = [$queue->getId() => $queue]; |
|
| 65 | + $requestsByQueue = $search->fetchByQueue(array_keys($queuesById)); |
|
| 66 | + $requestData = $requestsByQueue[$queue->getId()]; |
|
| 67 | 67 | |
| 68 | - $this->assign('requests', $this->prepareRequestData($requestData['data'])); |
|
| 69 | - $this->assign('totalRequests', $requestData['count']); |
|
| 70 | - $this->assign('header', $queue->getHeader()); |
|
| 71 | - $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
| 68 | + $this->assign('requests', $this->prepareRequestData($requestData['data'])); |
|
| 69 | + $this->assign('totalRequests', $requestData['count']); |
|
| 70 | + $this->assign('header', $queue->getHeader()); |
|
| 71 | + $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
| 72 | 72 | |
| 73 | - $this->setHtmlTitle('{$header|escape}{if $totalRequests > 0} [{$totalRequests|escape}]{/if}'); |
|
| 74 | - $this->setTemplate('mainpage/expandedrequestlist.tpl'); |
|
| 75 | - } |
|
| 73 | + $this->setHtmlTitle('{$header|escape}{if $totalRequests > 0} [{$totalRequests|escape}]{/if}'); |
|
| 74 | + $this->setTemplate('mainpage/expandedrequestlist.tpl'); |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -19,67 +19,67 @@ |
||
| 19 | 19 | |
| 20 | 20 | class PageFlagComment extends InternalPageBase |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @inheritDoc |
|
| 24 | - */ |
|
| 25 | - protected function main() |
|
| 26 | - { |
|
| 27 | - if (!WebRequest::wasPosted()) { |
|
| 28 | - throw new ApplicationLogicException('This page does not support GET methods.'); |
|
| 29 | - } |
|
| 22 | + /** |
|
| 23 | + * @inheritDoc |
|
| 24 | + */ |
|
| 25 | + protected function main() |
|
| 26 | + { |
|
| 27 | + if (!WebRequest::wasPosted()) { |
|
| 28 | + throw new ApplicationLogicException('This page does not support GET methods.'); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - $this->validateCSRFToken(); |
|
| 31 | + $this->validateCSRFToken(); |
|
| 32 | 32 | |
| 33 | - $flagState = WebRequest::postInt('flag'); |
|
| 34 | - $commentId = WebRequest::postInt('comment'); |
|
| 35 | - $updateVersion = WebRequest::postInt('updateversion'); |
|
| 33 | + $flagState = WebRequest::postInt('flag'); |
|
| 34 | + $commentId = WebRequest::postInt('comment'); |
|
| 35 | + $updateVersion = WebRequest::postInt('updateversion'); |
|
| 36 | 36 | |
| 37 | - if ($flagState !== 0 && $flagState !== 1) { |
|
| 38 | - throw new ApplicationLogicException('Flag status not valid'); |
|
| 39 | - } |
|
| 37 | + if ($flagState !== 0 && $flagState !== 1) { |
|
| 38 | + throw new ApplicationLogicException('Flag status not valid'); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - $database = $this->getDatabase(); |
|
| 41 | + $database = $this->getDatabase(); |
|
| 42 | 42 | |
| 43 | - /** @var Comment|false $comment */ |
|
| 44 | - $comment = Comment::getById($commentId, $database); |
|
| 45 | - if ($comment === false) { |
|
| 46 | - throw new ApplicationLogicException('Unknown comment'); |
|
| 47 | - } |
|
| 43 | + /** @var Comment|false $comment */ |
|
| 44 | + $comment = Comment::getById($commentId, $database); |
|
| 45 | + if ($comment === false) { |
|
| 46 | + throw new ApplicationLogicException('Unknown comment'); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - $currentUser = User::getCurrent($database); |
|
| 49 | + $currentUser = User::getCurrent($database); |
|
| 50 | 50 | |
| 51 | - if ($comment->getFlagged() && !$this->barrierTest('unflag', $currentUser)) { |
|
| 52 | - // user isn't allowed to unflag comments |
|
| 53 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 54 | - } |
|
| 51 | + if ($comment->getFlagged() && !$this->barrierTest('unflag', $currentUser)) { |
|
| 52 | + // user isn't allowed to unflag comments |
|
| 53 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** @var Request $request */ |
|
| 57 | - $request = Request::getById($comment->getRequest(), $database); |
|
| 56 | + /** @var Request $request */ |
|
| 57 | + $request = Request::getById($comment->getRequest(), $database); |
|
| 58 | 58 | |
| 59 | - if ($comment->getFlagged() |
|
| 60 | - && !$this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData') |
|
| 61 | - && $request->getReserved() !== $currentUser->getId() |
|
| 62 | - ) { |
|
| 63 | - // can't unflag if you can't see it. |
|
| 64 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 65 | - } |
|
| 59 | + if ($comment->getFlagged() |
|
| 60 | + && !$this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData') |
|
| 61 | + && $request->getReserved() !== $currentUser->getId() |
|
| 62 | + ) { |
|
| 63 | + // can't unflag if you can't see it. |
|
| 64 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - $comment->setFlagged($flagState == 1); |
|
| 68 | - $comment->setUpdateVersion($updateVersion); |
|
| 69 | - $comment->save(); |
|
| 67 | + $comment->setFlagged($flagState == 1); |
|
| 68 | + $comment->setUpdateVersion($updateVersion); |
|
| 69 | + $comment->save(); |
|
| 70 | 70 | |
| 71 | - if ($flagState === 1) { |
|
| 72 | - Logger::flaggedComment($database, $comment, $request->getDomain()); |
|
| 73 | - } |
|
| 74 | - else { |
|
| 75 | - Logger::unflaggedComment($database, $comment, $request->getDomain()); |
|
| 76 | - } |
|
| 71 | + if ($flagState === 1) { |
|
| 72 | + Logger::flaggedComment($database, $comment, $request->getDomain()); |
|
| 73 | + } |
|
| 74 | + else { |
|
| 75 | + Logger::unflaggedComment($database, $comment, $request->getDomain()); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - if (WebRequest::postString('return') == 'list') { |
|
| 79 | - $this->redirect('flaggedComments'); |
|
| 80 | - } |
|
| 81 | - else { |
|
| 82 | - $this->redirect('viewRequest', null, ['id' => $comment->getRequest()]); |
|
| 83 | - } |
|
| 84 | - } |
|
| 78 | + if (WebRequest::postString('return') == 'list') { |
|
| 79 | + $this->redirect('flaggedComments'); |
|
| 80 | + } |
|
| 81 | + else { |
|
| 82 | + $this->redirect('viewRequest', null, ['id' => $comment->getRequest()]); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | } |
| 86 | 86 | \ No newline at end of file |
@@ -22,292 +22,292 @@ |
||
| 22 | 22 | |
| 23 | 23 | class PageRequestFormManagement extends InternalPageBase |
| 24 | 24 | { |
| 25 | - protected function main() |
|
| 26 | - { |
|
| 27 | - $this->setHtmlTitle('Request Form Management'); |
|
| 28 | - |
|
| 29 | - $database = $this->getDatabase(); |
|
| 30 | - $domainId = Domain::getCurrent($database)->getId(); |
|
| 31 | - $forms = RequestForm::getAllForms($database, $domainId); |
|
| 32 | - $this->assign('forms', $forms); |
|
| 33 | - |
|
| 34 | - $queues = []; |
|
| 35 | - foreach ($forms as $f) { |
|
| 36 | - $queueId = $f->getOverrideQueue(); |
|
| 37 | - if ($queueId !== null) { |
|
| 38 | - if (!isset($queues[$queueId])) { |
|
| 39 | - /** @var RequestQueue $queue */ |
|
| 40 | - $queue = RequestQueue::getById($queueId, $this->getDatabase()); |
|
| 41 | - |
|
| 42 | - if ($queue->getDomain() == $domainId) { |
|
| 43 | - $queues[$queueId] = $queue; |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - $this->assign('queues', $queues); |
|
| 50 | - |
|
| 51 | - $user = User::getCurrent($database); |
|
| 52 | - $this->assign('canCreate', $this->barrierTest('create', $user)); |
|
| 53 | - $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
| 54 | - $this->assign('canView', $this->barrierTest('view', $user)); |
|
| 55 | - |
|
| 56 | - $this->setTemplate('form-management/main.tpl'); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - protected function preview() { |
|
| 60 | - $previewContent = WebRequest::getSessionContext('preview'); |
|
| 61 | - |
|
| 62 | - $renderer = new MarkdownRenderingHelper(); |
|
| 63 | - $this->assign('renderedContent', $renderer->doRender($previewContent['main'])); |
|
| 64 | - $this->assign('username', $renderer->doRenderInline($previewContent['username'])); |
|
| 65 | - $this->assign('email', $renderer->doRenderInline($previewContent['email'])); |
|
| 66 | - $this->assign('comment', $renderer->doRenderInline($previewContent['comment'])); |
|
| 67 | - |
|
| 68 | - $this->setTemplate('form-management/preview.tpl'); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - protected function create() |
|
| 72 | - { |
|
| 73 | - if (WebRequest::wasPosted()) { |
|
| 74 | - $this->validateCSRFToken(); |
|
| 75 | - $database = $this->getDatabase(); |
|
| 76 | - $domainId = Domain::getCurrent($database)->getId(); |
|
| 77 | - |
|
| 78 | - $form = new RequestForm(); |
|
| 79 | - |
|
| 80 | - $form->setDatabase($database); |
|
| 81 | - $form->setDomain($domainId); |
|
| 82 | - |
|
| 83 | - $this->setupObjectFromPost($form); |
|
| 84 | - $form->setPublicEndpoint(WebRequest::postString('endpoint')); |
|
| 85 | - |
|
| 86 | - if (WebRequest::postString("preview") === "preview") { |
|
| 87 | - $this->populateFromObject($form); |
|
| 88 | - |
|
| 89 | - WebRequest::setSessionContext('preview', [ |
|
| 90 | - 'main' => $form->getFormContent(), |
|
| 91 | - 'username' => $form->getUsernameHelp(), |
|
| 92 | - 'email' => $form->getEmailHelp(), |
|
| 93 | - 'comment' => $form->getCommentHelp(), |
|
| 94 | - ]); |
|
| 95 | - |
|
| 96 | - $this->assign('createMode', true); |
|
| 97 | - $this->setTemplate('form-management/edit.tpl'); |
|
| 98 | - |
|
| 99 | - return; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $proceed = true; |
|
| 103 | - |
|
| 104 | - if (RequestForm::getByPublicEndpoint($database, $form->getPublicEndpoint(), $domainId) !== false) { |
|
| 105 | - SessionAlert::error("The chosen public endpoint is already in use. Please choose another."); |
|
| 106 | - $proceed = false; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if (preg_match('/^[A-Za-z][a-zA-Z0-9-]*$/', $form->getPublicEndpoint()) !== 1) { |
|
| 110 | - SessionAlert::error("The chosen public endpoint contains invalid characters"); |
|
| 111 | - $proceed = false; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - if (RequestForm::getByName($database, $form->getName(), $domainId) !== false) { |
|
| 115 | - SessionAlert::error("The chosen name is already in use. Please choose another."); |
|
| 116 | - $proceed = false; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if ($form->getOverrideQueue() !== null) { |
|
| 120 | - /** @var RequestQueue|bool $queue */ |
|
| 121 | - $queue = RequestQueue::getById($form->getOverrideQueue(), $database); |
|
| 122 | - if ($queue === false || $queue->getDomain() !== $domainId || !$queue->isEnabled()) { |
|
| 123 | - SessionAlert::error("The chosen queue does not exist or is disabled."); |
|
| 124 | - $proceed = false; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if ($proceed) { |
|
| 129 | - $form->save(); |
|
| 130 | - Logger::requestFormCreated($database, $form); |
|
| 131 | - $this->redirect('requestFormManagement'); |
|
| 132 | - } |
|
| 133 | - else { |
|
| 134 | - $this->populateFromObject($form); |
|
| 135 | - WebRequest::setSessionContext('preview', [ |
|
| 136 | - 'main' => $form->getFormContent(), |
|
| 137 | - 'username' => $form->getUsernameHelp(), |
|
| 138 | - 'email' => $form->getEmailHelp(), |
|
| 139 | - 'comment' => $form->getCommentHelp(), |
|
| 140 | - ]); |
|
| 141 | - |
|
| 142 | - $this->assign('createMode', true); |
|
| 143 | - $this->setTemplate('form-management/edit.tpl'); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - else { |
|
| 147 | - $this->populateFromObject(new RequestForm()); |
|
| 148 | - WebRequest::setSessionContext('preview', null); |
|
| 149 | - $this->assign('hidePreview', true); |
|
| 150 | - |
|
| 151 | - $this->assignCSRFToken(); |
|
| 152 | - $this->assign('createMode', true); |
|
| 153 | - $this->setTemplate('form-management/edit.tpl'); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - protected function view() |
|
| 158 | - { |
|
| 159 | - $database = $this->getDatabase(); |
|
| 160 | - |
|
| 161 | - /** @var RequestForm $form */ |
|
| 162 | - $form = RequestForm::getById(WebRequest::getInt('form'), $database); |
|
| 163 | - |
|
| 164 | - if ($form->getDomain() !== Domain::getCurrent($database)->getId()) { |
|
| 165 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $this->populateFromObject($form); |
|
| 169 | - |
|
| 170 | - if ($form->getOverrideQueue() !== null) { |
|
| 171 | - $this->assign('queueObject', RequestQueue::getById($form->getOverrideQueue(), $database)); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - WebRequest::setSessionContext('preview', [ |
|
| 175 | - 'main' => $form->getFormContent(), |
|
| 176 | - 'username' => $form->getUsernameHelp(), |
|
| 177 | - 'email' => $form->getEmailHelp(), |
|
| 178 | - 'comment' => $form->getCommentHelp(), |
|
| 179 | - ]); |
|
| 180 | - |
|
| 181 | - $renderer = new MarkdownRenderingHelper(); |
|
| 182 | - $this->assign('renderedContent', $renderer->doRender($form->getFormContent())); |
|
| 183 | - |
|
| 184 | - $this->setTemplate('form-management/view.tpl'); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - protected function edit() |
|
| 188 | - { |
|
| 189 | - $database = $this->getDatabase(); |
|
| 190 | - |
|
| 191 | - /** @var RequestForm $form */ |
|
| 192 | - $form = RequestForm::getById(WebRequest::getInt('form'), $database); |
|
| 193 | - |
|
| 194 | - if ($form->getDomain() !== Domain::getCurrent($database)->getId()) { |
|
| 195 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if (WebRequest::wasPosted()) { |
|
| 199 | - $this->validateCSRFToken(); |
|
| 200 | - |
|
| 201 | - $this->setupObjectFromPost($form); |
|
| 202 | - |
|
| 203 | - if (WebRequest::postString("preview") === "preview") { |
|
| 204 | - $this->populateFromObject($form); |
|
| 205 | - |
|
| 206 | - WebRequest::setSessionContext('preview', [ |
|
| 207 | - 'main' => $form->getFormContent(), |
|
| 208 | - 'username' => $form->getUsernameHelp(), |
|
| 209 | - 'email' => $form->getEmailHelp(), |
|
| 210 | - 'comment' => $form->getCommentHelp(), |
|
| 211 | - ]); |
|
| 212 | - |
|
| 213 | - $this->assign('createMode', false); |
|
| 214 | - $this->setTemplate('form-management/edit.tpl'); |
|
| 215 | - |
|
| 216 | - return; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $proceed = true; |
|
| 220 | - |
|
| 221 | - $foundForm = RequestForm::getByName($database, $form->getName(), $form->getDomain()); |
|
| 222 | - if ($foundForm !== false && $foundForm->getId() !== $form->getId()) { |
|
| 223 | - SessionAlert::error("The chosen name is already in use. Please choose another."); |
|
| 224 | - $proceed = false; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - if ($form->getOverrideQueue() !== null) { |
|
| 228 | - /** @var RequestQueue $queue */ |
|
| 229 | - $queue = RequestQueue::getById($form->getOverrideQueue(), $database); |
|
| 230 | - if ($queue === false || $queue->getDomain() !== $form->getDomain() || !$queue->isEnabled()) { |
|
| 231 | - SessionAlert::error("The chosen queue does not exist or is disabled."); |
|
| 232 | - $proceed = false; |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - if ($proceed) { |
|
| 237 | - Logger::requestFormEdited($database, $form); |
|
| 238 | - $form->save(); |
|
| 239 | - $this->redirect('requestFormManagement'); |
|
| 240 | - } |
|
| 241 | - else { |
|
| 242 | - $this->populateFromObject($form); |
|
| 243 | - WebRequest::setSessionContext('preview', [ |
|
| 244 | - 'main' => $form->getFormContent(), |
|
| 245 | - 'username' => $form->getUsernameHelp(), |
|
| 246 | - 'email' => $form->getEmailHelp(), |
|
| 247 | - 'comment' => $form->getCommentHelp(), |
|
| 248 | - ]); |
|
| 249 | - |
|
| 250 | - $this->assign('createMode', false); |
|
| 251 | - $this->setTemplate('form-management/edit.tpl'); |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - else { |
|
| 255 | - $this->populateFromObject($form); |
|
| 256 | - WebRequest::setSessionContext('preview', [ |
|
| 257 | - 'main' => $form->getFormContent(), |
|
| 258 | - 'username' => $form->getUsernameHelp(), |
|
| 259 | - 'email' => $form->getEmailHelp(), |
|
| 260 | - 'comment' => $form->getCommentHelp(), |
|
| 261 | - ]); |
|
| 262 | - |
|
| 263 | - $this->assign('createMode', false); |
|
| 264 | - $this->setTemplate('form-management/edit.tpl'); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * @param RequestForm $form |
|
| 270 | - */ |
|
| 271 | - protected function populateFromObject(RequestForm $form): void |
|
| 272 | - { |
|
| 273 | - $this->assignCSRFToken(); |
|
| 274 | - |
|
| 275 | - $this->assign('name', $form->getName()); |
|
| 276 | - $this->assign('enabled', $form->isEnabled()); |
|
| 277 | - $this->assign('endpoint', $form->getPublicEndpoint()); |
|
| 278 | - $this->assign('queue', $form->getOverrideQueue()); |
|
| 279 | - $this->assign('content', $form->getFormContent()); |
|
| 280 | - $this->assign('username', $form->getUsernameHelp()); |
|
| 281 | - $this->assign('email', $form->getEmailHelp()); |
|
| 282 | - $this->assign('comment', $form->getCommentHelp()); |
|
| 283 | - |
|
| 284 | - $this->assign('domain', $form->getDomainObject()); |
|
| 285 | - |
|
| 286 | - $this->assign('availableQueues', RequestQueue::getEnabledQueues($this->getDatabase())); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * @param RequestForm $form |
|
| 291 | - * |
|
| 292 | - * @return void |
|
| 293 | - * @throws ApplicationLogicException |
|
| 294 | - */ |
|
| 295 | - protected function setupObjectFromPost(RequestForm $form): void |
|
| 296 | - { |
|
| 297 | - if (WebRequest::postString('content') === null |
|
| 298 | - || WebRequest::postString('username') === null |
|
| 299 | - || WebRequest::postString('email') === null |
|
| 300 | - || WebRequest::postString('comment') === null |
|
| 301 | - ) { |
|
| 302 | - throw new ApplicationLogicException("Form content, username help, email help, and comment help are all required fields."); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - $form->setName(WebRequest::postString('name')); |
|
| 306 | - $form->setEnabled(WebRequest::postBoolean('enabled')); |
|
| 307 | - $form->setFormContent(WebRequest::postString('content')); |
|
| 308 | - $form->setOverrideQueue(WebRequest::postInt('queue')); |
|
| 309 | - $form->setUsernameHelp(WebRequest::postString('username')); |
|
| 310 | - $form->setEmailHelp(WebRequest::postString('email')); |
|
| 311 | - $form->setCommentHelp(WebRequest::postString('comment')); |
|
| 312 | - } |
|
| 25 | + protected function main() |
|
| 26 | + { |
|
| 27 | + $this->setHtmlTitle('Request Form Management'); |
|
| 28 | + |
|
| 29 | + $database = $this->getDatabase(); |
|
| 30 | + $domainId = Domain::getCurrent($database)->getId(); |
|
| 31 | + $forms = RequestForm::getAllForms($database, $domainId); |
|
| 32 | + $this->assign('forms', $forms); |
|
| 33 | + |
|
| 34 | + $queues = []; |
|
| 35 | + foreach ($forms as $f) { |
|
| 36 | + $queueId = $f->getOverrideQueue(); |
|
| 37 | + if ($queueId !== null) { |
|
| 38 | + if (!isset($queues[$queueId])) { |
|
| 39 | + /** @var RequestQueue $queue */ |
|
| 40 | + $queue = RequestQueue::getById($queueId, $this->getDatabase()); |
|
| 41 | + |
|
| 42 | + if ($queue->getDomain() == $domainId) { |
|
| 43 | + $queues[$queueId] = $queue; |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + $this->assign('queues', $queues); |
|
| 50 | + |
|
| 51 | + $user = User::getCurrent($database); |
|
| 52 | + $this->assign('canCreate', $this->barrierTest('create', $user)); |
|
| 53 | + $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
| 54 | + $this->assign('canView', $this->barrierTest('view', $user)); |
|
| 55 | + |
|
| 56 | + $this->setTemplate('form-management/main.tpl'); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + protected function preview() { |
|
| 60 | + $previewContent = WebRequest::getSessionContext('preview'); |
|
| 61 | + |
|
| 62 | + $renderer = new MarkdownRenderingHelper(); |
|
| 63 | + $this->assign('renderedContent', $renderer->doRender($previewContent['main'])); |
|
| 64 | + $this->assign('username', $renderer->doRenderInline($previewContent['username'])); |
|
| 65 | + $this->assign('email', $renderer->doRenderInline($previewContent['email'])); |
|
| 66 | + $this->assign('comment', $renderer->doRenderInline($previewContent['comment'])); |
|
| 67 | + |
|
| 68 | + $this->setTemplate('form-management/preview.tpl'); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + protected function create() |
|
| 72 | + { |
|
| 73 | + if (WebRequest::wasPosted()) { |
|
| 74 | + $this->validateCSRFToken(); |
|
| 75 | + $database = $this->getDatabase(); |
|
| 76 | + $domainId = Domain::getCurrent($database)->getId(); |
|
| 77 | + |
|
| 78 | + $form = new RequestForm(); |
|
| 79 | + |
|
| 80 | + $form->setDatabase($database); |
|
| 81 | + $form->setDomain($domainId); |
|
| 82 | + |
|
| 83 | + $this->setupObjectFromPost($form); |
|
| 84 | + $form->setPublicEndpoint(WebRequest::postString('endpoint')); |
|
| 85 | + |
|
| 86 | + if (WebRequest::postString("preview") === "preview") { |
|
| 87 | + $this->populateFromObject($form); |
|
| 88 | + |
|
| 89 | + WebRequest::setSessionContext('preview', [ |
|
| 90 | + 'main' => $form->getFormContent(), |
|
| 91 | + 'username' => $form->getUsernameHelp(), |
|
| 92 | + 'email' => $form->getEmailHelp(), |
|
| 93 | + 'comment' => $form->getCommentHelp(), |
|
| 94 | + ]); |
|
| 95 | + |
|
| 96 | + $this->assign('createMode', true); |
|
| 97 | + $this->setTemplate('form-management/edit.tpl'); |
|
| 98 | + |
|
| 99 | + return; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $proceed = true; |
|
| 103 | + |
|
| 104 | + if (RequestForm::getByPublicEndpoint($database, $form->getPublicEndpoint(), $domainId) !== false) { |
|
| 105 | + SessionAlert::error("The chosen public endpoint is already in use. Please choose another."); |
|
| 106 | + $proceed = false; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if (preg_match('/^[A-Za-z][a-zA-Z0-9-]*$/', $form->getPublicEndpoint()) !== 1) { |
|
| 110 | + SessionAlert::error("The chosen public endpoint contains invalid characters"); |
|
| 111 | + $proceed = false; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + if (RequestForm::getByName($database, $form->getName(), $domainId) !== false) { |
|
| 115 | + SessionAlert::error("The chosen name is already in use. Please choose another."); |
|
| 116 | + $proceed = false; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if ($form->getOverrideQueue() !== null) { |
|
| 120 | + /** @var RequestQueue|bool $queue */ |
|
| 121 | + $queue = RequestQueue::getById($form->getOverrideQueue(), $database); |
|
| 122 | + if ($queue === false || $queue->getDomain() !== $domainId || !$queue->isEnabled()) { |
|
| 123 | + SessionAlert::error("The chosen queue does not exist or is disabled."); |
|
| 124 | + $proceed = false; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if ($proceed) { |
|
| 129 | + $form->save(); |
|
| 130 | + Logger::requestFormCreated($database, $form); |
|
| 131 | + $this->redirect('requestFormManagement'); |
|
| 132 | + } |
|
| 133 | + else { |
|
| 134 | + $this->populateFromObject($form); |
|
| 135 | + WebRequest::setSessionContext('preview', [ |
|
| 136 | + 'main' => $form->getFormContent(), |
|
| 137 | + 'username' => $form->getUsernameHelp(), |
|
| 138 | + 'email' => $form->getEmailHelp(), |
|
| 139 | + 'comment' => $form->getCommentHelp(), |
|
| 140 | + ]); |
|
| 141 | + |
|
| 142 | + $this->assign('createMode', true); |
|
| 143 | + $this->setTemplate('form-management/edit.tpl'); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + else { |
|
| 147 | + $this->populateFromObject(new RequestForm()); |
|
| 148 | + WebRequest::setSessionContext('preview', null); |
|
| 149 | + $this->assign('hidePreview', true); |
|
| 150 | + |
|
| 151 | + $this->assignCSRFToken(); |
|
| 152 | + $this->assign('createMode', true); |
|
| 153 | + $this->setTemplate('form-management/edit.tpl'); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + protected function view() |
|
| 158 | + { |
|
| 159 | + $database = $this->getDatabase(); |
|
| 160 | + |
|
| 161 | + /** @var RequestForm $form */ |
|
| 162 | + $form = RequestForm::getById(WebRequest::getInt('form'), $database); |
|
| 163 | + |
|
| 164 | + if ($form->getDomain() !== Domain::getCurrent($database)->getId()) { |
|
| 165 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $this->populateFromObject($form); |
|
| 169 | + |
|
| 170 | + if ($form->getOverrideQueue() !== null) { |
|
| 171 | + $this->assign('queueObject', RequestQueue::getById($form->getOverrideQueue(), $database)); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + WebRequest::setSessionContext('preview', [ |
|
| 175 | + 'main' => $form->getFormContent(), |
|
| 176 | + 'username' => $form->getUsernameHelp(), |
|
| 177 | + 'email' => $form->getEmailHelp(), |
|
| 178 | + 'comment' => $form->getCommentHelp(), |
|
| 179 | + ]); |
|
| 180 | + |
|
| 181 | + $renderer = new MarkdownRenderingHelper(); |
|
| 182 | + $this->assign('renderedContent', $renderer->doRender($form->getFormContent())); |
|
| 183 | + |
|
| 184 | + $this->setTemplate('form-management/view.tpl'); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + protected function edit() |
|
| 188 | + { |
|
| 189 | + $database = $this->getDatabase(); |
|
| 190 | + |
|
| 191 | + /** @var RequestForm $form */ |
|
| 192 | + $form = RequestForm::getById(WebRequest::getInt('form'), $database); |
|
| 193 | + |
|
| 194 | + if ($form->getDomain() !== Domain::getCurrent($database)->getId()) { |
|
| 195 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if (WebRequest::wasPosted()) { |
|
| 199 | + $this->validateCSRFToken(); |
|
| 200 | + |
|
| 201 | + $this->setupObjectFromPost($form); |
|
| 202 | + |
|
| 203 | + if (WebRequest::postString("preview") === "preview") { |
|
| 204 | + $this->populateFromObject($form); |
|
| 205 | + |
|
| 206 | + WebRequest::setSessionContext('preview', [ |
|
| 207 | + 'main' => $form->getFormContent(), |
|
| 208 | + 'username' => $form->getUsernameHelp(), |
|
| 209 | + 'email' => $form->getEmailHelp(), |
|
| 210 | + 'comment' => $form->getCommentHelp(), |
|
| 211 | + ]); |
|
| 212 | + |
|
| 213 | + $this->assign('createMode', false); |
|
| 214 | + $this->setTemplate('form-management/edit.tpl'); |
|
| 215 | + |
|
| 216 | + return; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $proceed = true; |
|
| 220 | + |
|
| 221 | + $foundForm = RequestForm::getByName($database, $form->getName(), $form->getDomain()); |
|
| 222 | + if ($foundForm !== false && $foundForm->getId() !== $form->getId()) { |
|
| 223 | + SessionAlert::error("The chosen name is already in use. Please choose another."); |
|
| 224 | + $proceed = false; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + if ($form->getOverrideQueue() !== null) { |
|
| 228 | + /** @var RequestQueue $queue */ |
|
| 229 | + $queue = RequestQueue::getById($form->getOverrideQueue(), $database); |
|
| 230 | + if ($queue === false || $queue->getDomain() !== $form->getDomain() || !$queue->isEnabled()) { |
|
| 231 | + SessionAlert::error("The chosen queue does not exist or is disabled."); |
|
| 232 | + $proceed = false; |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + if ($proceed) { |
|
| 237 | + Logger::requestFormEdited($database, $form); |
|
| 238 | + $form->save(); |
|
| 239 | + $this->redirect('requestFormManagement'); |
|
| 240 | + } |
|
| 241 | + else { |
|
| 242 | + $this->populateFromObject($form); |
|
| 243 | + WebRequest::setSessionContext('preview', [ |
|
| 244 | + 'main' => $form->getFormContent(), |
|
| 245 | + 'username' => $form->getUsernameHelp(), |
|
| 246 | + 'email' => $form->getEmailHelp(), |
|
| 247 | + 'comment' => $form->getCommentHelp(), |
|
| 248 | + ]); |
|
| 249 | + |
|
| 250 | + $this->assign('createMode', false); |
|
| 251 | + $this->setTemplate('form-management/edit.tpl'); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + else { |
|
| 255 | + $this->populateFromObject($form); |
|
| 256 | + WebRequest::setSessionContext('preview', [ |
|
| 257 | + 'main' => $form->getFormContent(), |
|
| 258 | + 'username' => $form->getUsernameHelp(), |
|
| 259 | + 'email' => $form->getEmailHelp(), |
|
| 260 | + 'comment' => $form->getCommentHelp(), |
|
| 261 | + ]); |
|
| 262 | + |
|
| 263 | + $this->assign('createMode', false); |
|
| 264 | + $this->setTemplate('form-management/edit.tpl'); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * @param RequestForm $form |
|
| 270 | + */ |
|
| 271 | + protected function populateFromObject(RequestForm $form): void |
|
| 272 | + { |
|
| 273 | + $this->assignCSRFToken(); |
|
| 274 | + |
|
| 275 | + $this->assign('name', $form->getName()); |
|
| 276 | + $this->assign('enabled', $form->isEnabled()); |
|
| 277 | + $this->assign('endpoint', $form->getPublicEndpoint()); |
|
| 278 | + $this->assign('queue', $form->getOverrideQueue()); |
|
| 279 | + $this->assign('content', $form->getFormContent()); |
|
| 280 | + $this->assign('username', $form->getUsernameHelp()); |
|
| 281 | + $this->assign('email', $form->getEmailHelp()); |
|
| 282 | + $this->assign('comment', $form->getCommentHelp()); |
|
| 283 | + |
|
| 284 | + $this->assign('domain', $form->getDomainObject()); |
|
| 285 | + |
|
| 286 | + $this->assign('availableQueues', RequestQueue::getEnabledQueues($this->getDatabase())); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * @param RequestForm $form |
|
| 291 | + * |
|
| 292 | + * @return void |
|
| 293 | + * @throws ApplicationLogicException |
|
| 294 | + */ |
|
| 295 | + protected function setupObjectFromPost(RequestForm $form): void |
|
| 296 | + { |
|
| 297 | + if (WebRequest::postString('content') === null |
|
| 298 | + || WebRequest::postString('username') === null |
|
| 299 | + || WebRequest::postString('email') === null |
|
| 300 | + || WebRequest::postString('comment') === null |
|
| 301 | + ) { |
|
| 302 | + throw new ApplicationLogicException("Form content, username help, email help, and comment help are all required fields."); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + $form->setName(WebRequest::postString('name')); |
|
| 306 | + $form->setEnabled(WebRequest::postBoolean('enabled')); |
|
| 307 | + $form->setFormContent(WebRequest::postString('content')); |
|
| 308 | + $form->setOverrideQueue(WebRequest::postInt('queue')); |
|
| 309 | + $form->setUsernameHelp(WebRequest::postString('username')); |
|
| 310 | + $form->setEmailHelp(WebRequest::postString('email')); |
|
| 311 | + $form->setCommentHelp(WebRequest::postString('comment')); |
|
| 312 | + } |
|
| 313 | 313 | } |
@@ -23,213 +23,213 @@ |
||
| 23 | 23 | |
| 24 | 24 | class PageForgotPassword extends InternalPageBase |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * Main function for this page, when no specific actions are called. |
|
| 28 | - * |
|
| 29 | - * This is the forgotten password reset form |
|
| 30 | - * @category Security-Critical |
|
| 31 | - */ |
|
| 32 | - protected function main() |
|
| 33 | - { |
|
| 34 | - if (WebRequest::wasPosted()) { |
|
| 35 | - $this->validateCSRFToken(); |
|
| 36 | - $username = WebRequest::postString('username'); |
|
| 37 | - $email = WebRequest::postEmail('email'); |
|
| 38 | - $database = $this->getDatabase(); |
|
| 39 | - |
|
| 40 | - if ($username === null || trim($username) === "" || $email === null || trim($email) === "") { |
|
| 41 | - throw new ApplicationLogicException("Both username and email address must be specified!"); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $user = User::getByUsername($username, $database); |
|
| 45 | - $this->sendResetMail($user, $email); |
|
| 46 | - |
|
| 47 | - SessionAlert::success('<strong>Your password reset request has been completed.</strong> If the details you have provided match our records, you should receive an email shortly.'); |
|
| 48 | - |
|
| 49 | - $this->redirect('login'); |
|
| 50 | - } |
|
| 51 | - else { |
|
| 52 | - $this->assignCSRFToken(); |
|
| 53 | - $this->setTemplate('forgot-password/forgotpw.tpl'); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Sends a reset email if the user is authenticated |
|
| 59 | - * |
|
| 60 | - * @param User|boolean $user The user located from the database, or false. Doesn't really matter, since we do the |
|
| 61 | - * check anyway within this method and silently skip if we don't have a user. |
|
| 62 | - * @param string $email The provided email address |
|
| 63 | - */ |
|
| 64 | - private function sendResetMail($user, $email) |
|
| 65 | - { |
|
| 66 | - // If the user isn't found, or the email address is wrong, skip sending the details silently. |
|
| 67 | - if (!$user instanceof User) { |
|
| 68 | - return; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if (strtolower($user->getEmail()) === strtolower($email)) { |
|
| 72 | - $clientIp = $this->getXffTrustProvider() |
|
| 73 | - ->getTrustedClientIp(WebRequest::remoteAddress(), WebRequest::forwardedAddress()); |
|
| 74 | - |
|
| 75 | - $this->cleanExistingTokens($user); |
|
| 76 | - |
|
| 77 | - $hash = Base32::encodeUpper(openssl_random_pseudo_bytes(30)); |
|
| 78 | - |
|
| 79 | - $encryptionHelper = new EncryptionHelper($this->getSiteConfiguration()); |
|
| 80 | - |
|
| 81 | - $cred = new Credential(); |
|
| 82 | - $cred->setDatabase($this->getDatabase()); |
|
| 83 | - $cred->setFactor(-1); |
|
| 84 | - $cred->setUserId($user->getId()); |
|
| 85 | - $cred->setType('reset'); |
|
| 86 | - $cred->setData($encryptionHelper->encryptData($hash)); |
|
| 87 | - $cred->setVersion(0); |
|
| 88 | - $cred->setDisabled(0); |
|
| 89 | - $cred->setTimeout(new DateTimeImmutable('+ 1 hour')); |
|
| 90 | - $cred->setPriority(9); |
|
| 91 | - $cred->save(); |
|
| 92 | - |
|
| 93 | - $this->assign("user", $user); |
|
| 94 | - $this->assign("hash", $hash); |
|
| 95 | - $this->assign("remoteAddress", $clientIp); |
|
| 96 | - |
|
| 97 | - $emailContent = $this->fetchTemplate('forgot-password/reset-mail.tpl'); |
|
| 98 | - |
|
| 99 | - // FIXME: domains! |
|
| 100 | - /** @var Domain $domain */ |
|
| 101 | - $domain = Domain::getById(1, $this->getDatabase()); |
|
| 102 | - $this->getEmailHelper()->sendMail( |
|
| 103 | - null, $user->getEmail(), "WP:ACC password reset", $emailContent); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Entry point for the reset action |
|
| 109 | - * |
|
| 110 | - * This is the reset password part of the form. |
|
| 111 | - * @category Security-Critical |
|
| 112 | - */ |
|
| 113 | - protected function reset() |
|
| 114 | - { |
|
| 115 | - $si = WebRequest::getString('si'); |
|
| 116 | - $id = WebRequest::getString('id'); |
|
| 117 | - |
|
| 118 | - if ($si === null || trim($si) === "" || $id === null || trim($id) === "") { |
|
| 119 | - throw new ApplicationLogicException("Link not valid, please ensure it has copied correctly"); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $database = $this->getDatabase(); |
|
| 123 | - $user = $this->getResettingUser($id, $database, $si); |
|
| 124 | - |
|
| 125 | - // Dual mode |
|
| 126 | - if (WebRequest::wasPosted()) { |
|
| 127 | - $this->validateCSRFToken(); |
|
| 128 | - try { |
|
| 129 | - $this->doReset($user); |
|
| 130 | - $this->cleanExistingTokens($user); |
|
| 131 | - } |
|
| 132 | - catch (ApplicationLogicException $ex) { |
|
| 133 | - SessionAlert::error($ex->getMessage()); |
|
| 134 | - $this->redirect('forgotPassword', 'reset', array('si' => $si, 'id' => $id)); |
|
| 135 | - |
|
| 136 | - return; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - else { |
|
| 140 | - $this->assignCSRFToken(); |
|
| 141 | - $this->assign('user', $user); |
|
| 142 | - $this->setTemplate('forgot-password/forgotpwreset.tpl'); |
|
| 143 | - $this->addJs("/vendor/dropbox/zxcvbn/dist/zxcvbn.js"); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Gets the user resetting their password from the database, or throwing an exception if that is not possible. |
|
| 149 | - * |
|
| 150 | - * @param integer $id The ID of the user to retrieve |
|
| 151 | - * @param PdoDatabase $database The database object to use |
|
| 152 | - * @param string $si The reset hash provided |
|
| 153 | - * |
|
| 154 | - * @return User |
|
| 155 | - * @throws ApplicationLogicException |
|
| 156 | - */ |
|
| 157 | - private function getResettingUser($id, $database, $si) |
|
| 158 | - { |
|
| 159 | - $user = User::getById($id, $database); |
|
| 160 | - |
|
| 161 | - if ($user === false || $user->isCommunityUser()) { |
|
| 162 | - throw new ApplicationLogicException("Password reset failed. Please try again."); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $statement = $database->prepare("SELECT * FROM credential WHERE type = 'reset' AND user = :user;"); |
|
| 166 | - $statement->execute([':user' => $user->getId()]); |
|
| 167 | - |
|
| 168 | - /** @var Credential $credential */ |
|
| 169 | - $credential = $statement->fetchObject(Credential::class); |
|
| 170 | - |
|
| 171 | - $statement->closeCursor(); |
|
| 172 | - |
|
| 173 | - if ($credential === false) { |
|
| 174 | - throw new ApplicationLogicException("Password reset failed. Please try again."); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $credential->setDatabase($database); |
|
| 178 | - |
|
| 179 | - $encryptionHelper = new EncryptionHelper($this->getSiteConfiguration()); |
|
| 180 | - if ($encryptionHelper->decryptData($credential->getData()) != $si) { |
|
| 181 | - throw new ApplicationLogicException("Password reset failed. Please try again."); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if ($credential->getTimeout() < new DateTimeImmutable()) { |
|
| 185 | - $credential->delete(); |
|
| 186 | - throw new ApplicationLogicException("Password reset token expired. Please try again."); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - return $user; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Performs the setting of the new password |
|
| 194 | - * |
|
| 195 | - * @param User $user The user to set the password for |
|
| 196 | - * |
|
| 197 | - * @throws ApplicationLogicException |
|
| 198 | - */ |
|
| 199 | - private function doReset(User $user) |
|
| 200 | - { |
|
| 201 | - $pw = WebRequest::postString('newpassword'); |
|
| 202 | - $pw2 = WebRequest::postString('newpasswordconfirm'); |
|
| 203 | - |
|
| 204 | - if ($pw !== $pw2) { |
|
| 205 | - throw new ApplicationLogicException('Passwords do not match!'); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - $passwordCredentialProvider = new PasswordCredentialProvider($user->getDatabase(), $this->getSiteConfiguration()); |
|
| 209 | - $passwordCredentialProvider->setCredential($user, 1, $pw); |
|
| 210 | - |
|
| 211 | - SessionAlert::success('You may now log in!'); |
|
| 212 | - $this->redirect('login'); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - protected function isProtectedPage() |
|
| 216 | - { |
|
| 217 | - return false; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @param $user |
|
| 222 | - */ |
|
| 223 | - private function cleanExistingTokens($user): void |
|
| 224 | - { |
|
| 225 | - // clean out existing reset tokens |
|
| 226 | - $statement = $this->getDatabase()->prepare("SELECT * FROM credential WHERE type = 'reset' AND user = :user;"); |
|
| 227 | - $statement->execute([':user' => $user->getId()]); |
|
| 228 | - $existing = $statement->fetchAll(PdoDatabase::FETCH_CLASS, Credential::class); |
|
| 229 | - |
|
| 230 | - foreach ($existing as $c) { |
|
| 231 | - $c->setDatabase($this->getDatabase()); |
|
| 232 | - $c->delete(); |
|
| 233 | - } |
|
| 234 | - } |
|
| 26 | + /** |
|
| 27 | + * Main function for this page, when no specific actions are called. |
|
| 28 | + * |
|
| 29 | + * This is the forgotten password reset form |
|
| 30 | + * @category Security-Critical |
|
| 31 | + */ |
|
| 32 | + protected function main() |
|
| 33 | + { |
|
| 34 | + if (WebRequest::wasPosted()) { |
|
| 35 | + $this->validateCSRFToken(); |
|
| 36 | + $username = WebRequest::postString('username'); |
|
| 37 | + $email = WebRequest::postEmail('email'); |
|
| 38 | + $database = $this->getDatabase(); |
|
| 39 | + |
|
| 40 | + if ($username === null || trim($username) === "" || $email === null || trim($email) === "") { |
|
| 41 | + throw new ApplicationLogicException("Both username and email address must be specified!"); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $user = User::getByUsername($username, $database); |
|
| 45 | + $this->sendResetMail($user, $email); |
|
| 46 | + |
|
| 47 | + SessionAlert::success('<strong>Your password reset request has been completed.</strong> If the details you have provided match our records, you should receive an email shortly.'); |
|
| 48 | + |
|
| 49 | + $this->redirect('login'); |
|
| 50 | + } |
|
| 51 | + else { |
|
| 52 | + $this->assignCSRFToken(); |
|
| 53 | + $this->setTemplate('forgot-password/forgotpw.tpl'); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Sends a reset email if the user is authenticated |
|
| 59 | + * |
|
| 60 | + * @param User|boolean $user The user located from the database, or false. Doesn't really matter, since we do the |
|
| 61 | + * check anyway within this method and silently skip if we don't have a user. |
|
| 62 | + * @param string $email The provided email address |
|
| 63 | + */ |
|
| 64 | + private function sendResetMail($user, $email) |
|
| 65 | + { |
|
| 66 | + // If the user isn't found, or the email address is wrong, skip sending the details silently. |
|
| 67 | + if (!$user instanceof User) { |
|
| 68 | + return; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if (strtolower($user->getEmail()) === strtolower($email)) { |
|
| 72 | + $clientIp = $this->getXffTrustProvider() |
|
| 73 | + ->getTrustedClientIp(WebRequest::remoteAddress(), WebRequest::forwardedAddress()); |
|
| 74 | + |
|
| 75 | + $this->cleanExistingTokens($user); |
|
| 76 | + |
|
| 77 | + $hash = Base32::encodeUpper(openssl_random_pseudo_bytes(30)); |
|
| 78 | + |
|
| 79 | + $encryptionHelper = new EncryptionHelper($this->getSiteConfiguration()); |
|
| 80 | + |
|
| 81 | + $cred = new Credential(); |
|
| 82 | + $cred->setDatabase($this->getDatabase()); |
|
| 83 | + $cred->setFactor(-1); |
|
| 84 | + $cred->setUserId($user->getId()); |
|
| 85 | + $cred->setType('reset'); |
|
| 86 | + $cred->setData($encryptionHelper->encryptData($hash)); |
|
| 87 | + $cred->setVersion(0); |
|
| 88 | + $cred->setDisabled(0); |
|
| 89 | + $cred->setTimeout(new DateTimeImmutable('+ 1 hour')); |
|
| 90 | + $cred->setPriority(9); |
|
| 91 | + $cred->save(); |
|
| 92 | + |
|
| 93 | + $this->assign("user", $user); |
|
| 94 | + $this->assign("hash", $hash); |
|
| 95 | + $this->assign("remoteAddress", $clientIp); |
|
| 96 | + |
|
| 97 | + $emailContent = $this->fetchTemplate('forgot-password/reset-mail.tpl'); |
|
| 98 | + |
|
| 99 | + // FIXME: domains! |
|
| 100 | + /** @var Domain $domain */ |
|
| 101 | + $domain = Domain::getById(1, $this->getDatabase()); |
|
| 102 | + $this->getEmailHelper()->sendMail( |
|
| 103 | + null, $user->getEmail(), "WP:ACC password reset", $emailContent); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Entry point for the reset action |
|
| 109 | + * |
|
| 110 | + * This is the reset password part of the form. |
|
| 111 | + * @category Security-Critical |
|
| 112 | + */ |
|
| 113 | + protected function reset() |
|
| 114 | + { |
|
| 115 | + $si = WebRequest::getString('si'); |
|
| 116 | + $id = WebRequest::getString('id'); |
|
| 117 | + |
|
| 118 | + if ($si === null || trim($si) === "" || $id === null || trim($id) === "") { |
|
| 119 | + throw new ApplicationLogicException("Link not valid, please ensure it has copied correctly"); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $database = $this->getDatabase(); |
|
| 123 | + $user = $this->getResettingUser($id, $database, $si); |
|
| 124 | + |
|
| 125 | + // Dual mode |
|
| 126 | + if (WebRequest::wasPosted()) { |
|
| 127 | + $this->validateCSRFToken(); |
|
| 128 | + try { |
|
| 129 | + $this->doReset($user); |
|
| 130 | + $this->cleanExistingTokens($user); |
|
| 131 | + } |
|
| 132 | + catch (ApplicationLogicException $ex) { |
|
| 133 | + SessionAlert::error($ex->getMessage()); |
|
| 134 | + $this->redirect('forgotPassword', 'reset', array('si' => $si, 'id' => $id)); |
|
| 135 | + |
|
| 136 | + return; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + else { |
|
| 140 | + $this->assignCSRFToken(); |
|
| 141 | + $this->assign('user', $user); |
|
| 142 | + $this->setTemplate('forgot-password/forgotpwreset.tpl'); |
|
| 143 | + $this->addJs("/vendor/dropbox/zxcvbn/dist/zxcvbn.js"); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Gets the user resetting their password from the database, or throwing an exception if that is not possible. |
|
| 149 | + * |
|
| 150 | + * @param integer $id The ID of the user to retrieve |
|
| 151 | + * @param PdoDatabase $database The database object to use |
|
| 152 | + * @param string $si The reset hash provided |
|
| 153 | + * |
|
| 154 | + * @return User |
|
| 155 | + * @throws ApplicationLogicException |
|
| 156 | + */ |
|
| 157 | + private function getResettingUser($id, $database, $si) |
|
| 158 | + { |
|
| 159 | + $user = User::getById($id, $database); |
|
| 160 | + |
|
| 161 | + if ($user === false || $user->isCommunityUser()) { |
|
| 162 | + throw new ApplicationLogicException("Password reset failed. Please try again."); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $statement = $database->prepare("SELECT * FROM credential WHERE type = 'reset' AND user = :user;"); |
|
| 166 | + $statement->execute([':user' => $user->getId()]); |
|
| 167 | + |
|
| 168 | + /** @var Credential $credential */ |
|
| 169 | + $credential = $statement->fetchObject(Credential::class); |
|
| 170 | + |
|
| 171 | + $statement->closeCursor(); |
|
| 172 | + |
|
| 173 | + if ($credential === false) { |
|
| 174 | + throw new ApplicationLogicException("Password reset failed. Please try again."); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $credential->setDatabase($database); |
|
| 178 | + |
|
| 179 | + $encryptionHelper = new EncryptionHelper($this->getSiteConfiguration()); |
|
| 180 | + if ($encryptionHelper->decryptData($credential->getData()) != $si) { |
|
| 181 | + throw new ApplicationLogicException("Password reset failed. Please try again."); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if ($credential->getTimeout() < new DateTimeImmutable()) { |
|
| 185 | + $credential->delete(); |
|
| 186 | + throw new ApplicationLogicException("Password reset token expired. Please try again."); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + return $user; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Performs the setting of the new password |
|
| 194 | + * |
|
| 195 | + * @param User $user The user to set the password for |
|
| 196 | + * |
|
| 197 | + * @throws ApplicationLogicException |
|
| 198 | + */ |
|
| 199 | + private function doReset(User $user) |
|
| 200 | + { |
|
| 201 | + $pw = WebRequest::postString('newpassword'); |
|
| 202 | + $pw2 = WebRequest::postString('newpasswordconfirm'); |
|
| 203 | + |
|
| 204 | + if ($pw !== $pw2) { |
|
| 205 | + throw new ApplicationLogicException('Passwords do not match!'); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + $passwordCredentialProvider = new PasswordCredentialProvider($user->getDatabase(), $this->getSiteConfiguration()); |
|
| 209 | + $passwordCredentialProvider->setCredential($user, 1, $pw); |
|
| 210 | + |
|
| 211 | + SessionAlert::success('You may now log in!'); |
|
| 212 | + $this->redirect('login'); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + protected function isProtectedPage() |
|
| 216 | + { |
|
| 217 | + return false; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @param $user |
|
| 222 | + */ |
|
| 223 | + private function cleanExistingTokens($user): void |
|
| 224 | + { |
|
| 225 | + // clean out existing reset tokens |
|
| 226 | + $statement = $this->getDatabase()->prepare("SELECT * FROM credential WHERE type = 'reset' AND user = :user;"); |
|
| 227 | + $statement->execute([':user' => $user->getId()]); |
|
| 228 | + $existing = $statement->fetchAll(PdoDatabase::FETCH_CLASS, Credential::class); |
|
| 229 | + |
|
| 230 | + foreach ($existing as $c) { |
|
| 231 | + $c->setDatabase($this->getDatabase()); |
|
| 232 | + $c->delete(); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | 235 | } |
@@ -13,31 +13,31 @@ |
||
| 13 | 13 | |
| 14 | 14 | class PagePasswordLogin extends LoginCredentialPageBase |
| 15 | 15 | { |
| 16 | - protected function providerSpecificSetup() |
|
| 17 | - { |
|
| 18 | - list($partialId, $partialStage) = WebRequest::getAuthPartialLogin(); |
|
| 19 | - |
|
| 20 | - if ($partialId !== null && $partialStage > 1) { |
|
| 21 | - $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0 ORDER BY priority'; |
|
| 22 | - $statement = $this->getDatabase()->prepare($sql); |
|
| 23 | - $statement->execute(array(':user' => $partialId, ':stage' => $partialStage)); |
|
| 24 | - $nextStage = $statement->fetchColumn(); |
|
| 25 | - $statement->closeCursor(); |
|
| 26 | - |
|
| 27 | - $this->redirect("login/" . $this->nextPageMap[$nextStage]); |
|
| 28 | - return; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $this->setTemplate('login/password.tpl'); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - protected function getProviderCredentials() |
|
| 35 | - { |
|
| 36 | - $password = WebRequest::postString("password"); |
|
| 37 | - if ($password === null || $password === "") { |
|
| 38 | - throw new ApplicationLogicException("No password specified"); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - return $password; |
|
| 42 | - } |
|
| 16 | + protected function providerSpecificSetup() |
|
| 17 | + { |
|
| 18 | + list($partialId, $partialStage) = WebRequest::getAuthPartialLogin(); |
|
| 19 | + |
|
| 20 | + if ($partialId !== null && $partialStage > 1) { |
|
| 21 | + $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0 ORDER BY priority'; |
|
| 22 | + $statement = $this->getDatabase()->prepare($sql); |
|
| 23 | + $statement->execute(array(':user' => $partialId, ':stage' => $partialStage)); |
|
| 24 | + $nextStage = $statement->fetchColumn(); |
|
| 25 | + $statement->closeCursor(); |
|
| 26 | + |
|
| 27 | + $this->redirect("login/" . $this->nextPageMap[$nextStage]); |
|
| 28 | + return; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $this->setTemplate('login/password.tpl'); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + protected function getProviderCredentials() |
|
| 35 | + { |
|
| 36 | + $password = WebRequest::postString("password"); |
|
| 37 | + if ($password === null || $password === "") { |
|
| 38 | + throw new ApplicationLogicException("No password specified"); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + return $password; |
|
| 42 | + } |
|
| 43 | 43 | } |
| 44 | 44 | \ No newline at end of file |