@@ -18,191 +18,191 @@ |
||
| 18 | 18 | |
| 19 | 19 | class PageQueueManagement extends InternalPageBase |
| 20 | 20 | { |
| 21 | - /** @var RequestQueueHelper */ |
|
| 22 | - private $helper; |
|
| 23 | - |
|
| 24 | - public function __construct() |
|
| 25 | - { |
|
| 26 | - $this->helper = new RequestQueueHelper(); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - protected function main() |
|
| 30 | - { |
|
| 31 | - $this->setHtmlTitle('Request Queue Management'); |
|
| 32 | - |
|
| 33 | - $database = $this->getDatabase(); |
|
| 34 | - $queues = RequestQueue::getAllQueues($database); |
|
| 35 | - |
|
| 36 | - $this->assign('queues', $queues); |
|
| 37 | - |
|
| 38 | - $user = User::getCurrent($database); |
|
| 39 | - $this->assign('canCreate', $this->barrierTest('create', $user)); |
|
| 40 | - $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
| 41 | - |
|
| 42 | - $this->setTemplate('queue-management/main.tpl'); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - protected function create() |
|
| 46 | - { |
|
| 47 | - if (WebRequest::wasPosted()) { |
|
| 48 | - $this->validateCSRFToken(); |
|
| 49 | - $database = $this->getDatabase(); |
|
| 50 | - |
|
| 51 | - $queue = new RequestQueue(); |
|
| 52 | - |
|
| 53 | - $queue->setDatabase($database); |
|
| 54 | - $queue->setDomain(1); // FIXME: domain |
|
| 55 | - |
|
| 56 | - $queue->setHeader(WebRequest::postString('header')); |
|
| 57 | - $queue->setDisplayName(WebRequest::postString('displayName')); |
|
| 58 | - $queue->setApiName(WebRequest::postString('apiName')); |
|
| 59 | - $queue->setEnabled(WebRequest::postBoolean('enabled')); |
|
| 60 | - $queue->setDefault(WebRequest::postBoolean('default') && WebRequest::postBoolean('enabled')); |
|
| 61 | - $queue->setDefaultAntispoof(WebRequest::postBoolean('antispoof') && WebRequest::postBoolean('enabled')); |
|
| 62 | - $queue->setDefaultTitleBlacklist(WebRequest::postBoolean('titleblacklist') && WebRequest::postBoolean('enabled')); |
|
| 63 | - $queue->setHelp(WebRequest::postString('help')); |
|
| 64 | - $queue->setLogName(WebRequest::postString('logName')); |
|
| 65 | - |
|
| 66 | - $proceed = true; |
|
| 67 | - |
|
| 68 | - if (RequestQueue::getByApiName($database, $queue->getApiName(), 1) !== false) { |
|
| 69 | - // FIXME: domain |
|
| 70 | - SessionAlert::error("The chosen API name is already in use. Please choose another."); |
|
| 71 | - $proceed = false; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if (preg_match('/^[A-Za-z][a-zA-Z0-9_-]*$/', $queue->getApiName()) !== 1) { |
|
| 75 | - SessionAlert::error("The chosen API name contains invalid characters"); |
|
| 76 | - $proceed = false; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if (RequestQueue::getByDisplayName($database, $queue->getDisplayName(), 1) !== false) { |
|
| 80 | - // FIXME: domain |
|
| 81 | - SessionAlert::error("The chosen target display name is already in use. Please choose another."); |
|
| 82 | - $proceed = false; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if (RequestQueue::getByHeader($database, $queue->getHeader(), 1) !== false) { |
|
| 86 | - // FIXME: domain |
|
| 87 | - SessionAlert::error("The chosen header is already in use. Please choose another."); |
|
| 88 | - $proceed = false; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - if ($proceed) { |
|
| 92 | - $queue->save(); |
|
| 93 | - Logger::requestQueueCreated($database, $queue); |
|
| 94 | - $this->redirect('queueManagement'); |
|
| 95 | - } |
|
| 96 | - else { |
|
| 97 | - $this->populateFromObject($queue); |
|
| 98 | - |
|
| 99 | - $this->assign('createMode', true); |
|
| 100 | - $this->setTemplate('queue-management/edit.tpl'); |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - else { |
|
| 104 | - $this->assign('header', null); |
|
| 105 | - $this->assign('displayName', null); |
|
| 106 | - $this->assign('apiName', null); |
|
| 107 | - $this->assign('enabled', false); |
|
| 108 | - $this->assign('antispoof', false); |
|
| 109 | - $this->assign('isTarget', false); |
|
| 110 | - $this->assign('titleblacklist', false); |
|
| 111 | - $this->assign('default', false); |
|
| 112 | - $this->assign('help', null); |
|
| 113 | - $this->assign('logName', null); |
|
| 114 | - |
|
| 115 | - $this->assignCSRFToken(); |
|
| 116 | - $this->assign('createMode', true); |
|
| 117 | - $this->setTemplate('queue-management/edit.tpl'); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - protected function edit() |
|
| 122 | - { |
|
| 123 | - $database = $this->getDatabase(); |
|
| 124 | - |
|
| 125 | - $id = WebRequest::getInt('queue'); |
|
| 126 | - if ($id === null) { |
|
| 127 | - $this->redirect('queueManagement'); |
|
| 128 | - |
|
| 129 | - return; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** @var RequestQueue $queue */ |
|
| 133 | - $queue = RequestQueue::getById($id, $database); |
|
| 134 | - |
|
| 135 | - if (WebRequest::wasPosted()) { |
|
| 136 | - $this->validateCSRFToken(); |
|
| 137 | - |
|
| 138 | - $this->helper->configureDefaults( |
|
| 139 | - $queue, |
|
| 140 | - WebRequest::postBoolean('enabled'), |
|
| 141 | - WebRequest::postBoolean('default'), |
|
| 142 | - WebRequest::postBoolean('antispoof'), |
|
| 143 | - WebRequest::postBoolean('titleblacklist'), |
|
| 144 | - $this->helper->isEmailTemplateTarget($queue, $this->getDatabase()) || $this->helper->isRequestFormTarget($queue, $this->getDatabase())); |
|
| 145 | - |
|
| 146 | - $queue->setHeader(WebRequest::postString('header')); |
|
| 147 | - $queue->setDisplayName(WebRequest::postString('displayName')); |
|
| 148 | - $queue->setHelp(WebRequest::postString('help')); |
|
| 149 | - |
|
| 150 | - $proceed = true; |
|
| 151 | - |
|
| 152 | - $foundRequestQueue = RequestQueue::getByDisplayName($database, $queue->getDisplayName(), 1); |
|
| 153 | - if ($foundRequestQueue !== false && $foundRequestQueue->getId() !== $queue->getId()) { |
|
| 154 | - // FIXME: domain |
|
| 155 | - SessionAlert::error("The chosen target display name is already in use. Please choose another."); |
|
| 156 | - $proceed = false; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - $foundRequestQueue = RequestQueue::getByHeader($database, $queue->getHeader(), 1); |
|
| 160 | - if ($foundRequestQueue !== false && $foundRequestQueue->getId() !== $queue->getId()) { |
|
| 161 | - // FIXME: domain |
|
| 162 | - SessionAlert::error("The chosen header is already in use. Please choose another."); |
|
| 163 | - $proceed = false; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if ($proceed) { |
|
| 167 | - Logger::requestQueueEdited($database, $queue); |
|
| 168 | - $queue->save(); |
|
| 169 | - $this->redirect('queueManagement'); |
|
| 170 | - } |
|
| 171 | - else { |
|
| 172 | - $this->populateFromObject($queue); |
|
| 173 | - |
|
| 174 | - $this->assign('createMode', false); |
|
| 175 | - $this->setTemplate('queue-management/edit.tpl'); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - else { |
|
| 179 | - $this->populateFromObject($queue); |
|
| 180 | - |
|
| 181 | - $this->assign('createMode', false); |
|
| 182 | - $this->setTemplate('queue-management/edit.tpl'); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @param RequestQueue $queue |
|
| 188 | - */ |
|
| 189 | - protected function populateFromObject(RequestQueue $queue): void |
|
| 190 | - { |
|
| 191 | - $this->assignCSRFToken(); |
|
| 192 | - |
|
| 193 | - $this->assign('header', $queue->getHeader()); |
|
| 194 | - $this->assign('displayName', $queue->getDisplayName()); |
|
| 195 | - $this->assign('apiName', $queue->getApiName()); |
|
| 196 | - $this->assign('enabled', $queue->isEnabled()); |
|
| 197 | - $this->assign('default', $queue->isDefault()); |
|
| 198 | - $this->assign('antispoof', $queue->isDefaultAntispoof()); |
|
| 199 | - $this->assign('titleblacklist', $queue->isDefaultTitleBlacklist()); |
|
| 200 | - $this->assign('help', $queue->getHelp()); |
|
| 201 | - $this->assign('logName', $queue->getLogName()); |
|
| 202 | - |
|
| 203 | - $isQueueTarget = $this->helper->isEmailTemplateTarget($queue, $this->getDatabase()); |
|
| 204 | - $isFormTarget = $this->helper->isRequestFormTarget($queue, $this->getDatabase()); |
|
| 205 | - $this->assign('isTarget', $isQueueTarget); |
|
| 206 | - $this->assign('isFormTarget', $isFormTarget); |
|
| 207 | - } |
|
| 21 | + /** @var RequestQueueHelper */ |
|
| 22 | + private $helper; |
|
| 23 | + |
|
| 24 | + public function __construct() |
|
| 25 | + { |
|
| 26 | + $this->helper = new RequestQueueHelper(); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + protected function main() |
|
| 30 | + { |
|
| 31 | + $this->setHtmlTitle('Request Queue Management'); |
|
| 32 | + |
|
| 33 | + $database = $this->getDatabase(); |
|
| 34 | + $queues = RequestQueue::getAllQueues($database); |
|
| 35 | + |
|
| 36 | + $this->assign('queues', $queues); |
|
| 37 | + |
|
| 38 | + $user = User::getCurrent($database); |
|
| 39 | + $this->assign('canCreate', $this->barrierTest('create', $user)); |
|
| 40 | + $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
| 41 | + |
|
| 42 | + $this->setTemplate('queue-management/main.tpl'); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + protected function create() |
|
| 46 | + { |
|
| 47 | + if (WebRequest::wasPosted()) { |
|
| 48 | + $this->validateCSRFToken(); |
|
| 49 | + $database = $this->getDatabase(); |
|
| 50 | + |
|
| 51 | + $queue = new RequestQueue(); |
|
| 52 | + |
|
| 53 | + $queue->setDatabase($database); |
|
| 54 | + $queue->setDomain(1); // FIXME: domain |
|
| 55 | + |
|
| 56 | + $queue->setHeader(WebRequest::postString('header')); |
|
| 57 | + $queue->setDisplayName(WebRequest::postString('displayName')); |
|
| 58 | + $queue->setApiName(WebRequest::postString('apiName')); |
|
| 59 | + $queue->setEnabled(WebRequest::postBoolean('enabled')); |
|
| 60 | + $queue->setDefault(WebRequest::postBoolean('default') && WebRequest::postBoolean('enabled')); |
|
| 61 | + $queue->setDefaultAntispoof(WebRequest::postBoolean('antispoof') && WebRequest::postBoolean('enabled')); |
|
| 62 | + $queue->setDefaultTitleBlacklist(WebRequest::postBoolean('titleblacklist') && WebRequest::postBoolean('enabled')); |
|
| 63 | + $queue->setHelp(WebRequest::postString('help')); |
|
| 64 | + $queue->setLogName(WebRequest::postString('logName')); |
|
| 65 | + |
|
| 66 | + $proceed = true; |
|
| 67 | + |
|
| 68 | + if (RequestQueue::getByApiName($database, $queue->getApiName(), 1) !== false) { |
|
| 69 | + // FIXME: domain |
|
| 70 | + SessionAlert::error("The chosen API name is already in use. Please choose another."); |
|
| 71 | + $proceed = false; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if (preg_match('/^[A-Za-z][a-zA-Z0-9_-]*$/', $queue->getApiName()) !== 1) { |
|
| 75 | + SessionAlert::error("The chosen API name contains invalid characters"); |
|
| 76 | + $proceed = false; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if (RequestQueue::getByDisplayName($database, $queue->getDisplayName(), 1) !== false) { |
|
| 80 | + // FIXME: domain |
|
| 81 | + SessionAlert::error("The chosen target display name is already in use. Please choose another."); |
|
| 82 | + $proceed = false; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if (RequestQueue::getByHeader($database, $queue->getHeader(), 1) !== false) { |
|
| 86 | + // FIXME: domain |
|
| 87 | + SessionAlert::error("The chosen header is already in use. Please choose another."); |
|
| 88 | + $proceed = false; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + if ($proceed) { |
|
| 92 | + $queue->save(); |
|
| 93 | + Logger::requestQueueCreated($database, $queue); |
|
| 94 | + $this->redirect('queueManagement'); |
|
| 95 | + } |
|
| 96 | + else { |
|
| 97 | + $this->populateFromObject($queue); |
|
| 98 | + |
|
| 99 | + $this->assign('createMode', true); |
|
| 100 | + $this->setTemplate('queue-management/edit.tpl'); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + else { |
|
| 104 | + $this->assign('header', null); |
|
| 105 | + $this->assign('displayName', null); |
|
| 106 | + $this->assign('apiName', null); |
|
| 107 | + $this->assign('enabled', false); |
|
| 108 | + $this->assign('antispoof', false); |
|
| 109 | + $this->assign('isTarget', false); |
|
| 110 | + $this->assign('titleblacklist', false); |
|
| 111 | + $this->assign('default', false); |
|
| 112 | + $this->assign('help', null); |
|
| 113 | + $this->assign('logName', null); |
|
| 114 | + |
|
| 115 | + $this->assignCSRFToken(); |
|
| 116 | + $this->assign('createMode', true); |
|
| 117 | + $this->setTemplate('queue-management/edit.tpl'); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + protected function edit() |
|
| 122 | + { |
|
| 123 | + $database = $this->getDatabase(); |
|
| 124 | + |
|
| 125 | + $id = WebRequest::getInt('queue'); |
|
| 126 | + if ($id === null) { |
|
| 127 | + $this->redirect('queueManagement'); |
|
| 128 | + |
|
| 129 | + return; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** @var RequestQueue $queue */ |
|
| 133 | + $queue = RequestQueue::getById($id, $database); |
|
| 134 | + |
|
| 135 | + if (WebRequest::wasPosted()) { |
|
| 136 | + $this->validateCSRFToken(); |
|
| 137 | + |
|
| 138 | + $this->helper->configureDefaults( |
|
| 139 | + $queue, |
|
| 140 | + WebRequest::postBoolean('enabled'), |
|
| 141 | + WebRequest::postBoolean('default'), |
|
| 142 | + WebRequest::postBoolean('antispoof'), |
|
| 143 | + WebRequest::postBoolean('titleblacklist'), |
|
| 144 | + $this->helper->isEmailTemplateTarget($queue, $this->getDatabase()) || $this->helper->isRequestFormTarget($queue, $this->getDatabase())); |
|
| 145 | + |
|
| 146 | + $queue->setHeader(WebRequest::postString('header')); |
|
| 147 | + $queue->setDisplayName(WebRequest::postString('displayName')); |
|
| 148 | + $queue->setHelp(WebRequest::postString('help')); |
|
| 149 | + |
|
| 150 | + $proceed = true; |
|
| 151 | + |
|
| 152 | + $foundRequestQueue = RequestQueue::getByDisplayName($database, $queue->getDisplayName(), 1); |
|
| 153 | + if ($foundRequestQueue !== false && $foundRequestQueue->getId() !== $queue->getId()) { |
|
| 154 | + // FIXME: domain |
|
| 155 | + SessionAlert::error("The chosen target display name is already in use. Please choose another."); |
|
| 156 | + $proceed = false; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + $foundRequestQueue = RequestQueue::getByHeader($database, $queue->getHeader(), 1); |
|
| 160 | + if ($foundRequestQueue !== false && $foundRequestQueue->getId() !== $queue->getId()) { |
|
| 161 | + // FIXME: domain |
|
| 162 | + SessionAlert::error("The chosen header is already in use. Please choose another."); |
|
| 163 | + $proceed = false; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if ($proceed) { |
|
| 167 | + Logger::requestQueueEdited($database, $queue); |
|
| 168 | + $queue->save(); |
|
| 169 | + $this->redirect('queueManagement'); |
|
| 170 | + } |
|
| 171 | + else { |
|
| 172 | + $this->populateFromObject($queue); |
|
| 173 | + |
|
| 174 | + $this->assign('createMode', false); |
|
| 175 | + $this->setTemplate('queue-management/edit.tpl'); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + else { |
|
| 179 | + $this->populateFromObject($queue); |
|
| 180 | + |
|
| 181 | + $this->assign('createMode', false); |
|
| 182 | + $this->setTemplate('queue-management/edit.tpl'); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @param RequestQueue $queue |
|
| 188 | + */ |
|
| 189 | + protected function populateFromObject(RequestQueue $queue): void |
|
| 190 | + { |
|
| 191 | + $this->assignCSRFToken(); |
|
| 192 | + |
|
| 193 | + $this->assign('header', $queue->getHeader()); |
|
| 194 | + $this->assign('displayName', $queue->getDisplayName()); |
|
| 195 | + $this->assign('apiName', $queue->getApiName()); |
|
| 196 | + $this->assign('enabled', $queue->isEnabled()); |
|
| 197 | + $this->assign('default', $queue->isDefault()); |
|
| 198 | + $this->assign('antispoof', $queue->isDefaultAntispoof()); |
|
| 199 | + $this->assign('titleblacklist', $queue->isDefaultTitleBlacklist()); |
|
| 200 | + $this->assign('help', $queue->getHelp()); |
|
| 201 | + $this->assign('logName', $queue->getLogName()); |
|
| 202 | + |
|
| 203 | + $isQueueTarget = $this->helper->isEmailTemplateTarget($queue, $this->getDatabase()); |
|
| 204 | + $isFormTarget = $this->helper->isRequestFormTarget($queue, $this->getDatabase()); |
|
| 205 | + $this->assign('isTarget', $isQueueTarget); |
|
| 206 | + $this->assign('isFormTarget', $isFormTarget); |
|
| 207 | + } |
|
| 208 | 208 | } |
| 209 | 209 | \ No newline at end of file |
@@ -92,15 +92,13 @@ discard block |
||
| 92 | 92 | $queue->save(); |
| 93 | 93 | Logger::requestQueueCreated($database, $queue); |
| 94 | 94 | $this->redirect('queueManagement'); |
| 95 | - } |
|
| 96 | - else { |
|
| 95 | + } else { |
|
| 97 | 96 | $this->populateFromObject($queue); |
| 98 | 97 | |
| 99 | 98 | $this->assign('createMode', true); |
| 100 | 99 | $this->setTemplate('queue-management/edit.tpl'); |
| 101 | 100 | } |
| 102 | - } |
|
| 103 | - else { |
|
| 101 | + } else { |
|
| 104 | 102 | $this->assign('header', null); |
| 105 | 103 | $this->assign('displayName', null); |
| 106 | 104 | $this->assign('apiName', null); |
@@ -167,15 +165,13 @@ discard block |
||
| 167 | 165 | Logger::requestQueueEdited($database, $queue); |
| 168 | 166 | $queue->save(); |
| 169 | 167 | $this->redirect('queueManagement'); |
| 170 | - } |
|
| 171 | - else { |
|
| 168 | + } else { |
|
| 172 | 169 | $this->populateFromObject($queue); |
| 173 | 170 | |
| 174 | 171 | $this->assign('createMode', false); |
| 175 | 172 | $this->setTemplate('queue-management/edit.tpl'); |
| 176 | 173 | } |
| 177 | - } |
|
| 178 | - else { |
|
| 174 | + } else { |
|
| 179 | 175 | $this->populateFromObject($queue); |
| 180 | 176 | |
| 181 | 177 | $this->assign('createMode', false); |
@@ -13,19 +13,19 @@ |
||
| 13 | 13 | |
| 14 | 14 | class PageRegisterOption extends InternalPageBase |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Main function for this page, when no specific actions are called. |
|
| 18 | - * @return void |
|
| 19 | - */ |
|
| 20 | - protected function main() |
|
| 21 | - { |
|
| 22 | - $this->assign('allowRegistration', $this->getSiteConfiguration()->isRegistrationAllowed()); |
|
| 23 | - $this->assign('domains', Domain::getAll($this->getDatabase())); |
|
| 24 | - $this->setTemplate('registration/option.tpl'); |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * Main function for this page, when no specific actions are called. |
|
| 18 | + * @return void |
|
| 19 | + */ |
|
| 20 | + protected function main() |
|
| 21 | + { |
|
| 22 | + $this->assign('allowRegistration', $this->getSiteConfiguration()->isRegistrationAllowed()); |
|
| 23 | + $this->assign('domains', Domain::getAll($this->getDatabase())); |
|
| 24 | + $this->setTemplate('registration/option.tpl'); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - protected function isProtectedPage() |
|
| 28 | - { |
|
| 29 | - return false; |
|
| 30 | - } |
|
| 27 | + protected function isProtectedPage() |
|
| 28 | + { |
|
| 29 | + return false; |
|
| 30 | + } |
|
| 31 | 31 | } |
@@ -24,255 +24,255 @@ |
||
| 24 | 24 | |
| 25 | 25 | abstract class PageRegisterBase extends InternalPageBase |
| 26 | 26 | { |
| 27 | - /** |
|
| 28 | - * Main function for this page, when no specific actions are called. |
|
| 29 | - * @throws AccessDeniedException |
|
| 30 | - * @throws ApplicationLogicException |
|
| 31 | - * @throws Exception |
|
| 32 | - */ |
|
| 33 | - protected function main() |
|
| 34 | - { |
|
| 35 | - $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup(); |
|
| 36 | - if (!$this->getSiteConfiguration()->isRegistrationAllowed()) { |
|
| 37 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - // Dual-mode page |
|
| 41 | - if (WebRequest::wasPosted()) { |
|
| 42 | - $this->validateCSRFToken(); |
|
| 43 | - |
|
| 44 | - try { |
|
| 45 | - $this->handlePost($useOAuthSignup); |
|
| 46 | - } |
|
| 47 | - catch (ApplicationLogicException $ex) { |
|
| 48 | - SessionAlert::error($ex->getMessage()); |
|
| 49 | - |
|
| 50 | - $this->getDatabase()->rollBack(); |
|
| 51 | - |
|
| 52 | - $this->assignCSRFToken(); |
|
| 53 | - $this->assign("useOAuthSignup", $useOAuthSignup); |
|
| 54 | - $this->applyErrorValues(); |
|
| 55 | - $this->setTemplate($this->getRegistrationTemplate()); |
|
| 56 | - $this->addJs("/vendor/dropbox/zxcvbn/dist/zxcvbn.js"); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - else { |
|
| 60 | - $domain = WebRequest::getString('d'); |
|
| 61 | - if ($domain === null) { |
|
| 62 | - throw new ApplicationLogicException("No domain specified."); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** @var Domain|false $domainObject */ |
|
| 66 | - $domainObject = Domain::getByShortName($domain, $this->getDatabase()); |
|
| 67 | - if ($domainObject === false || !$domainObject->isEnabled()) { |
|
| 68 | - throw new ApplicationLogicException("Unknown domain or domain not enabled."); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $this->assign('localDocumentation', $domainObject->getLocalDocumentation()); |
|
| 72 | - |
|
| 73 | - $this->assignCSRFToken(); |
|
| 74 | - $this->assign("useOAuthSignup", $useOAuthSignup); |
|
| 75 | - $this->setTemplate($this->getRegistrationTemplate()); |
|
| 76 | - $this->addJs("/vendor/dropbox/zxcvbn/dist/zxcvbn.js"); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - protected abstract function getRegistrationTemplate(); |
|
| 81 | - |
|
| 82 | - protected function isProtectedPage() |
|
| 83 | - { |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param string $emailAddress |
|
| 89 | - * |
|
| 90 | - * @throws ApplicationLogicException |
|
| 91 | - */ |
|
| 92 | - protected function validateUniqueEmail($emailAddress) |
|
| 93 | - { |
|
| 94 | - $query = 'SELECT COUNT(id) FROM user WHERE email = :email'; |
|
| 95 | - $statement = $this->getDatabase()->prepare($query); |
|
| 96 | - $statement->execute(array(':email' => $emailAddress)); |
|
| 97 | - |
|
| 98 | - if ($statement->fetchColumn() > 0) { |
|
| 99 | - throw new ApplicationLogicException('That email address is already in use on this system.'); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $statement->closeCursor(); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @param $emailAddress |
|
| 107 | - * @param $password |
|
| 108 | - * @param $username |
|
| 109 | - * @param $useOAuthSignup |
|
| 110 | - * @param $confirmationId |
|
| 111 | - * @param $onwikiUsername |
|
| 112 | - * @param Domain|false $domainObject |
|
| 113 | - * |
|
| 114 | - * @throws ApplicationLogicException |
|
| 115 | - */ |
|
| 116 | - protected function validateRequest( |
|
| 117 | - $emailAddress, |
|
| 118 | - $password, |
|
| 119 | - $username, |
|
| 120 | - $useOAuthSignup, |
|
| 121 | - $confirmationId, |
|
| 122 | - $onwikiUsername, |
|
| 123 | - $domainObject |
|
| 124 | - ) { |
|
| 125 | - if (!WebRequest::postBoolean('guidelines')) { |
|
| 126 | - throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.'); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - if ($domainObject === false) { |
|
| 130 | - throw new ApplicationLogicException('The chosen wiki does not exist on this tool.'); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - if (!$domainObject->isEnabled()) { |
|
| 134 | - throw new ApplicationLogicException('The chosen wiki is not currently enabled on this tool.'); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $this->validateGeneralInformation($emailAddress, $password, $username); |
|
| 138 | - $this->validateUniqueEmail($emailAddress); |
|
| 139 | - $this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param $useOAuthSignup |
|
| 144 | - * @param $confirmationId |
|
| 145 | - * @param $onwikiUsername |
|
| 146 | - * |
|
| 147 | - * @throws ApplicationLogicException |
|
| 148 | - */ |
|
| 149 | - protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername) |
|
| 150 | - { |
|
| 151 | - if (!$useOAuthSignup) { |
|
| 152 | - if ($confirmationId === null || $confirmationId <= 0) { |
|
| 153 | - throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - if ($onwikiUsername === null) { |
|
| 157 | - throw new ApplicationLogicException('Please specify your on-wiki username.'); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @param $emailAddress |
|
| 164 | - * @param $password |
|
| 165 | - * @param $username |
|
| 166 | - * |
|
| 167 | - * @throws ApplicationLogicException |
|
| 168 | - */ |
|
| 169 | - protected function validateGeneralInformation($emailAddress, $password, $username) |
|
| 170 | - { |
|
| 171 | - if ($emailAddress === null) { |
|
| 172 | - throw new ApplicationLogicException('Your email address appears to be invalid!'); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if ($password !== WebRequest::postString('newpasswordconfirm')) { |
|
| 176 | - throw new ApplicationLogicException('Your passwords did not match, please try again.'); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - if (User::getByUsername($username, $this->getDatabase()) !== false) { |
|
| 180 | - throw new ApplicationLogicException('That username is already in use on this system.'); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @param $useOAuthSignup |
|
| 186 | - * |
|
| 187 | - * @throws ApplicationLogicException |
|
| 188 | - * @throws Exception |
|
| 189 | - */ |
|
| 190 | - protected function handlePost($useOAuthSignup) |
|
| 191 | - { |
|
| 192 | - // Get the data |
|
| 193 | - $emailAddress = WebRequest::postEmail('email'); |
|
| 194 | - $password = WebRequest::postString('newpassword'); |
|
| 195 | - $username = WebRequest::postString('name'); |
|
| 196 | - |
|
| 197 | - // Only set if OAuth is disabled |
|
| 198 | - $confirmationId = WebRequest::postInt('conf_revid'); |
|
| 199 | - $onwikiUsername = WebRequest::postString('wname'); |
|
| 200 | - |
|
| 201 | - $database = $this->getDatabase(); |
|
| 202 | - $domain = WebRequest::getString('d'); |
|
| 203 | - $domainObject = Domain::getByShortName($domain, $database); |
|
| 204 | - |
|
| 205 | - // Do some validation |
|
| 206 | - $this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId, |
|
| 207 | - $onwikiUsername, $domainObject); |
|
| 208 | - |
|
| 209 | - $user = new User(); |
|
| 210 | - $user->setDatabase($database); |
|
| 211 | - |
|
| 212 | - $user->setUsername($username); |
|
| 213 | - $user->setEmail($emailAddress); |
|
| 214 | - |
|
| 215 | - if (!$useOAuthSignup) { |
|
| 216 | - $user->setOnWikiName($onwikiUsername); |
|
| 217 | - $user->setConfirmationDiff($confirmationId); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - $user->save(); |
|
| 221 | - |
|
| 222 | - $passwordCredentialProvider = new PasswordCredentialProvider($database, $this->getSiteConfiguration()); |
|
| 223 | - $passwordCredentialProvider->setCredential($user, 1, $password); |
|
| 224 | - |
|
| 225 | - $defaultRole = $this->getDefaultRole(); |
|
| 226 | - |
|
| 227 | - $role = new UserRole(); |
|
| 228 | - $role->setDatabase($database); |
|
| 229 | - $role->setUser($user->getId()); |
|
| 230 | - $role->setRole($defaultRole); |
|
| 231 | - $role->setDomain($domainObject->getId()); // FIXME: domains |
|
| 232 | - $role->save(); |
|
| 233 | - |
|
| 234 | - // Log now to get the signup date. |
|
| 235 | - Logger::newUser($database, $user); |
|
| 236 | - Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array(), $domainObject->getId()); |
|
| 237 | - |
|
| 238 | - $userDomain = new UserDomain(); |
|
| 239 | - $userDomain->setDatabase($database); |
|
| 240 | - $userDomain->setUser($user->getId()); |
|
| 241 | - $userDomain->setDomain($domainObject->getId()); |
|
| 242 | - $userDomain->save(); |
|
| 243 | - |
|
| 244 | - if ($useOAuthSignup) { |
|
| 245 | - $oauthProtocolHelper = $this->getOAuthProtocolHelper(); |
|
| 246 | - $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration()); |
|
| 247 | - |
|
| 248 | - $authoriseUrl = $oauth->getRequestToken(); |
|
| 249 | - WebRequest::setOAuthPartialLogin($user); |
|
| 250 | - $this->redirectUrl($authoriseUrl); |
|
| 251 | - } |
|
| 252 | - else { |
|
| 253 | - // only notify if we're not using the oauth signup. |
|
| 254 | - $this->getNotificationHelper()->userNew($user); |
|
| 255 | - WebRequest::setLoggedInUser($user); |
|
| 256 | - $this->getDomainAccessManager()->switchToDefaultDomain($user); |
|
| 257 | - $this->redirect('preferences'); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - protected abstract function getDefaultRole(); |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Entry point for registration complete |
|
| 265 | - * @throws Exception |
|
| 266 | - */ |
|
| 267 | - protected function done() |
|
| 268 | - { |
|
| 269 | - $this->setTemplate('registration/alert-registrationcomplete.tpl'); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - protected function applyErrorValues() |
|
| 273 | - { |
|
| 274 | - $this->assign('tplUsername', WebRequest::postString('name')); |
|
| 275 | - $this->assign('tplEmail', WebRequest::postString('email')); |
|
| 276 | - $this->assign('tplWikipediaUsername', WebRequest::postString('wname')); |
|
| 277 | - $this->assign('tplConfRevId', WebRequest::postInt('conf_revid')); |
|
| 278 | - }} |
|
| 27 | + /** |
|
| 28 | + * Main function for this page, when no specific actions are called. |
|
| 29 | + * @throws AccessDeniedException |
|
| 30 | + * @throws ApplicationLogicException |
|
| 31 | + * @throws Exception |
|
| 32 | + */ |
|
| 33 | + protected function main() |
|
| 34 | + { |
|
| 35 | + $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup(); |
|
| 36 | + if (!$this->getSiteConfiguration()->isRegistrationAllowed()) { |
|
| 37 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + // Dual-mode page |
|
| 41 | + if (WebRequest::wasPosted()) { |
|
| 42 | + $this->validateCSRFToken(); |
|
| 43 | + |
|
| 44 | + try { |
|
| 45 | + $this->handlePost($useOAuthSignup); |
|
| 46 | + } |
|
| 47 | + catch (ApplicationLogicException $ex) { |
|
| 48 | + SessionAlert::error($ex->getMessage()); |
|
| 49 | + |
|
| 50 | + $this->getDatabase()->rollBack(); |
|
| 51 | + |
|
| 52 | + $this->assignCSRFToken(); |
|
| 53 | + $this->assign("useOAuthSignup", $useOAuthSignup); |
|
| 54 | + $this->applyErrorValues(); |
|
| 55 | + $this->setTemplate($this->getRegistrationTemplate()); |
|
| 56 | + $this->addJs("/vendor/dropbox/zxcvbn/dist/zxcvbn.js"); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + else { |
|
| 60 | + $domain = WebRequest::getString('d'); |
|
| 61 | + if ($domain === null) { |
|
| 62 | + throw new ApplicationLogicException("No domain specified."); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** @var Domain|false $domainObject */ |
|
| 66 | + $domainObject = Domain::getByShortName($domain, $this->getDatabase()); |
|
| 67 | + if ($domainObject === false || !$domainObject->isEnabled()) { |
|
| 68 | + throw new ApplicationLogicException("Unknown domain or domain not enabled."); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $this->assign('localDocumentation', $domainObject->getLocalDocumentation()); |
|
| 72 | + |
|
| 73 | + $this->assignCSRFToken(); |
|
| 74 | + $this->assign("useOAuthSignup", $useOAuthSignup); |
|
| 75 | + $this->setTemplate($this->getRegistrationTemplate()); |
|
| 76 | + $this->addJs("/vendor/dropbox/zxcvbn/dist/zxcvbn.js"); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + protected abstract function getRegistrationTemplate(); |
|
| 81 | + |
|
| 82 | + protected function isProtectedPage() |
|
| 83 | + { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param string $emailAddress |
|
| 89 | + * |
|
| 90 | + * @throws ApplicationLogicException |
|
| 91 | + */ |
|
| 92 | + protected function validateUniqueEmail($emailAddress) |
|
| 93 | + { |
|
| 94 | + $query = 'SELECT COUNT(id) FROM user WHERE email = :email'; |
|
| 95 | + $statement = $this->getDatabase()->prepare($query); |
|
| 96 | + $statement->execute(array(':email' => $emailAddress)); |
|
| 97 | + |
|
| 98 | + if ($statement->fetchColumn() > 0) { |
|
| 99 | + throw new ApplicationLogicException('That email address is already in use on this system.'); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $statement->closeCursor(); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @param $emailAddress |
|
| 107 | + * @param $password |
|
| 108 | + * @param $username |
|
| 109 | + * @param $useOAuthSignup |
|
| 110 | + * @param $confirmationId |
|
| 111 | + * @param $onwikiUsername |
|
| 112 | + * @param Domain|false $domainObject |
|
| 113 | + * |
|
| 114 | + * @throws ApplicationLogicException |
|
| 115 | + */ |
|
| 116 | + protected function validateRequest( |
|
| 117 | + $emailAddress, |
|
| 118 | + $password, |
|
| 119 | + $username, |
|
| 120 | + $useOAuthSignup, |
|
| 121 | + $confirmationId, |
|
| 122 | + $onwikiUsername, |
|
| 123 | + $domainObject |
|
| 124 | + ) { |
|
| 125 | + if (!WebRequest::postBoolean('guidelines')) { |
|
| 126 | + throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.'); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + if ($domainObject === false) { |
|
| 130 | + throw new ApplicationLogicException('The chosen wiki does not exist on this tool.'); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + if (!$domainObject->isEnabled()) { |
|
| 134 | + throw new ApplicationLogicException('The chosen wiki is not currently enabled on this tool.'); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $this->validateGeneralInformation($emailAddress, $password, $username); |
|
| 138 | + $this->validateUniqueEmail($emailAddress); |
|
| 139 | + $this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param $useOAuthSignup |
|
| 144 | + * @param $confirmationId |
|
| 145 | + * @param $onwikiUsername |
|
| 146 | + * |
|
| 147 | + * @throws ApplicationLogicException |
|
| 148 | + */ |
|
| 149 | + protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername) |
|
| 150 | + { |
|
| 151 | + if (!$useOAuthSignup) { |
|
| 152 | + if ($confirmationId === null || $confirmationId <= 0) { |
|
| 153 | + throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + if ($onwikiUsername === null) { |
|
| 157 | + throw new ApplicationLogicException('Please specify your on-wiki username.'); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @param $emailAddress |
|
| 164 | + * @param $password |
|
| 165 | + * @param $username |
|
| 166 | + * |
|
| 167 | + * @throws ApplicationLogicException |
|
| 168 | + */ |
|
| 169 | + protected function validateGeneralInformation($emailAddress, $password, $username) |
|
| 170 | + { |
|
| 171 | + if ($emailAddress === null) { |
|
| 172 | + throw new ApplicationLogicException('Your email address appears to be invalid!'); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if ($password !== WebRequest::postString('newpasswordconfirm')) { |
|
| 176 | + throw new ApplicationLogicException('Your passwords did not match, please try again.'); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + if (User::getByUsername($username, $this->getDatabase()) !== false) { |
|
| 180 | + throw new ApplicationLogicException('That username is already in use on this system.'); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @param $useOAuthSignup |
|
| 186 | + * |
|
| 187 | + * @throws ApplicationLogicException |
|
| 188 | + * @throws Exception |
|
| 189 | + */ |
|
| 190 | + protected function handlePost($useOAuthSignup) |
|
| 191 | + { |
|
| 192 | + // Get the data |
|
| 193 | + $emailAddress = WebRequest::postEmail('email'); |
|
| 194 | + $password = WebRequest::postString('newpassword'); |
|
| 195 | + $username = WebRequest::postString('name'); |
|
| 196 | + |
|
| 197 | + // Only set if OAuth is disabled |
|
| 198 | + $confirmationId = WebRequest::postInt('conf_revid'); |
|
| 199 | + $onwikiUsername = WebRequest::postString('wname'); |
|
| 200 | + |
|
| 201 | + $database = $this->getDatabase(); |
|
| 202 | + $domain = WebRequest::getString('d'); |
|
| 203 | + $domainObject = Domain::getByShortName($domain, $database); |
|
| 204 | + |
|
| 205 | + // Do some validation |
|
| 206 | + $this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId, |
|
| 207 | + $onwikiUsername, $domainObject); |
|
| 208 | + |
|
| 209 | + $user = new User(); |
|
| 210 | + $user->setDatabase($database); |
|
| 211 | + |
|
| 212 | + $user->setUsername($username); |
|
| 213 | + $user->setEmail($emailAddress); |
|
| 214 | + |
|
| 215 | + if (!$useOAuthSignup) { |
|
| 216 | + $user->setOnWikiName($onwikiUsername); |
|
| 217 | + $user->setConfirmationDiff($confirmationId); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + $user->save(); |
|
| 221 | + |
|
| 222 | + $passwordCredentialProvider = new PasswordCredentialProvider($database, $this->getSiteConfiguration()); |
|
| 223 | + $passwordCredentialProvider->setCredential($user, 1, $password); |
|
| 224 | + |
|
| 225 | + $defaultRole = $this->getDefaultRole(); |
|
| 226 | + |
|
| 227 | + $role = new UserRole(); |
|
| 228 | + $role->setDatabase($database); |
|
| 229 | + $role->setUser($user->getId()); |
|
| 230 | + $role->setRole($defaultRole); |
|
| 231 | + $role->setDomain($domainObject->getId()); // FIXME: domains |
|
| 232 | + $role->save(); |
|
| 233 | + |
|
| 234 | + // Log now to get the signup date. |
|
| 235 | + Logger::newUser($database, $user); |
|
| 236 | + Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array(), $domainObject->getId()); |
|
| 237 | + |
|
| 238 | + $userDomain = new UserDomain(); |
|
| 239 | + $userDomain->setDatabase($database); |
|
| 240 | + $userDomain->setUser($user->getId()); |
|
| 241 | + $userDomain->setDomain($domainObject->getId()); |
|
| 242 | + $userDomain->save(); |
|
| 243 | + |
|
| 244 | + if ($useOAuthSignup) { |
|
| 245 | + $oauthProtocolHelper = $this->getOAuthProtocolHelper(); |
|
| 246 | + $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration()); |
|
| 247 | + |
|
| 248 | + $authoriseUrl = $oauth->getRequestToken(); |
|
| 249 | + WebRequest::setOAuthPartialLogin($user); |
|
| 250 | + $this->redirectUrl($authoriseUrl); |
|
| 251 | + } |
|
| 252 | + else { |
|
| 253 | + // only notify if we're not using the oauth signup. |
|
| 254 | + $this->getNotificationHelper()->userNew($user); |
|
| 255 | + WebRequest::setLoggedInUser($user); |
|
| 256 | + $this->getDomainAccessManager()->switchToDefaultDomain($user); |
|
| 257 | + $this->redirect('preferences'); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + protected abstract function getDefaultRole(); |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Entry point for registration complete |
|
| 265 | + * @throws Exception |
|
| 266 | + */ |
|
| 267 | + protected function done() |
|
| 268 | + { |
|
| 269 | + $this->setTemplate('registration/alert-registrationcomplete.tpl'); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + protected function applyErrorValues() |
|
| 273 | + { |
|
| 274 | + $this->assign('tplUsername', WebRequest::postString('name')); |
|
| 275 | + $this->assign('tplEmail', WebRequest::postString('email')); |
|
| 276 | + $this->assign('tplWikipediaUsername', WebRequest::postString('wname')); |
|
| 277 | + $this->assign('tplConfRevId', WebRequest::postInt('conf_revid')); |
|
| 278 | + }} |
|
@@ -55,8 +55,7 @@ discard block |
||
| 55 | 55 | $this->setTemplate($this->getRegistrationTemplate()); |
| 56 | 56 | $this->addJs("/vendor/dropbox/zxcvbn/dist/zxcvbn.js"); |
| 57 | 57 | } |
| 58 | - } |
|
| 59 | - else { |
|
| 58 | + } else { |
|
| 60 | 59 | $domain = WebRequest::getString('d'); |
| 61 | 60 | if ($domain === null) { |
| 62 | 61 | throw new ApplicationLogicException("No domain specified."); |
@@ -248,8 +247,7 @@ discard block |
||
| 248 | 247 | $authoriseUrl = $oauth->getRequestToken(); |
| 249 | 248 | WebRequest::setOAuthPartialLogin($user); |
| 250 | 249 | $this->redirectUrl($authoriseUrl); |
| 251 | - } |
|
| 252 | - else { |
|
| 250 | + } else { |
|
| 253 | 251 | // only notify if we're not using the oauth signup. |
| 254 | 252 | $this->getNotificationHelper()->userNew($user); |
| 255 | 253 | WebRequest::setLoggedInUser($user); |
@@ -12,17 +12,17 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PageRequestSubmitted extends PublicInterfacePageBase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Main function for this page, when no specific actions are called. |
|
| 17 | - * @return void |
|
| 18 | - */ |
|
| 19 | - protected function main() |
|
| 20 | - { |
|
| 21 | - // clear any requests for client hints. Should have been done already prior to |
|
| 22 | - // email confirmation, but this catches the case where email confirmation is |
|
| 23 | - // disabled. |
|
| 24 | - $this->headerQueue[] = "Accept-CH:"; |
|
| 15 | + /** |
|
| 16 | + * Main function for this page, when no specific actions are called. |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 19 | + protected function main() |
|
| 20 | + { |
|
| 21 | + // clear any requests for client hints. Should have been done already prior to |
|
| 22 | + // email confirmation, but this catches the case where email confirmation is |
|
| 23 | + // disabled. |
|
| 24 | + $this->headerQueue[] = "Accept-CH:"; |
|
| 25 | 25 | |
| 26 | - $this->setTemplate('request/email-confirmed.tpl'); |
|
| 27 | - } |
|
| 26 | + $this->setTemplate('request/email-confirmed.tpl'); |
|
| 27 | + } |
|
| 28 | 28 | } |
| 29 | 29 | \ No newline at end of file |
@@ -27,316 +27,316 @@ |
||
| 27 | 27 | |
| 28 | 28 | class PageRequestAccount extends PublicInterfacePageBase |
| 29 | 29 | { |
| 30 | - /** @var RequestValidationHelper do not use directly. */ |
|
| 31 | - private $validationHelper; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Main function for this page, when no specific actions are called. |
|
| 35 | - * @return void |
|
| 36 | - * @throws OptimisticLockFailedException |
|
| 37 | - * @throws Exception |
|
| 38 | - */ |
|
| 39 | - protected function main() |
|
| 40 | - { |
|
| 41 | - // dual mode page |
|
| 42 | - if (WebRequest::wasPosted()) { |
|
| 43 | - $request = $this->createNewRequest(null); |
|
| 44 | - $this->handleFormPost($request); |
|
| 45 | - } |
|
| 46 | - else { |
|
| 47 | - $this->requestClientHints(); |
|
| 48 | - $this->handleFormRefilling(); |
|
| 49 | - |
|
| 50 | - $this->setTemplate('request/request-form.tpl'); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Handles dynamic request forms. |
|
| 56 | - * @return void |
|
| 57 | - * @throws OptimisticLockFailedException |
|
| 58 | - * @throws Exception |
|
| 59 | - */ |
|
| 60 | - protected function dynamic() |
|
| 61 | - { |
|
| 62 | - $database = $this->getDatabase(); |
|
| 63 | - |
|
| 64 | - $pathInfo = WebRequest::pathInfo(); |
|
| 65 | - $domain = Domain::getByShortName($pathInfo[1], $database); |
|
| 66 | - if ($domain === false || !$domain->isEnabled()) { |
|
| 67 | - throw new ApplicationLogicException("This form is not available at this time."); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $form = RequestForm::getByPublicEndpoint($database, $pathInfo[2], $domain->getId()); |
|
| 71 | - |
|
| 72 | - if ($form === false || !$form->isEnabled()) { |
|
| 73 | - throw new ApplicationLogicException("This form is not available at this time."); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // dual mode page |
|
| 77 | - if (WebRequest::wasPosted()) { |
|
| 78 | - $request = $this->createNewRequest($form); |
|
| 79 | - $this->handleFormPost($request); |
|
| 80 | - } |
|
| 81 | - else { |
|
| 82 | - $this->requestClientHints(); |
|
| 83 | - $this->handleFormRefilling(); |
|
| 84 | - |
|
| 85 | - $renderer = new MarkdownRenderingHelper(); |
|
| 86 | - $this->assign('formPreamble', $renderer->doRender($form->getFormContent())); |
|
| 87 | - $this->assign('formUsernameHelp', $renderer->doRenderInline($form->getUsernameHelp())); |
|
| 88 | - $this->assign('formEmailHelp', $renderer->doRenderInline($form->getEmailHelp())); |
|
| 89 | - $this->assign('formCommentsHelp', $renderer->doRenderInline($form->getCommentHelp())); |
|
| 90 | - |
|
| 91 | - $this->setTemplate('request/request-form-dynamic.tpl'); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @param RequestForm|null $form |
|
| 97 | - * |
|
| 98 | - * @return Request |
|
| 99 | - * @throws ApplicationLogicException |
|
| 100 | - */ |
|
| 101 | - protected function createNewRequest(?RequestForm $form): Request |
|
| 102 | - { |
|
| 103 | - $database = $this->getDatabase(); |
|
| 104 | - |
|
| 105 | - $request = new Request(); |
|
| 106 | - |
|
| 107 | - if ($form === null) { |
|
| 108 | - $domain = 1; |
|
| 109 | - } |
|
| 110 | - else { |
|
| 111 | - $domain = $form->getDomain(); |
|
| 112 | - $request->setOriginForm($form->getId()); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $request->setQueue(RequestQueue::getDefaultQueue($database, $domain)->getId()); |
|
| 116 | - $request->setDatabase($database); |
|
| 117 | - $request->setDomain($domain); |
|
| 118 | - |
|
| 119 | - $request->setName(trim(WebRequest::postString('name'))); |
|
| 120 | - $request->setEmail(WebRequest::postEmail('email')); |
|
| 121 | - |
|
| 122 | - $request->setIp(WebRequest::remoteAddress()); |
|
| 123 | - $request->setForwardedIp(WebRequest::forwardedAddress()); |
|
| 124 | - |
|
| 125 | - $request->setUserAgent(WebRequest::userAgent()); |
|
| 126 | - |
|
| 127 | - return $request; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return Comment|null |
|
| 132 | - */ |
|
| 133 | - private function createComment() |
|
| 134 | - { |
|
| 135 | - $commentText = WebRequest::postString('comments'); |
|
| 136 | - if ($commentText === null || trim($commentText) === '') { |
|
| 137 | - return null; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - $comment = new Comment(); |
|
| 141 | - $comment->setDatabase($this->getDatabase()); |
|
| 142 | - |
|
| 143 | - $comment->setVisibility('requester'); |
|
| 144 | - $comment->setUser(null); |
|
| 145 | - $comment->setComment($commentText); |
|
| 146 | - |
|
| 147 | - return $comment; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @param Request $request |
|
| 152 | - * |
|
| 153 | - * @return ValidationError[] |
|
| 154 | - */ |
|
| 155 | - protected function validateRequest($request) |
|
| 156 | - { |
|
| 157 | - $validationHelper = $this->getRequestValidationHelper(); |
|
| 158 | - |
|
| 159 | - // These are arrays of ValidationError. |
|
| 160 | - $nameValidation = $validationHelper->validateName($request); |
|
| 161 | - $emailValidation = $validationHelper->validateEmail($request, WebRequest::postEmail('emailconfirm')); |
|
| 162 | - $otherValidation = $validationHelper->validateOther($request); |
|
| 163 | - |
|
| 164 | - $validationErrors = array_merge($nameValidation, $emailValidation, $otherValidation); |
|
| 165 | - |
|
| 166 | - return $validationErrors; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param Request $request |
|
| 171 | - * |
|
| 172 | - * @param Comment|null $comment |
|
| 173 | - * |
|
| 174 | - * @throws OptimisticLockFailedException |
|
| 175 | - * @throws Exception |
|
| 176 | - */ |
|
| 177 | - protected function saveAsEmailConfirmation(Request $request, $comment) |
|
| 178 | - { |
|
| 179 | - $request->generateEmailConfirmationHash(); |
|
| 180 | - $request->save(); |
|
| 181 | - |
|
| 182 | - if ($comment !== null) { |
|
| 183 | - $comment->setRequest($request->getId()); |
|
| 184 | - $comment->save(); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
| 188 | - $request->getIp(), |
|
| 189 | - $request->getForwardedIp()); |
|
| 190 | - |
|
| 191 | - $this->assign("ip", $trustedIp); |
|
| 192 | - $this->assign("id", $request->getId()); |
|
| 193 | - $this->assign("hash", $request->getEmailConfirm()); |
|
| 194 | - |
|
| 195 | - // Sends the confirmation email to the user. |
|
| 196 | - // FIXME: domains |
|
| 197 | - /** @var Domain $domain */ |
|
| 198 | - $domain = Domain::getById(1, $this->getDatabase()); |
|
| 199 | - $this->getEmailHelper()->sendMail( |
|
| 200 | - $domain->getEmailReplyAddress(), |
|
| 201 | - $request->getEmail(), |
|
| 202 | - "[ACC #{$request->getId()}] English Wikipedia Account Request", |
|
| 203 | - $this->fetchTemplate('request/confirmation-mail.tpl')); |
|
| 204 | - |
|
| 205 | - $this->redirect('emailConfirmationRequired'); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param Request $request |
|
| 210 | - * |
|
| 211 | - * @param Comment|null $comment |
|
| 212 | - * |
|
| 213 | - * @throws OptimisticLockFailedException |
|
| 214 | - * @throws Exception |
|
| 215 | - */ |
|
| 216 | - protected function saveWithoutEmailConfirmation(Request $request, $comment) |
|
| 217 | - { |
|
| 218 | - $request->setEmailConfirm(0); // fixme Since it can't be null |
|
| 219 | - $request->save(); |
|
| 220 | - |
|
| 221 | - if ($comment !== null) { |
|
| 222 | - $comment->setRequest($request->getId()); |
|
| 223 | - $comment->save(); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $this->getNotificationHelper()->requestReceived($request); |
|
| 227 | - |
|
| 228 | - $this->redirect('requestSubmitted'); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * @return RequestValidationHelper |
|
| 233 | - */ |
|
| 234 | - protected function getRequestValidationHelper(): RequestValidationHelper |
|
| 235 | - { |
|
| 236 | - $banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), null); |
|
| 237 | - |
|
| 238 | - if ($this->validationHelper === null) { |
|
| 239 | - $this->validationHelper = new RequestValidationHelper( |
|
| 240 | - $banHelper, |
|
| 241 | - $this->getDatabase(), |
|
| 242 | - $this->getAntiSpoofProvider(), |
|
| 243 | - $this->getXffTrustProvider(), |
|
| 244 | - $this->getHttpHelper(), |
|
| 245 | - $this->getTorExitProvider(), |
|
| 246 | - $this->getSiteConfiguration()); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - return $this->validationHelper; |
|
| 30 | + /** @var RequestValidationHelper do not use directly. */ |
|
| 31 | + private $validationHelper; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Main function for this page, when no specific actions are called. |
|
| 35 | + * @return void |
|
| 36 | + * @throws OptimisticLockFailedException |
|
| 37 | + * @throws Exception |
|
| 38 | + */ |
|
| 39 | + protected function main() |
|
| 40 | + { |
|
| 41 | + // dual mode page |
|
| 42 | + if (WebRequest::wasPosted()) { |
|
| 43 | + $request = $this->createNewRequest(null); |
|
| 44 | + $this->handleFormPost($request); |
|
| 45 | + } |
|
| 46 | + else { |
|
| 47 | + $this->requestClientHints(); |
|
| 48 | + $this->handleFormRefilling(); |
|
| 49 | + |
|
| 50 | + $this->setTemplate('request/request-form.tpl'); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Handles dynamic request forms. |
|
| 56 | + * @return void |
|
| 57 | + * @throws OptimisticLockFailedException |
|
| 58 | + * @throws Exception |
|
| 59 | + */ |
|
| 60 | + protected function dynamic() |
|
| 61 | + { |
|
| 62 | + $database = $this->getDatabase(); |
|
| 63 | + |
|
| 64 | + $pathInfo = WebRequest::pathInfo(); |
|
| 65 | + $domain = Domain::getByShortName($pathInfo[1], $database); |
|
| 66 | + if ($domain === false || !$domain->isEnabled()) { |
|
| 67 | + throw new ApplicationLogicException("This form is not available at this time."); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $form = RequestForm::getByPublicEndpoint($database, $pathInfo[2], $domain->getId()); |
|
| 71 | + |
|
| 72 | + if ($form === false || !$form->isEnabled()) { |
|
| 73 | + throw new ApplicationLogicException("This form is not available at this time."); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // dual mode page |
|
| 77 | + if (WebRequest::wasPosted()) { |
|
| 78 | + $request = $this->createNewRequest($form); |
|
| 79 | + $this->handleFormPost($request); |
|
| 80 | + } |
|
| 81 | + else { |
|
| 82 | + $this->requestClientHints(); |
|
| 83 | + $this->handleFormRefilling(); |
|
| 84 | + |
|
| 85 | + $renderer = new MarkdownRenderingHelper(); |
|
| 86 | + $this->assign('formPreamble', $renderer->doRender($form->getFormContent())); |
|
| 87 | + $this->assign('formUsernameHelp', $renderer->doRenderInline($form->getUsernameHelp())); |
|
| 88 | + $this->assign('formEmailHelp', $renderer->doRenderInline($form->getEmailHelp())); |
|
| 89 | + $this->assign('formCommentsHelp', $renderer->doRenderInline($form->getCommentHelp())); |
|
| 90 | + |
|
| 91 | + $this->setTemplate('request/request-form-dynamic.tpl'); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @param RequestForm|null $form |
|
| 97 | + * |
|
| 98 | + * @return Request |
|
| 99 | + * @throws ApplicationLogicException |
|
| 100 | + */ |
|
| 101 | + protected function createNewRequest(?RequestForm $form): Request |
|
| 102 | + { |
|
| 103 | + $database = $this->getDatabase(); |
|
| 104 | + |
|
| 105 | + $request = new Request(); |
|
| 106 | + |
|
| 107 | + if ($form === null) { |
|
| 108 | + $domain = 1; |
|
| 109 | + } |
|
| 110 | + else { |
|
| 111 | + $domain = $form->getDomain(); |
|
| 112 | + $request->setOriginForm($form->getId()); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $request->setQueue(RequestQueue::getDefaultQueue($database, $domain)->getId()); |
|
| 116 | + $request->setDatabase($database); |
|
| 117 | + $request->setDomain($domain); |
|
| 118 | + |
|
| 119 | + $request->setName(trim(WebRequest::postString('name'))); |
|
| 120 | + $request->setEmail(WebRequest::postEmail('email')); |
|
| 121 | + |
|
| 122 | + $request->setIp(WebRequest::remoteAddress()); |
|
| 123 | + $request->setForwardedIp(WebRequest::forwardedAddress()); |
|
| 124 | + |
|
| 125 | + $request->setUserAgent(WebRequest::userAgent()); |
|
| 126 | + |
|
| 127 | + return $request; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return Comment|null |
|
| 132 | + */ |
|
| 133 | + private function createComment() |
|
| 134 | + { |
|
| 135 | + $commentText = WebRequest::postString('comments'); |
|
| 136 | + if ($commentText === null || trim($commentText) === '') { |
|
| 137 | + return null; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + $comment = new Comment(); |
|
| 141 | + $comment->setDatabase($this->getDatabase()); |
|
| 142 | + |
|
| 143 | + $comment->setVisibility('requester'); |
|
| 144 | + $comment->setUser(null); |
|
| 145 | + $comment->setComment($commentText); |
|
| 146 | + |
|
| 147 | + return $comment; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @param Request $request |
|
| 152 | + * |
|
| 153 | + * @return ValidationError[] |
|
| 154 | + */ |
|
| 155 | + protected function validateRequest($request) |
|
| 156 | + { |
|
| 157 | + $validationHelper = $this->getRequestValidationHelper(); |
|
| 158 | + |
|
| 159 | + // These are arrays of ValidationError. |
|
| 160 | + $nameValidation = $validationHelper->validateName($request); |
|
| 161 | + $emailValidation = $validationHelper->validateEmail($request, WebRequest::postEmail('emailconfirm')); |
|
| 162 | + $otherValidation = $validationHelper->validateOther($request); |
|
| 163 | + |
|
| 164 | + $validationErrors = array_merge($nameValidation, $emailValidation, $otherValidation); |
|
| 165 | + |
|
| 166 | + return $validationErrors; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param Request $request |
|
| 171 | + * |
|
| 172 | + * @param Comment|null $comment |
|
| 173 | + * |
|
| 174 | + * @throws OptimisticLockFailedException |
|
| 175 | + * @throws Exception |
|
| 176 | + */ |
|
| 177 | + protected function saveAsEmailConfirmation(Request $request, $comment) |
|
| 178 | + { |
|
| 179 | + $request->generateEmailConfirmationHash(); |
|
| 180 | + $request->save(); |
|
| 181 | + |
|
| 182 | + if ($comment !== null) { |
|
| 183 | + $comment->setRequest($request->getId()); |
|
| 184 | + $comment->save(); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
| 188 | + $request->getIp(), |
|
| 189 | + $request->getForwardedIp()); |
|
| 190 | + |
|
| 191 | + $this->assign("ip", $trustedIp); |
|
| 192 | + $this->assign("id", $request->getId()); |
|
| 193 | + $this->assign("hash", $request->getEmailConfirm()); |
|
| 194 | + |
|
| 195 | + // Sends the confirmation email to the user. |
|
| 196 | + // FIXME: domains |
|
| 197 | + /** @var Domain $domain */ |
|
| 198 | + $domain = Domain::getById(1, $this->getDatabase()); |
|
| 199 | + $this->getEmailHelper()->sendMail( |
|
| 200 | + $domain->getEmailReplyAddress(), |
|
| 201 | + $request->getEmail(), |
|
| 202 | + "[ACC #{$request->getId()}] English Wikipedia Account Request", |
|
| 203 | + $this->fetchTemplate('request/confirmation-mail.tpl')); |
|
| 204 | + |
|
| 205 | + $this->redirect('emailConfirmationRequired'); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param Request $request |
|
| 210 | + * |
|
| 211 | + * @param Comment|null $comment |
|
| 212 | + * |
|
| 213 | + * @throws OptimisticLockFailedException |
|
| 214 | + * @throws Exception |
|
| 215 | + */ |
|
| 216 | + protected function saveWithoutEmailConfirmation(Request $request, $comment) |
|
| 217 | + { |
|
| 218 | + $request->setEmailConfirm(0); // fixme Since it can't be null |
|
| 219 | + $request->save(); |
|
| 220 | + |
|
| 221 | + if ($comment !== null) { |
|
| 222 | + $comment->setRequest($request->getId()); |
|
| 223 | + $comment->save(); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $this->getNotificationHelper()->requestReceived($request); |
|
| 227 | + |
|
| 228 | + $this->redirect('requestSubmitted'); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @return RequestValidationHelper |
|
| 233 | + */ |
|
| 234 | + protected function getRequestValidationHelper(): RequestValidationHelper |
|
| 235 | + { |
|
| 236 | + $banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), null); |
|
| 237 | + |
|
| 238 | + if ($this->validationHelper === null) { |
|
| 239 | + $this->validationHelper = new RequestValidationHelper( |
|
| 240 | + $banHelper, |
|
| 241 | + $this->getDatabase(), |
|
| 242 | + $this->getAntiSpoofProvider(), |
|
| 243 | + $this->getXffTrustProvider(), |
|
| 244 | + $this->getHttpHelper(), |
|
| 245 | + $this->getTorExitProvider(), |
|
| 246 | + $this->getSiteConfiguration()); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + return $this->validationHelper; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * @param Request $request |
|
| 254 | - * |
|
| 255 | - * @return void |
|
| 256 | - * @throws OptimisticLockFailedException |
|
| 257 | - */ |
|
| 258 | - protected function handleFormPost(Request $request): void |
|
| 259 | - { |
|
| 260 | - $comment = $this->createComment(); |
|
| 261 | - |
|
| 262 | - $validationErrors = $this->validateRequest($request); |
|
| 263 | - |
|
| 264 | - if (count($validationErrors) > 0) { |
|
| 265 | - foreach ($validationErrors as $validationError) { |
|
| 266 | - SessionAlert::error($validationError->getErrorMessage()); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // Preserve the data after an error |
|
| 270 | - WebRequest::setSessionContext('accountReq', |
|
| 271 | - array( |
|
| 272 | - 'username' => WebRequest::postString('name'), |
|
| 273 | - 'email' => WebRequest::postEmail('email'), |
|
| 274 | - 'comments' => WebRequest::postString('comments'), |
|
| 275 | - ) |
|
| 276 | - ); |
|
| 277 | - |
|
| 278 | - // Validation error, bomb out early. |
|
| 279 | - $this->redirect(); |
|
| 280 | - |
|
| 281 | - return; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - // actually save the request to the database |
|
| 285 | - if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) { |
|
| 286 | - $this->saveAsEmailConfirmation($request, $comment); |
|
| 287 | - $this->savePrivateData($request); |
|
| 288 | - } |
|
| 289 | - else { |
|
| 290 | - $this->saveWithoutEmailConfirmation($request, $comment); |
|
| 291 | - $this->savePrivateData($request); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - $this->getRequestValidationHelper()->postSaveValidations($request); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * @return void |
|
| 299 | - */ |
|
| 300 | - protected function handleFormRefilling(): void |
|
| 301 | - { |
|
| 302 | - // set the form values from the session context |
|
| 303 | - $context = WebRequest::getSessionContext('accountReq'); |
|
| 304 | - if ($context !== null && is_array($context)) { |
|
| 305 | - $this->assign('username', $context['username']); |
|
| 306 | - $this->assign('email', $context['email']); |
|
| 307 | - $this->assign('comments', $context['comments']); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - // Clear it for a refresh |
|
| 311 | - WebRequest::setSessionContext('accountReq', null); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - private function requestClientHints() |
|
| 315 | - { |
|
| 316 | - $hints = $this->getSiteConfiguration()->getAcceptClientHints(); |
|
| 317 | - |
|
| 318 | - $this->headerQueue[] = "Accept-CH: " . implode(', ', $hints); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - private function savePrivateData(Request $request) |
|
| 322 | - { |
|
| 323 | - foreach ($this->getSiteConfiguration()->getAcceptClientHints() as $header) |
|
| 324 | - { |
|
| 325 | - $value = WebRequest::httpHeader($header); |
|
| 326 | - |
|
| 327 | - if($value === null){ |
|
| 328 | - continue; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - $d = new RequestData(); |
|
| 332 | - $d->setDatabase($request->getDatabase()); |
|
| 333 | - $d->setRequest($request->getId()); |
|
| 334 | - |
|
| 335 | - $d->setType(RequestData::TYPE_CLIENTHINT); |
|
| 336 | - $d->setName($header); |
|
| 337 | - $d->setValue(WebRequest::httpHeader($header)); |
|
| 338 | - |
|
| 339 | - $d->save(); |
|
| 340 | - } |
|
| 341 | - } |
|
| 252 | + /** |
|
| 253 | + * @param Request $request |
|
| 254 | + * |
|
| 255 | + * @return void |
|
| 256 | + * @throws OptimisticLockFailedException |
|
| 257 | + */ |
|
| 258 | + protected function handleFormPost(Request $request): void |
|
| 259 | + { |
|
| 260 | + $comment = $this->createComment(); |
|
| 261 | + |
|
| 262 | + $validationErrors = $this->validateRequest($request); |
|
| 263 | + |
|
| 264 | + if (count($validationErrors) > 0) { |
|
| 265 | + foreach ($validationErrors as $validationError) { |
|
| 266 | + SessionAlert::error($validationError->getErrorMessage()); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // Preserve the data after an error |
|
| 270 | + WebRequest::setSessionContext('accountReq', |
|
| 271 | + array( |
|
| 272 | + 'username' => WebRequest::postString('name'), |
|
| 273 | + 'email' => WebRequest::postEmail('email'), |
|
| 274 | + 'comments' => WebRequest::postString('comments'), |
|
| 275 | + ) |
|
| 276 | + ); |
|
| 277 | + |
|
| 278 | + // Validation error, bomb out early. |
|
| 279 | + $this->redirect(); |
|
| 280 | + |
|
| 281 | + return; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + // actually save the request to the database |
|
| 285 | + if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) { |
|
| 286 | + $this->saveAsEmailConfirmation($request, $comment); |
|
| 287 | + $this->savePrivateData($request); |
|
| 288 | + } |
|
| 289 | + else { |
|
| 290 | + $this->saveWithoutEmailConfirmation($request, $comment); |
|
| 291 | + $this->savePrivateData($request); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + $this->getRequestValidationHelper()->postSaveValidations($request); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * @return void |
|
| 299 | + */ |
|
| 300 | + protected function handleFormRefilling(): void |
|
| 301 | + { |
|
| 302 | + // set the form values from the session context |
|
| 303 | + $context = WebRequest::getSessionContext('accountReq'); |
|
| 304 | + if ($context !== null && is_array($context)) { |
|
| 305 | + $this->assign('username', $context['username']); |
|
| 306 | + $this->assign('email', $context['email']); |
|
| 307 | + $this->assign('comments', $context['comments']); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + // Clear it for a refresh |
|
| 311 | + WebRequest::setSessionContext('accountReq', null); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + private function requestClientHints() |
|
| 315 | + { |
|
| 316 | + $hints = $this->getSiteConfiguration()->getAcceptClientHints(); |
|
| 317 | + |
|
| 318 | + $this->headerQueue[] = "Accept-CH: " . implode(', ', $hints); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + private function savePrivateData(Request $request) |
|
| 322 | + { |
|
| 323 | + foreach ($this->getSiteConfiguration()->getAcceptClientHints() as $header) |
|
| 324 | + { |
|
| 325 | + $value = WebRequest::httpHeader($header); |
|
| 326 | + |
|
| 327 | + if($value === null){ |
|
| 328 | + continue; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + $d = new RequestData(); |
|
| 332 | + $d->setDatabase($request->getDatabase()); |
|
| 333 | + $d->setRequest($request->getId()); |
|
| 334 | + |
|
| 335 | + $d->setType(RequestData::TYPE_CLIENTHINT); |
|
| 336 | + $d->setName($header); |
|
| 337 | + $d->setValue(WebRequest::httpHeader($header)); |
|
| 338 | + |
|
| 339 | + $d->save(); |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | 342 | } |
| 343 | 343 | \ No newline at end of file |
@@ -324,7 +324,7 @@ |
||
| 324 | 324 | { |
| 325 | 325 | $value = WebRequest::httpHeader($header); |
| 326 | 326 | |
| 327 | - if($value === null){ |
|
| 327 | + if ($value === null) { |
|
| 328 | 328 | continue; |
| 329 | 329 | } |
| 330 | 330 | |
@@ -42,8 +42,7 @@ discard block |
||
| 42 | 42 | if (WebRequest::wasPosted()) { |
| 43 | 43 | $request = $this->createNewRequest(null); |
| 44 | 44 | $this->handleFormPost($request); |
| 45 | - } |
|
| 46 | - else { |
|
| 45 | + } else { |
|
| 47 | 46 | $this->requestClientHints(); |
| 48 | 47 | $this->handleFormRefilling(); |
| 49 | 48 | |
@@ -77,8 +76,7 @@ discard block |
||
| 77 | 76 | if (WebRequest::wasPosted()) { |
| 78 | 77 | $request = $this->createNewRequest($form); |
| 79 | 78 | $this->handleFormPost($request); |
| 80 | - } |
|
| 81 | - else { |
|
| 79 | + } else { |
|
| 82 | 80 | $this->requestClientHints(); |
| 83 | 81 | $this->handleFormRefilling(); |
| 84 | 82 | |
@@ -106,8 +104,7 @@ discard block |
||
| 106 | 104 | |
| 107 | 105 | if ($form === null) { |
| 108 | 106 | $domain = 1; |
| 109 | - } |
|
| 110 | - else { |
|
| 107 | + } else { |
|
| 111 | 108 | $domain = $form->getDomain(); |
| 112 | 109 | $request->setOriginForm($form->getId()); |
| 113 | 110 | } |
@@ -285,8 +282,7 @@ discard block |
||
| 285 | 282 | if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) { |
| 286 | 283 | $this->saveAsEmailConfirmation($request, $comment); |
| 287 | 284 | $this->savePrivateData($request); |
| 288 | - } |
|
| 289 | - else { |
|
| 285 | + } else { |
|
| 290 | 286 | $this->saveWithoutEmailConfirmation($request, $comment); |
| 291 | 287 | $this->savePrivateData($request); |
| 292 | 288 | } |
@@ -320,11 +316,10 @@ discard block |
||
| 320 | 316 | |
| 321 | 317 | private function savePrivateData(Request $request) |
| 322 | 318 | { |
| 323 | - foreach ($this->getSiteConfiguration()->getAcceptClientHints() as $header) |
|
| 324 | - { |
|
| 319 | + foreach ($this->getSiteConfiguration()->getAcceptClientHints() as $header) { |
|
| 325 | 320 | $value = WebRequest::httpHeader($header); |
| 326 | 321 | |
| 327 | - if($value === null){ |
|
| 322 | + if($value === null) { |
|
| 328 | 323 | continue; |
| 329 | 324 | } |
| 330 | 325 | |
@@ -12,15 +12,15 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PageEmailConfirmationRequired extends PublicInterfacePageBase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Main function for this page, when no specific actions are called. |
|
| 17 | - * @return void |
|
| 18 | - */ |
|
| 19 | - protected function main() |
|
| 20 | - { |
|
| 21 | - // clear any requests for client hints |
|
| 22 | - $this->headerQueue[] = "Accept-CH:"; |
|
| 15 | + /** |
|
| 16 | + * Main function for this page, when no specific actions are called. |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 19 | + protected function main() |
|
| 20 | + { |
|
| 21 | + // clear any requests for client hints |
|
| 22 | + $this->headerQueue[] = "Accept-CH:"; |
|
| 23 | 23 | |
| 24 | - $this->setTemplate('request/email-confirmation.tpl'); |
|
| 25 | - } |
|
| 24 | + $this->setTemplate('request/email-confirmation.tpl'); |
|
| 25 | + } |
|
| 26 | 26 | } |
| 27 | 27 | \ No newline at end of file |
@@ -21,159 +21,159 @@ |
||
| 21 | 21 | |
| 22 | 22 | class PageEditComment extends InternalPageBase |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Main function for this page, when no specific actions are called. |
|
| 26 | - * @throws ApplicationLogicException |
|
| 27 | - * @throws Exception |
|
| 28 | - */ |
|
| 29 | - protected function main() |
|
| 30 | - { |
|
| 31 | - $commentId = WebRequest::getInt('id'); |
|
| 32 | - if ($commentId === null) { |
|
| 33 | - throw new ApplicationLogicException('Comment ID not specified'); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - $database = $this->getDatabase(); |
|
| 37 | - |
|
| 38 | - /** @var Comment|false $comment */ |
|
| 39 | - $comment = Comment::getById($commentId, $database); |
|
| 40 | - if ($comment === false) { |
|
| 41 | - throw new ApplicationLogicException('Comment not found'); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $currentUser = User::getCurrent($database); |
|
| 45 | - |
|
| 46 | - $this->checkCommentAccess($comment, $currentUser); |
|
| 47 | - |
|
| 48 | - /** @var Request|false $request */ |
|
| 49 | - $request = Request::getById($comment->getRequest(), $database); |
|
| 50 | - |
|
| 51 | - if ($request === false) { |
|
| 52 | - throw new ApplicationLogicException('Request was not found.'); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - $canUnflag = $this->barrierTest('unflag', $currentUser, PageFlagComment::class); |
|
| 56 | - |
|
| 57 | - if (WebRequest::wasPosted()) { |
|
| 58 | - $this->validateCSRFToken(); |
|
| 59 | - $newComment = WebRequest::postString('newcomment'); |
|
| 60 | - $visibility = WebRequest::postString('visibility'); |
|
| 61 | - $doUnflag = WebRequest::postBoolean('unflag'); |
|
| 62 | - |
|
| 63 | - if ($newComment === null || $newComment === '') { |
|
| 64 | - throw new ApplicationLogicException('Comment cannot be empty!'); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - $commentDataUnchanged = $newComment === $comment->getComment() |
|
| 68 | - && ($comment->getVisibility() === 'requester' || $comment->getVisibility() === $visibility); |
|
| 69 | - $flagStatusUnchanged = (!$canUnflag || $comment->getFlagged() && !$doUnflag); |
|
| 70 | - |
|
| 71 | - if ($commentDataUnchanged && $flagStatusUnchanged) { |
|
| 72 | - // No change was made; redirect back. |
|
| 73 | - $this->redirectBack($comment->getRequest()); |
|
| 74 | - |
|
| 75 | - return; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // optimistically lock from the load of the edit comment form |
|
| 79 | - $updateVersion = WebRequest::postInt('updateversion'); |
|
| 80 | - |
|
| 81 | - // comment data has changed, update the object |
|
| 82 | - if (!$commentDataUnchanged) { |
|
| 83 | - $this->updateCommentData($comment, $visibility, $newComment); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if ($doUnflag && $canUnflag) { |
|
| 87 | - $comment->setFlagged(false); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $comment->setUpdateVersion($updateVersion); |
|
| 91 | - $comment->save(); |
|
| 92 | - |
|
| 93 | - if (!$commentDataUnchanged) { |
|
| 94 | - Logger::editComment($database, $comment, $request); |
|
| 95 | - $this->getNotificationHelper()->commentEdited($comment, $request); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - if ($doUnflag && $canUnflag) { |
|
| 99 | - Logger::unflaggedComment($database, $comment, $request->getDomain()); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - SessionAlert::success('Comment has been saved successfully'); |
|
| 103 | - $this->redirectBack($comment->getRequest()); |
|
| 104 | - } |
|
| 105 | - else { |
|
| 106 | - $this->assignCSRFToken(); |
|
| 107 | - $this->assign('comment', $comment); |
|
| 108 | - $this->assign('request', $request); |
|
| 109 | - $this->assign('user', User::getById($comment->getUser(), $database)); |
|
| 110 | - $this->assign('canUnflag', $canUnflag); |
|
| 111 | - $this->setTemplate('edit-comment.tpl'); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @throws AccessDeniedException |
|
| 117 | - */ |
|
| 118 | - private function checkCommentAccess(Comment $comment, User $currentUser): void |
|
| 119 | - { |
|
| 120 | - if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) { |
|
| 121 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $restrictedVisibility = $comment->getFlagged() |
|
| 125 | - || $comment->getVisibility() === 'admin' |
|
| 126 | - || $comment->getVisibility() === 'checkuser'; |
|
| 127 | - |
|
| 128 | - if ($restrictedVisibility && !$this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) { |
|
| 129 | - // Restricted visibility comments can only be seen if the user has a request reserved. |
|
| 130 | - /** @var Request $request */ |
|
| 131 | - $request = Request::getById($comment->getRequest(), $comment->getDatabase()); |
|
| 132 | - |
|
| 133 | - if ($request->getReserved() !== $currentUser->getId()) { |
|
| 134 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - if ($comment->getVisibility() === 'admin' |
|
| 139 | - && !$this->barrierTest('seeRestrictedComments', $currentUser, 'RequestData') |
|
| 140 | - && $comment->getUser() !== $currentUser->getId()) { |
|
| 141 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - if ($comment->getVisibility() === 'checkuser' |
|
| 145 | - && !$this->barrierTest('seeCheckuserComments', $currentUser, 'RequestData') |
|
| 146 | - && $comment->getUser() !== $currentUser->getId()) { |
|
| 147 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @throws ApplicationLogicException |
|
| 153 | - */ |
|
| 154 | - private function updateCommentData(Comment $comment, ?string $visibility, string $newComment): void |
|
| 155 | - { |
|
| 156 | - if ($comment->getVisibility() !== 'requester') { |
|
| 157 | - if ($visibility !== 'user' && $visibility !== 'admin' && $visibility !== 'checkuser') { |
|
| 158 | - throw new ApplicationLogicException('Comment visibility is not valid'); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $comment->setVisibility($visibility); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $comment->setComment($newComment); |
|
| 165 | - $comment->touchEdited(); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - private function redirectBack(int $requestId): void |
|
| 169 | - { |
|
| 170 | - $source = WebRequest::getString('from'); |
|
| 171 | - |
|
| 172 | - if ($source == 'flagged') { |
|
| 173 | - $this->redirect('flaggedComments'); |
|
| 174 | - } |
|
| 175 | - else { |
|
| 176 | - $this->redirect('viewRequest', null, array('id' => $requestId)); |
|
| 177 | - } |
|
| 178 | - } |
|
| 24 | + /** |
|
| 25 | + * Main function for this page, when no specific actions are called. |
|
| 26 | + * @throws ApplicationLogicException |
|
| 27 | + * @throws Exception |
|
| 28 | + */ |
|
| 29 | + protected function main() |
|
| 30 | + { |
|
| 31 | + $commentId = WebRequest::getInt('id'); |
|
| 32 | + if ($commentId === null) { |
|
| 33 | + throw new ApplicationLogicException('Comment ID not specified'); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + $database = $this->getDatabase(); |
|
| 37 | + |
|
| 38 | + /** @var Comment|false $comment */ |
|
| 39 | + $comment = Comment::getById($commentId, $database); |
|
| 40 | + if ($comment === false) { |
|
| 41 | + throw new ApplicationLogicException('Comment not found'); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $currentUser = User::getCurrent($database); |
|
| 45 | + |
|
| 46 | + $this->checkCommentAccess($comment, $currentUser); |
|
| 47 | + |
|
| 48 | + /** @var Request|false $request */ |
|
| 49 | + $request = Request::getById($comment->getRequest(), $database); |
|
| 50 | + |
|
| 51 | + if ($request === false) { |
|
| 52 | + throw new ApplicationLogicException('Request was not found.'); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + $canUnflag = $this->barrierTest('unflag', $currentUser, PageFlagComment::class); |
|
| 56 | + |
|
| 57 | + if (WebRequest::wasPosted()) { |
|
| 58 | + $this->validateCSRFToken(); |
|
| 59 | + $newComment = WebRequest::postString('newcomment'); |
|
| 60 | + $visibility = WebRequest::postString('visibility'); |
|
| 61 | + $doUnflag = WebRequest::postBoolean('unflag'); |
|
| 62 | + |
|
| 63 | + if ($newComment === null || $newComment === '') { |
|
| 64 | + throw new ApplicationLogicException('Comment cannot be empty!'); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + $commentDataUnchanged = $newComment === $comment->getComment() |
|
| 68 | + && ($comment->getVisibility() === 'requester' || $comment->getVisibility() === $visibility); |
|
| 69 | + $flagStatusUnchanged = (!$canUnflag || $comment->getFlagged() && !$doUnflag); |
|
| 70 | + |
|
| 71 | + if ($commentDataUnchanged && $flagStatusUnchanged) { |
|
| 72 | + // No change was made; redirect back. |
|
| 73 | + $this->redirectBack($comment->getRequest()); |
|
| 74 | + |
|
| 75 | + return; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // optimistically lock from the load of the edit comment form |
|
| 79 | + $updateVersion = WebRequest::postInt('updateversion'); |
|
| 80 | + |
|
| 81 | + // comment data has changed, update the object |
|
| 82 | + if (!$commentDataUnchanged) { |
|
| 83 | + $this->updateCommentData($comment, $visibility, $newComment); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if ($doUnflag && $canUnflag) { |
|
| 87 | + $comment->setFlagged(false); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $comment->setUpdateVersion($updateVersion); |
|
| 91 | + $comment->save(); |
|
| 92 | + |
|
| 93 | + if (!$commentDataUnchanged) { |
|
| 94 | + Logger::editComment($database, $comment, $request); |
|
| 95 | + $this->getNotificationHelper()->commentEdited($comment, $request); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + if ($doUnflag && $canUnflag) { |
|
| 99 | + Logger::unflaggedComment($database, $comment, $request->getDomain()); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + SessionAlert::success('Comment has been saved successfully'); |
|
| 103 | + $this->redirectBack($comment->getRequest()); |
|
| 104 | + } |
|
| 105 | + else { |
|
| 106 | + $this->assignCSRFToken(); |
|
| 107 | + $this->assign('comment', $comment); |
|
| 108 | + $this->assign('request', $request); |
|
| 109 | + $this->assign('user', User::getById($comment->getUser(), $database)); |
|
| 110 | + $this->assign('canUnflag', $canUnflag); |
|
| 111 | + $this->setTemplate('edit-comment.tpl'); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @throws AccessDeniedException |
|
| 117 | + */ |
|
| 118 | + private function checkCommentAccess(Comment $comment, User $currentUser): void |
|
| 119 | + { |
|
| 120 | + if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) { |
|
| 121 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $restrictedVisibility = $comment->getFlagged() |
|
| 125 | + || $comment->getVisibility() === 'admin' |
|
| 126 | + || $comment->getVisibility() === 'checkuser'; |
|
| 127 | + |
|
| 128 | + if ($restrictedVisibility && !$this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) { |
|
| 129 | + // Restricted visibility comments can only be seen if the user has a request reserved. |
|
| 130 | + /** @var Request $request */ |
|
| 131 | + $request = Request::getById($comment->getRequest(), $comment->getDatabase()); |
|
| 132 | + |
|
| 133 | + if ($request->getReserved() !== $currentUser->getId()) { |
|
| 134 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + if ($comment->getVisibility() === 'admin' |
|
| 139 | + && !$this->barrierTest('seeRestrictedComments', $currentUser, 'RequestData') |
|
| 140 | + && $comment->getUser() !== $currentUser->getId()) { |
|
| 141 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if ($comment->getVisibility() === 'checkuser' |
|
| 145 | + && !$this->barrierTest('seeCheckuserComments', $currentUser, 'RequestData') |
|
| 146 | + && $comment->getUser() !== $currentUser->getId()) { |
|
| 147 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @throws ApplicationLogicException |
|
| 153 | + */ |
|
| 154 | + private function updateCommentData(Comment $comment, ?string $visibility, string $newComment): void |
|
| 155 | + { |
|
| 156 | + if ($comment->getVisibility() !== 'requester') { |
|
| 157 | + if ($visibility !== 'user' && $visibility !== 'admin' && $visibility !== 'checkuser') { |
|
| 158 | + throw new ApplicationLogicException('Comment visibility is not valid'); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $comment->setVisibility($visibility); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $comment->setComment($newComment); |
|
| 165 | + $comment->touchEdited(); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + private function redirectBack(int $requestId): void |
|
| 169 | + { |
|
| 170 | + $source = WebRequest::getString('from'); |
|
| 171 | + |
|
| 172 | + if ($source == 'flagged') { |
|
| 173 | + $this->redirect('flaggedComments'); |
|
| 174 | + } |
|
| 175 | + else { |
|
| 176 | + $this->redirect('viewRequest', null, array('id' => $requestId)); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | } |
@@ -101,8 +101,7 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | SessionAlert::success('Comment has been saved successfully'); |
| 103 | 103 | $this->redirectBack($comment->getRequest()); |
| 104 | - } |
|
| 105 | - else { |
|
| 104 | + } else { |
|
| 106 | 105 | $this->assignCSRFToken(); |
| 107 | 106 | $this->assign('comment', $comment); |
| 108 | 107 | $this->assign('request', $request); |
@@ -171,8 +170,7 @@ discard block |
||
| 171 | 170 | |
| 172 | 171 | if ($source == 'flagged') { |
| 173 | 172 | $this->redirect('flaggedComments'); |
| 174 | - } |
|
| 175 | - else { |
|
| 173 | + } else { |
|
| 176 | 174 | $this->redirect('viewRequest', null, array('id' => $requestId)); |
| 177 | 175 | } |
| 178 | 176 | } |
@@ -13,11 +13,11 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class StatsFastCloses extends InternalPageBase |
| 15 | 15 | { |
| 16 | - public function main() |
|
| 17 | - { |
|
| 18 | - $this->setHtmlTitle('Fast Closes :: Statistics'); |
|
| 16 | + public function main() |
|
| 17 | + { |
|
| 18 | + $this->setHtmlTitle('Fast Closes :: Statistics'); |
|
| 19 | 19 | |
| 20 | - $query = <<<SQL |
|
| 20 | + $query = <<<SQL |
|
| 21 | 21 | WITH closedescs AS ( |
| 22 | 22 | SELECT closes, mail_desc FROM closes |
| 23 | 23 | UNION ALL |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | ORDER BY TIMEDIFF(log_closed.timestamp, log_reserved.timestamp) ASC |
| 48 | 48 | ; |
| 49 | 49 | SQL; |
| 50 | - $database = $this->getDatabase(); |
|
| 51 | - $statement = $database->query($query); |
|
| 52 | - $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 53 | - $this->assign('dataTable', $data); |
|
| 54 | - $this->assign('statsPageTitle', 'Requests closed less than 30 seconds after reservation in the past 3 months'); |
|
| 55 | - $this->setTemplate('statistics/fast-closes.tpl'); |
|
| 56 | - } |
|
| 50 | + $database = $this->getDatabase(); |
|
| 51 | + $statement = $database->query($query); |
|
| 52 | + $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 53 | + $this->assign('dataTable', $data); |
|
| 54 | + $this->assign('statsPageTitle', 'Requests closed less than 30 seconds after reservation in the past 3 months'); |
|
| 55 | + $this->setTemplate('statistics/fast-closes.tpl'); |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | class StatsTemplateStats extends InternalPageBase |
| 17 | 17 | { |
| 18 | - public function main() |
|
| 19 | - { |
|
| 20 | - $this->setHtmlTitle('Template Stats :: Statistics'); |
|
| 18 | + public function main() |
|
| 19 | + { |
|
| 20 | + $this->setHtmlTitle('Template Stats :: Statistics'); |
|
| 21 | 21 | |
| 22 | - $query = <<<SQL |
|
| 22 | + $query = <<<SQL |
|
| 23 | 23 | SELECT |
| 24 | 24 | t.id AS templateid, |
| 25 | 25 | t.usercode AS usercode, |
@@ -49,17 +49,17 @@ discard block |
||
| 49 | 49 | ) allUsers ON allUsers.welcome_template = t.id |
| 50 | 50 | ORDER BY t.id |
| 51 | 51 | SQL; |
| 52 | - $database = $this->getDatabase(); |
|
| 53 | - $statement = $database->prepare($query); |
|
| 54 | - $statement->execute([ |
|
| 55 | - ':domain1' => WebRequest::getSessionDomain(), |
|
| 56 | - ':domain2' => WebRequest::getSessionDomain(), |
|
| 57 | - ':preference1' => PreferenceManager::PREF_WELCOMETEMPLATE, |
|
| 58 | - ':preference2' => PreferenceManager::PREF_WELCOMETEMPLATE, |
|
| 59 | - ]); |
|
| 60 | - $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 61 | - $this->assign('dataTable', $data); |
|
| 62 | - $this->assign('statsPageTitle', 'Template Stats'); |
|
| 63 | - $this->setTemplate('statistics/welcome-template-usage.tpl'); |
|
| 64 | - } |
|
| 52 | + $database = $this->getDatabase(); |
|
| 53 | + $statement = $database->prepare($query); |
|
| 54 | + $statement->execute([ |
|
| 55 | + ':domain1' => WebRequest::getSessionDomain(), |
|
| 56 | + ':domain2' => WebRequest::getSessionDomain(), |
|
| 57 | + ':preference1' => PreferenceManager::PREF_WELCOMETEMPLATE, |
|
| 58 | + ':preference2' => PreferenceManager::PREF_WELCOMETEMPLATE, |
|
| 59 | + ]); |
|
| 60 | + $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 61 | + $this->assign('dataTable', $data); |
|
| 62 | + $this->assign('statsPageTitle', 'Template Stats'); |
|
| 63 | + $this->setTemplate('statistics/welcome-template-usage.tpl'); |
|
| 64 | + } |
|
| 65 | 65 | } |