Skip to content

Commit

Permalink
1.0.2 - Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
West14 committed Sep 22, 2019
1 parent eaad0aa commit 94d51dc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
32 changes: 15 additions & 17 deletions Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,23 @@

class Listener
{
public static function postDispatchAdminLogin(\XF\Mvc\Controller $controller, $action, \XF\Mvc\ParameterBag $params, \XF\Mvc\Reply\AbstractReply &$reply)
/**
* @param \XF\Mvc\Controller $controller
* @param $action
* @param \XF\Mvc\ParameterBag $params
* @throws \XF\Mvc\Reply\Exception
*/
public static function preDispatchAdminLogin(\XF\Mvc\Controller $controller, $action, \XF\Mvc\ParameterBag $params)
{
if (strtolower($action) == 'form')
{
$cookie = $controller->request()->getCookie('user');
$redirect = $controller->redirect(\XF::app()->router('public')->buildLink('index'));

if ($cookie)
{
$userId = stristr($cookie, ',', true);
/** @var \XF\Entity\User $user */
$user = \XF::em()->find('XF:User', $userId);
/** @var \XF\Entity\User|null $user */
$user = \XF::em()->find(
'XF:User',
\XF::app()->container('session.public')['userId']
);

if (!$user || !$user->is_admin) $reply = $redirect;
}
else
{
$reply = $redirect;
}
if (!$user || !$user->is_admin)
{
throw $controller->exception($controller->redirect(\XF::app()->router('public')->buildLink('index')));
}
}
}
4 changes: 2 additions & 2 deletions _output/code_event_listeners/_metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"controller_post_dispatch_d0e0ae1713ba07fd6c53571e8d2bdbd2.json": {
"hash": "4cf82e98045a762bcf89af55c9417297"
"controller_pre_dispatch_8ac4313b3926a10db7b432cc85eda211.json": {
"hash": "ab12d665471f360148a389924f4028c9"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"event_id": "controller_post_dispatch",
"event_id": "controller_pre_dispatch",
"execute_order": 10,
"callback_class": "West\\ProtectACP\\Listener",
"callback_method": "postDispatchAdminLogin",
"callback_method": "preDispatchAdminLogin",
"active": true,
"hint": "XF\\Admin\\Controller\\Login",
"description": ""
Expand Down
4 changes: 2 additions & 2 deletions addon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"legacy_addon_id": "",
"title": "[West] Protect ACP",
"description": "This add-on redirects users who don't have admin permissions to the public index.",
"version_id": 1000170,
"version_string": "1.0.1",
"version_id": 1000270,
"version_string": "1.0.2",
"dev": "West",
"dev_url": "https://t.me/West99",
"faq_url": "",
Expand Down

0 comments on commit 94d51dc

Please sign in to comment.