use mobiledevice as login object for mobile api
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user