Refactoring: added controlled middleware and changed response class
This commit is contained in:
36
app/Middleware/PostAuthenticationMiddleware.php
Normal file
36
app/Middleware/PostAuthenticationMiddleware.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Middleware;
|
||||
|
||||
use Kanboard\Core\Controller\BaseMiddleware;
|
||||
|
||||
/**
|
||||
* Class PostAuthenticationMiddleware
|
||||
*
|
||||
* @package Kanboard\Middleware
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class PostAuthenticationMiddleware extends BaseMiddleware
|
||||
{
|
||||
/**
|
||||
* Execute middleware
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$controller = strtolower($this->router->getController());
|
||||
$action = strtolower($this->router->getAction());
|
||||
$ignore = ($controller === 'twofactor' && in_array($action, array('code', 'check'))) || ($controller === 'auth' && $action === 'logout');
|
||||
|
||||
if ($ignore === false && $this->userSession->hasPostAuthentication() && ! $this->userSession->isPostAuthenticationValidated()) {
|
||||
$this->setNextMiddleware(null);
|
||||
|
||||
if ($this->request->isAjax()) {
|
||||
$this->response->text('Not Authorized', 401);
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('twofactor', 'code'));
|
||||
}
|
||||
|
||||
$this->next();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user