Added registrar impersonation, fixed #155

This commit is contained in:
Pinga 2024-08-25 19:41:56 +03:00
parent 34d966aeeb
commit 4d8239afc7
5 changed files with 26 additions and 0 deletions

View file

@ -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
*/

View file

@ -1247,4 +1247,9 @@ class RegistrarsController extends Controller
}
}
public function leave_impersonation(Request $request, Response $response)
{
Auth::leaveImpersonation();
}
}

View file

@ -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);

View file

@ -61,6 +61,7 @@
</a>
<div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
<a href="{{route('profile')}}" class="dropdown-item">{{ __('My Profile') }}</a>
{% if isAdminImpersonation %}<a href="{{ route('leave_impersonation') }}" class="dropdown-item">{{ __('Leave Impersonation') }}</a>{% endif %}
<a href="{{route('logout')}}" class="dropdown-item">{{ __('Logout') }}</a>
</div>
</div>

View file

@ -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');