diff --git a/cp/app/Auth/Auth.php b/cp/app/Auth/Auth.php index 024d3fd..93f9b4a 100644 --- a/cp/app/Auth/Auth.php +++ b/cp/app/Auth/Auth.php @@ -341,6 +341,21 @@ class Auth } } + /** + * Leave impersonation mode + * @throws \Pinga\Auth\AuthError + */ + public static function leaveImpersonation(){ + $auth = self::$auth; + if (self::$auth->isLoggedIn()) { + $auth->leaveImpersonation(); + redirect()->route('registrars')->with('success','Left registrar panel successfully'); + } + else { + return false; + } + } + /** * @throws \Pinga\Auth\AuthError */ diff --git a/cp/app/Controllers/RegistrarsController.php b/cp/app/Controllers/RegistrarsController.php index 3e965a5..1948d71 100644 --- a/cp/app/Controllers/RegistrarsController.php +++ b/cp/app/Controllers/RegistrarsController.php @@ -1247,4 +1247,9 @@ class RegistrarsController extends Controller } } + public function leave_impersonation(Request $request, Response $response) + { + Auth::leaveImpersonation(); + } + } \ No newline at end of file diff --git a/cp/bootstrap/app.php b/cp/bootstrap/app.php index d991bbf..cd194ee 100644 --- a/cp/bootstrap/app.php +++ b/cp/bootstrap/app.php @@ -159,6 +159,10 @@ $container->set('view', function ($container) { $currency = isset($_SESSION['_currency']) ? $_SESSION['_currency'] : 'USD'; $view->getEnvironment()->addGlobal('currency', $currency); + // Check if the user is impersonated from the admin, otherwise default to false + $isAdminImpersonation = isset($_SESSION['impersonator']) ? $_SESSION['impersonator'] : false; + $view->getEnvironment()->addGlobal('isAdminImpersonation', $isAdminImpersonation); + $translateFunction = new TwigFunction('__', function ($text) use ($translations) { // Find the translation $translation = $translations->find(null, $text); diff --git a/cp/resources/views/layouts/app.twig b/cp/resources/views/layouts/app.twig index 3937b50..51cf10e 100644 --- a/cp/resources/views/layouts/app.twig +++ b/cp/resources/views/layouts/app.twig @@ -61,6 +61,7 @@ diff --git a/cp/routes/web.php b/cp/routes/web.php index 1ba511f..0dc4456 100644 --- a/cp/routes/web.php +++ b/cp/routes/web.php @@ -96,6 +96,7 @@ $app->group('', function ($route) { $route->map(['GET', 'POST'], '/registrar/edit', RegistrarsController::class .':editRegistrar')->setName('editRegistrar'); $route->get('/registrar/check', RegistrarsController::class . ':oteCheck')->setName('oteCheck'); $route->get('/registrar/impersonate/{registrar}', RegistrarsController::class . ':impersonateRegistrar')->setName('impersonateRegistrar'); + $route->get('/leave_impersonation', RegistrarsController::class . ':leave_impersonation')->setName('leave_impersonation'); $route->get('/users', UsersController::class .':listUsers')->setName('listUsers');