use mobiledevice as login object for mobile api

This commit is contained in:
2022-02-22 14:41:16 +01:00
parent 356fc1f0fd
commit 530accd8bf
8 changed files with 90 additions and 71 deletions

View File

@@ -3,7 +3,7 @@
namespace mobileapi\components;
use common\components\HttpStatus;
use common\manager\MobileDeviceManager;
use common\models\MobileDevice;
use Yii;
use yii\base\Action;
@@ -28,18 +28,18 @@ class ActivatedFilter extends ActionFilter
try {
$activated = false;
// get the customer
$customer = \Yii::$app->user->getIdentity();
if (isset($customer)) {
$idCard = $customer->id_customer_card;
// get the device
/** @var MobileDevice $mobileDevice */
$mobileDevice = \Yii::$app->user->getIdentity();
if (isset($mobileDevice)) {
$idCard = $mobileDevice->id_card;
// find out if the device is activated
$mobileDeviceManager = new MobileDeviceManager();
$activated = $mobileDeviceManager->isMobileDeviceActivatedByIdCard($idCard);
$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,"Card not activated");
throw new HttpException( HttpStatus::PRECONDITION_FAILED,"Device is not activated: " . $mobileDevice->id);
}
} catch (HttpException $e) {
if ($e->statusCode === HttpStatus::PRECONDITION_FAILED && $this->isOptional($action)) {