42 lines
1.5 KiB
PHP
42 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace routes;
|
|
|
|
use classes\authentication;
|
|
use objects\logs_o;
|
|
use objects\tokens_o;
|
|
use objects\users_o;
|
|
use traits\route_t;
|
|
|
|
class intimidateRoute
|
|
{
|
|
use route_t;
|
|
|
|
public function run(): void
|
|
{
|
|
$this->post('/su/intimidate', function () {
|
|
// Get the post data
|
|
global $response;
|
|
// Make sure the user has the SUPERUSER_INTIMIDATE permission
|
|
if (!$this->requirePermission('SUPERUSER_INTIMIDATE')) {
|
|
$response->error('Permission denied', 403);
|
|
}
|
|
// 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
|
|
$token = (new authentication())->create_token($intimidated_user->customer_number->value());
|
|
// Return the token
|
|
$response->success(['token' => $token]);
|
|
});
|
|
}
|
|
} |