<?php

/**
 * Switches the current session user to $userId (requires permission!)
 *
 * @param int $userId - Slave User ID
 *
 * @throws QUI\Exception
 */

use QUI\MasterLogin\Manager;

QUI::getAjax()->registerFunction(
    'package_quiqqer_masterlogin_ajax_frontend_logInAs',
    function ($userId, $csrfToken) {
        Manager::checkCsrfToken((string)$csrfToken);
        Manager::checkUsePermission();
        Manager::logInAs((string)$userId);
    },
    ['userId', 'csrfToken'],
    'Permission::checkUser'
);
