Log activity when modifying account details
This commit is contained in:
parent
0b2c0db170
commit
287fd60891
15 changed files with 85 additions and 57 deletions
|
@ -6,6 +6,7 @@ use Illuminate\Http\Request;
|
|||
use Illuminate\Http\Response;
|
||||
use Illuminate\Auth\AuthManager;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Facades\Activity;
|
||||
use Pterodactyl\Services\Users\UserUpdateService;
|
||||
use Pterodactyl\Transformers\Api\Client\AccountTransformer;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Account\UpdateEmailRequest;
|
||||
|
@ -43,14 +44,16 @@ class AccountController extends ClientApiController
|
|||
|
||||
/**
|
||||
* Update the authenticated user's email address.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function updateEmail(UpdateEmailRequest $request): JsonResponse
|
||||
{
|
||||
$original = $request->user()->email;
|
||||
$this->updateService->handle($request->user(), $request->validated());
|
||||
|
||||
Activity::event('user:account.email-changed')
|
||||
->property(['old' => $original, 'new' => $request->input('email')])
|
||||
->log();
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
|
@ -76,6 +79,8 @@ class AccountController extends ClientApiController
|
|||
$guard->logoutOtherDevices($request->input('password'));
|
||||
}
|
||||
|
||||
Activity::event('user:account.password-changed')->log();
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,47 +4,14 @@ namespace Pterodactyl\Http\Controllers\Api\Client;
|
|||
|
||||
use Pterodactyl\Models\ApiKey;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Facades\Activity;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Pterodactyl\Services\Api\KeyCreationService;
|
||||
use Pterodactyl\Repositories\Eloquent\ApiKeyRepository;
|
||||
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
||||
use Pterodactyl\Transformers\Api\Client\ApiKeyTransformer;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Account\StoreApiKeyRequest;
|
||||
|
||||
class ApiKeyController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Api\KeyCreationService
|
||||
*/
|
||||
private $keyCreationService;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Encryption\Encrypter
|
||||
*/
|
||||
private $encrypter;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\ApiKeyRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ApiKeyController constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
Encrypter $encrypter,
|
||||
KeyCreationService $keyCreationService,
|
||||
ApiKeyRepository $repository
|
||||
) {
|
||||
parent::__construct();
|
||||
|
||||
$this->encrypter = $encrypter;
|
||||
$this->keyCreationService = $keyCreationService;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the API keys that exist for the given client.
|
||||
*
|
||||
|
@ -75,6 +42,11 @@ class ApiKeyController extends ClientApiController
|
|||
$request->input('allowed_ips')
|
||||
);
|
||||
|
||||
Activity::event('user:api-key.create')
|
||||
->subject($token->accessToken)
|
||||
->property('identifier', $token->accessToken->identifier)
|
||||
->log();
|
||||
|
||||
return $this->fractal->item($token->accessToken)
|
||||
->transformWith($this->getTransformer(ApiKeyTransformer::class))
|
||||
->addMeta(['secret_token' => $token->plainTextToken])
|
||||
|
@ -88,15 +60,16 @@ class ApiKeyController extends ClientApiController
|
|||
*/
|
||||
public function delete(ClientApiRequest $request, string $identifier)
|
||||
{
|
||||
$response = $this->repository->deleteWhere([
|
||||
'key_type' => ApiKey::TYPE_ACCOUNT,
|
||||
'user_id' => $request->user()->id,
|
||||
'identifier' => $identifier,
|
||||
]);
|
||||
$key = $request->user()->apiKeys()
|
||||
->where('key_type', ApiKey::TYPE_ACCOUNT)
|
||||
->where('identifier', $identifier)
|
||||
->first();
|
||||
|
||||
if (!$response) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
Activity::event('user:api-key.delete')
|
||||
->property('identifer', $key->identifer)
|
||||
->log();
|
||||
|
||||
$key->delete();
|
||||
|
||||
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Pterodactyl\Http\Controllers\Api\Client;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Facades\Activity;
|
||||
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
||||
use Pterodactyl\Transformers\Api\Client\UserSSHKeyTransformer;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Account\StoreSSHKeyRequest;
|
||||
|
@ -31,6 +32,11 @@ class SSHKeyController extends ClientApiController
|
|||
'fingerprint' => $request->getKeyFingerprint(),
|
||||
]);
|
||||
|
||||
Activity::event('user:ssh-key.create')
|
||||
->subject($model)
|
||||
->property('fingerprint', $request->getKeyFingerprint())
|
||||
->log();
|
||||
|
||||
return $this->fractal->item($model)
|
||||
->transformWith($this->getTransformer(UserSSHKeyTransformer::class))
|
||||
->toArray();
|
||||
|
@ -41,7 +47,14 @@ class SSHKeyController extends ClientApiController
|
|||
*/
|
||||
public function delete(ClientApiRequest $request, string $identifier): JsonResponse
|
||||
{
|
||||
$request->user()->sshKeys()->where('fingerprint', $identifier)->delete();
|
||||
$key = $request->user()->sshKeys()->where('fingerprint', $identifier)->firstOrFail();
|
||||
|
||||
$key->delete();
|
||||
|
||||
Activity::event('user:ssh-key.delete')
|
||||
->subject($key)
|
||||
->property('fingerprint', $key->fingerprint)
|
||||
->log();
|
||||
|
||||
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use Carbon\Carbon;
|
|||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Facades\Activity;
|
||||
use Illuminate\Contracts\Validation\Factory;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Pterodactyl\Services\Users\TwoFactorSetupService;
|
||||
|
@ -89,6 +90,8 @@ class TwoFactorController extends ClientApiController
|
|||
|
||||
$tokens = $this->toggleTwoFactorService->handle($request->user(), $request->input('code'), true);
|
||||
|
||||
Activity::event('user:two-factor.create')->log();
|
||||
|
||||
return new JsonResponse([
|
||||
'object' => 'recovery_tokens',
|
||||
'attributes' => [
|
||||
|
@ -117,6 +120,8 @@ class TwoFactorController extends ClientApiController
|
|||
'use_totp' => false,
|
||||
]);
|
||||
|
||||
Activity::event('user:two-factor.delete')->log();
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class BackupStatusController extends Controller
|
|||
throw new BadRequestHttpException('Cannot update the status of a backup that is already marked as completed.');
|
||||
}
|
||||
|
||||
$action = $request->boolean('successful') ? 'server:backup.complete' : 'server:backup.failed';
|
||||
$action = $request->boolean('successful') ? 'server:backup.complete' : 'server:backup.fail';
|
||||
$log = Activity::event($action)->subject($model, $model->server)->property('name', $model->name);
|
||||
|
||||
$log->transaction(function () use ($model, $request) {
|
||||
|
|
|
@ -72,7 +72,7 @@ class LoginController extends AbstractLoginController
|
|||
return $this->sendLoginResponse($user, $request);
|
||||
}
|
||||
|
||||
Activity::event('login.checkpoint')->withRequestMetadata()->subject($user)->log();
|
||||
Activity::event('auth:checkpoint')->withRequestMetadata()->subject($user)->log();
|
||||
|
||||
$request->session()->put('auth_confirmation_token', [
|
||||
'user_id' => $user->id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue