Added almost full registrar impersonation

This commit is contained in:
Pinga 2024-08-25 19:15:35 +03:00
parent b7c375ede2
commit 34d966aeeb
4 changed files with 45 additions and 1 deletions

View file

@ -322,6 +322,25 @@ class Auth
}
}
/**
* Impersonate a user
* @param $userId
* @throws \Pinga\Auth\AuthError
*/
public static function impersonateUser($userId){
$auth = self::$auth;
try {
$auth->admin()->logInAsUserById($userId);
redirect()->route('home')->with('success','Registrar impersonation started');
}
catch (UnknownIdException $e) {
redirect()->route('registrars')->with('error','Unknown ID');
}
catch (EmailNotVerifiedException $e) {
redirect()->route('registrars')->with('error','Email address not verified');
}
}
/**
* @throws \Pinga\Auth\AuthError
*/

View file

@ -7,6 +7,7 @@ use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Container\ContainerInterface;
use League\ISO3166\ISO3166;
use Respect\Validation\Validator as v;
use App\Auth\Auth;
class RegistrarsController extends Controller
{
@ -1223,4 +1224,27 @@ class RegistrarsController extends Controller
}
}
public function impersonateRegistrar(Request $request, Response $response, $args)
{
if ($_SESSION["auth_roles"] != 0) {
return $response->withHeader('Location', '/dashboard')->withStatus(302);
}
$db = $this->container->get('db');
if ($args) {
$args = trim($args);
$registrar_id = $db->selectValue('SELECT id FROM registrar WHERE clid = ?',
[ $args ]);
$user_id = $db->selectValue('SELECT user_id FROM registrar_users WHERE registrar_id = ?',
[ $registrar_id ]);
Auth::impersonateUser($user_id);
} else {
// Redirect to the registrars view
return $response->withHeader('Location', '/registrars')->withStatus(302);
}
}
}

View file

@ -13,7 +13,7 @@
function actionsFormatter(cell, formatterParams, onRendered) {
return `
<a class="btn btn-outline-primary btn-icon update-btn" href="/registrar/update/${cell.getRow().getData().clid}" title="{{ __('Manage Registrar') }}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1"></path><path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z"></path><path d="M16 5l3 3"></path></svg></a> <a class="btn btn-outline-secondary btn-icon update-btn" href="/registrar/pricing/${cell.getRow().getData().clid}" title="{{ __('Manage Custom Pricing') }}"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 21v-16a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v16l-3 -2l-2 2l-2 -2l-2 2l-2 -2l-3 2" /><path d="M14 8h-2.5a1.5 1.5 0 0 0 0 3h1a1.5 1.5 0 0 1 0 3h-2.5m2 0v1.5m0 -9v1.5" /></svg></a>
<a class="btn btn-outline-primary btn-icon update-btn" href="/registrar/update/${cell.getRow().getData().clid}" title="{{ __('Manage Registrar') }}"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1"></path><path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z"></path><path d="M16 5l3 3"></path></svg></a> <a class="btn btn-outline-secondary btn-icon update-btn" href="/registrar/pricing/${cell.getRow().getData().clid}" title="{{ __('Manage Custom Pricing') }}"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 21v-16a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v16l-3 -2l-2 2l-2 -2l-2 2l-2 -2l-3 2" /><path d="M14 8h-2.5a1.5 1.5 0 0 0 0 3h1a1.5 1.5 0 0 1 0 3h-2.5m2 0v1.5m0 -9v1.5" /></svg></a> <a class="btn btn-outline-info btn-icon update-btn" href="/registrar/impersonate/${cell.getRow().getData().clid}" title="{{ __('Impersonate') }}"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 8v-2a2 2 0 0 1 2 -2h7a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-7a2 2 0 0 1 -2 -2v-2" /><path d="M3 12h13l-3 -3" /><path d="M13 15l3 -3" /></svg></a>
`;
}

View file

@ -95,6 +95,7 @@ $app->group('', function ($route) {
$route->get('/registrar', RegistrarsController::class .':registrar')->setName('registrar');
$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('/users', UsersController::class .':listUsers')->setName('listUsers');