2020-08-20 23:07:55 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
final class FingerprintPutController extends AbstractController
|
|
|
|
{
|
|
|
|
protected string $route = '/api/v1/fingerprint/{fingerprintId}';
|
2020-08-21 22:47:49 +02:00
|
|
|
protected array $mandatoryAttributes = [
|
|
|
|
'fingerprint',
|
|
|
|
];
|
2020-08-20 23:07:55 +02:00
|
|
|
|
|
|
|
private int $fingerprintId;
|
|
|
|
|
|
|
|
public function __construct(string $url)
|
|
|
|
{
|
|
|
|
parent::__construct($url);
|
|
|
|
|
|
|
|
$this->fingerprintId = (int)$this->getUrlParamInt('fingerprintId');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle(): void
|
|
|
|
{
|
2020-08-23 11:44:12 +02:00
|
|
|
if (!$this->isUserLoggedIn()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-20 23:07:55 +02:00
|
|
|
parent::handle();
|
|
|
|
|
|
|
|
$this->response = new ApiJsonResponse();
|
|
|
|
|
|
|
|
try {
|
|
|
|
$fingerprint = new Fingerprint($this->fingerprintId);
|
|
|
|
|
2020-09-10 11:46:31 +02:00
|
|
|
if ($this->hasUserPermission($fingerprint->getUserId()) && $this->handleFingerprint($fingerprint)) {
|
2020-08-20 23:07:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->response->setMessage('Fingerprint did not differ from the stored. Nothing changed.');
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
$this->response->setStatus(ServerStatus::BAD_REQUEST);
|
|
|
|
$this->response->setParameter('success', false);
|
|
|
|
$this->response->setMessage($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-24 22:19:46 +02:00
|
|
|
public function handleFingerprint(Fingerprint $fingerprint): bool
|
2020-08-20 23:07:55 +02:00
|
|
|
{
|
2020-08-24 22:19:46 +02:00
|
|
|
if ($fingerprint->getFingerprint() !== $this->jsonBody->fingerprint) {
|
|
|
|
$fingerprint->setFingerprint($this->jsonBody->fingerprint);
|
|
|
|
$fingerprint->Save();
|
2020-08-20 23:07:55 +02:00
|
|
|
|
2020-08-24 22:19:46 +02:00
|
|
|
return true;
|
2020-08-20 23:07:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|