use mobiledevice as login object for mobile api
This commit is contained in:
@@ -30,7 +30,7 @@ class LoginController extends RestController
|
||||
$form->load(\Yii::$app->request->post(), '');
|
||||
|
||||
if (!$form->validate()) {
|
||||
throw new BadRequestHttpException("Hibás e-mail cím vagy jelszó!");
|
||||
throw new BadRequestHttpException("Hibás bejelentkezés " . print_r($form->getErrors( ),true));
|
||||
}
|
||||
|
||||
/** @var Jwt $jwt */
|
||||
@@ -47,7 +47,7 @@ class LoginController extends RestController
|
||||
->identifiedBy('A989C57D19E2AF756BA9585AC4CFAF7974AE3D2BCA7CCA7307B39AB28CC7C2C8', true)// Configures the id (jti claim), replicating as a header item
|
||||
->issuedAt($time)// Configures the time that the token was issue (iat claim)
|
||||
->expiresAt($time + $validFor)// Configures the expiration time of the token (exp claim)
|
||||
->withClaim('uid', $form->getCustomer()->getId())// Configures a new claim, called "uid"
|
||||
->withClaim('uid', $form->getMobileDevice()->getId())// Configures a new claim, called "uid"
|
||||
->getToken($signer, $key); // Retrieves the generated token
|
||||
|
||||
return $this->asJson([
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace mobileapi\controllers;
|
||||
|
||||
|
||||
use common\models\Customer;
|
||||
use common\models\MobileDevice;
|
||||
use Exception;
|
||||
use Lcobucci\JWT\Token;
|
||||
use mobileapi\components\ActivatedFilter;
|
||||
@@ -33,7 +34,7 @@ class RestController extends Controller
|
||||
/**
|
||||
* This method will check the token
|
||||
* @param Token $token
|
||||
* @return Customer|null
|
||||
* @return MobileDevice|null
|
||||
*/
|
||||
public function auth($token)
|
||||
{
|
||||
@@ -42,13 +43,13 @@ class RestController extends Controller
|
||||
}
|
||||
try {
|
||||
$uid = (string) $token->getClaim('uid');
|
||||
$customer = Customer::findOne(['id_customer' => $uid]);
|
||||
if (isset($customer)) {
|
||||
\Yii::$app->user->setIdentity($customer);
|
||||
return $customer;
|
||||
$mobileDevice = MobileDevice::findOne(['id' => $uid]);
|
||||
if (isset($mobileDevice)) {
|
||||
\Yii::$app->user->setIdentity($mobileDevice);
|
||||
return $mobileDevice;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Yii::error('Failed to load customer: ' . $e->getMessage());
|
||||
Yii::error('Failed to load mobile device: ' . $e->getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user