add cors filter for mobileapi

This commit is contained in:
2022-02-25 22:59:01 +01:00
parent 530accd8bf
commit 24d67f56d8
5 changed files with 109 additions and 15 deletions

View File

@@ -31,15 +31,16 @@ class ActivatedFilter extends ActionFilter
// get the device
/** @var MobileDevice $mobileDevice */
$mobileDevice = \Yii::$app->user->getIdentity();
$deviceId = null;
if (isset($mobileDevice)) {
$deviceId = $mobileDevice->id;
$idCard = $mobileDevice->id_card;
// find out if the device is activated
$activated = $mobileDevice->status === MobileDevice::STATUS_ACTIVE;
}
// if device is not activated, throw exception with http status 412
if ($activated === false) {
throw new HttpException( HttpStatus::PRECONDITION_FAILED,"Device is not activated: " . $mobileDevice->id);
throw new HttpException( HttpStatus::PRECONDITION_FAILED,"Device is not activated: " . $deviceId);
}
} catch (HttpException $e) {
if ($e->statusCode === HttpStatus::PRECONDITION_FAILED && $this->isOptional($action)) {