use mobiledevice as login object for mobile api
This commit is contained in:
@@ -7,7 +7,6 @@ use common\models\Customer;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\db\ActiveRecord;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
@@ -19,10 +18,10 @@ class LoginForm extends Model
|
||||
{
|
||||
// cardnumber
|
||||
public $cardNumber;
|
||||
public $deviceId;
|
||||
public $deviceIdentifier;
|
||||
public $deviceName;
|
||||
|
||||
public $customer;
|
||||
public $mobileDevice;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -31,20 +30,12 @@ class LoginForm extends Model
|
||||
{
|
||||
return [
|
||||
// username and password are both required
|
||||
[['cardNumber', 'deviceId','deviceName'], 'required'],
|
||||
[['cardNumber', 'deviceIdentifier', 'deviceName'], 'required'],
|
||||
// cardNumber is validated by validatePassword()
|
||||
['cardNumber', 'validateCardNumber'],
|
||||
];
|
||||
}
|
||||
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'username' => Yii::t('common/site', 'Username'),
|
||||
'password' => Yii::t('common/site', 'Password'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the password.
|
||||
* This method serves as the inline validation for password.
|
||||
@@ -55,11 +46,11 @@ class LoginForm extends Model
|
||||
*/
|
||||
public function validateCardNumber($attribute, $params)
|
||||
{
|
||||
if ($this->hasErrors()) {
|
||||
if (!$this->hasErrors()) {
|
||||
/** @var \common\models\Customer $user */
|
||||
throw new BadRequestHttpException();
|
||||
$this->getMobileDevice();
|
||||
|
||||
}
|
||||
$customer = $this->getCustomer();
|
||||
}
|
||||
|
||||
|
||||
@@ -68,21 +59,17 @@ class LoginForm extends Model
|
||||
*
|
||||
* @return Customer|null|ActiveRecord
|
||||
*/
|
||||
public function getCustomer()
|
||||
public function getMobileDevice()
|
||||
{
|
||||
|
||||
if ($this->customer === null) {
|
||||
if ($this->mobileDevice === null) {
|
||||
$mobileDeviceManager = new MobileDeviceManager();
|
||||
$mobileDevice = $mobileDeviceManager->loginOrCreate($this->cardNumber, $this->deviceId, $this->deviceName);
|
||||
/** @var Customer */
|
||||
$this->customer = Customer::find()->andWhere([
|
||||
'id_customer_card' => $mobileDevice->id_card
|
||||
])->one();
|
||||
if ($this->customer == null) {
|
||||
$this->mobileDevice = $mobileDeviceManager->loginOrCreate($this->cardNumber, $this->deviceIdentifier, $this->deviceName);
|
||||
if ($this->mobileDevice === null) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->customer;
|
||||
return $this->mobileDevice;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user