diff options
Diffstat (limited to 'app/Controller')
-rw-r--r-- | app/Controller/Base.php | 12 | ||||
-rw-r--r-- | app/Controller/File.php | 2 | ||||
-rw-r--r-- | app/Controller/Ical.php | 1 | ||||
-rw-r--r-- | app/Controller/User.php | 6 | ||||
-rw-r--r-- | app/Controller/Webhook.php | 43 |
5 files changed, 28 insertions, 36 deletions
diff --git a/app/Controller/Base.php b/app/Controller/Base.php index fcd07b99..19bb9ac9 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -211,6 +211,18 @@ abstract class Base extends \Core\Base } /** + * Check webhook token + * + * @access protected + */ + protected function checkWebhookToken() + { + if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { + $this->response->text('Not Authorized', 401); + } + } + + /** * Redirection when there is no project in the database * * @access protected diff --git a/app/Controller/File.php b/app/Controller/File.php index f0367537..f73a9de9 100644 --- a/app/Controller/File.php +++ b/app/Controller/File.php @@ -19,7 +19,7 @@ class File extends Base { $task = $this->getTask(); - if ($this->request->isPost() && $this->file->uploadScreenshot($task['project_id'], $task['id'], $this->request->getValue('screenshot'))) { + if ($this->request->isPost() && $this->file->uploadScreenshot($task['project_id'], $task['id'], $this->request->getValue('screenshot')) !== false) { $this->session->flash(t('Screenshot uploaded successfully.')); diff --git a/app/Controller/Ical.php b/app/Controller/Ical.php index 52e10fa1..8a7ed8b5 100644 --- a/app/Controller/Ical.php +++ b/app/Controller/Ical.php @@ -3,7 +3,6 @@ namespace Controller; use Model\TaskFilter; -use Model\Task as TaskModel; use Eluceo\iCal\Component\Calendar as iCalendar; /** diff --git a/app/Controller/User.php b/app/Controller/User.php index b049c926..4cea06b1 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -105,9 +105,11 @@ class User extends Base if ($valid) { - if ($this->user->create($values)) { + $user_id = $this->user->create($values); + + if ($user_id !== false) { $this->session->flash(t('User created successfully.')); - $this->response->redirect('?controller=user'); + $this->response->redirect($this->helper->url->to('user', 'show', array('user_id' => $user_id))); } else { $this->session->flashError(t('Unable to create your user.')); diff --git a/app/Controller/Webhook.php b/app/Controller/Webhook.php index c79b4ed6..d04f83b3 100644 --- a/app/Controller/Webhook.php +++ b/app/Controller/Webhook.php @@ -17,9 +17,7 @@ class Webhook extends Base */ public function task() { - if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { - $this->response->text('Not Authorized', 401); - } + $this->checkWebhookToken(); $defaultProject = $this->project->getFirst(); @@ -49,9 +47,7 @@ class Webhook extends Base */ public function github() { - if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { - $this->response->text('Not Authorized', 401); - } + $this->checkWebhookToken(); $this->githubWebhook->setProjectId($this->request->getIntegerParam('project_id')); @@ -70,15 +66,10 @@ class Webhook extends Base */ public function gitlab() { - if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { - $this->response->text('Not Authorized', 401); - } + $this->checkWebhookToken(); $this->gitlabWebhook->setProjectId($this->request->getIntegerParam('project_id')); - - $result = $this->gitlabWebhook->parsePayload( - $this->request->getJson() ?: array() - ); + $result = $this->gitlabWebhook->parsePayload($this->request->getJson() ?: array()); echo $result ? 'PARSED' : 'IGNORED'; } @@ -90,12 +81,9 @@ class Webhook extends Base */ public function bitbucket() { - if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { - $this->response->text('Not Authorized', 401); - } + $this->checkWebhookToken(); $this->bitbucketWebhook->setProjectId($this->request->getIntegerParam('project_id')); - $result = $this->bitbucketWebhook->parsePayload(json_decode(@$_POST['payload'], true) ?: array()); echo $result ? 'PARSED' : 'IGNORED'; @@ -108,11 +96,8 @@ class Webhook extends Base */ public function postmark() { - if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { - $this->response->text('Not Authorized', 401); - } - - echo $this->postmarkWebhook->parsePayload($this->request->getJson() ?: array()) ? 'PARSED' : 'IGNORED'; + $this->checkWebhookToken(); + echo $this->postmark->receiveEmail($this->request->getJson() ?: array()) ? 'PARSED' : 'IGNORED'; } /** @@ -122,11 +107,8 @@ class Webhook extends Base */ public function mailgun() { - if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { - $this->response->text('Not Authorized', 401); - } - - echo $this->mailgunWebhook->parsePayload($_POST) ? 'PARSED' : 'IGNORED'; + $this->checkWebhookToken(); + echo $this->mailgun->receiveEmail($_POST) ? 'PARSED' : 'IGNORED'; } /** @@ -136,10 +118,7 @@ class Webhook extends Base */ public function sendgrid() { - if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { - $this->response->text('Not Authorized', 401); - } - - echo $this->sendgridWebhook->parsePayload($_POST) ? 'PARSED' : 'IGNORED'; + $this->checkWebhookToken(); + echo $this->sendgrid->receiveEmail($_POST) ? 'PARSED' : 'IGNORED'; } } |