post('/su/intimidate', function () { ScopeMiddleware::requireScope(Scope::SUPERUSER_WRITE, '/su/intimidate'); // Get the post data global $response; // Make sure the user has the SUPERUSER_INTIMIDATE permission $this->requirePermission('SUPERUSER_INTIMIDATE'); // Get the user object $user = (new authentication())->get_user(); // Get the post data $data = json_decode(file_get_contents('php://input'), true); // Check if the customer number, and password are set if (!isset($data['user_id'])) { $response->error('User id is required', 400); } // Get the user object $intimidated_user = (new users_o())->getUserById($data['user_id']); // Log the incident (new logs_o())->add('auth', 'global', 1, $user->id, 'AUTH_SUCCESS_INTIMIDATE', 'Created intimidate token for customer: ' . $data['user_id']); // If the credentials are valid, create a token (We're using the create_employee_token, since it's using user_id, and not customer_numbers.) $token = (new authentication())->create_impersonation_token( (int)$data['user_id'], (int)$user->id ); // Return the token $response->success(['token' => $token]); }, [ 'SUPERUSER_INTIMIDATE' => 'Intimidate a user' ] ); } }