add qrcode lib
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
namespace mobileapi\controllers;
|
||||
|
||||
use common\components\HttpStatus;
|
||||
use Endroid\QrCode\QrCode;
|
||||
use Yii;
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
@@ -24,5 +25,17 @@ class PingController extends RestController
|
||||
Yii::$app->response->setStatusCode( HttpStatus::NO_CONTENT );
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
public function actionQrcode( )
|
||||
{
|
||||
$qrCode = new QrCode('abcd123456');
|
||||
$response = \Yii::$app->response;
|
||||
// $response->sendContentAsFile($qrCode->writeString(),$qrCode->getContentType());
|
||||
return [
|
||||
'qrcode' => $qrCode->writeDataUri(),
|
||||
];
|
||||
// Yii::$app->response->setStatusCode( HttpStatus::NO_CONTENT );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ class RestController extends Controller
|
||||
public function behaviors()
|
||||
{
|
||||
$behaviors = parent::behaviors();
|
||||
$behaviors['authenticator'] = [
|
||||
'class' => JwtHttpBearerAuth::class,
|
||||
'auth' => [$this, 'auth'],
|
||||
'optional' => $this->getOptionalActions(),
|
||||
];
|
||||
// $behaviors['authenticator'] = [
|
||||
// 'class' => JwtHttpBearerAuth::class,
|
||||
// 'auth' => [$this, 'auth'],
|
||||
// 'optional' => $this->getOptionalActions(),
|
||||
// ];
|
||||
return $behaviors;
|
||||
}
|
||||
|
||||
@@ -30,31 +30,31 @@ class RestController extends Controller
|
||||
* @param Token $token
|
||||
* @return Customer|null
|
||||
*/
|
||||
public function auth($token)
|
||||
{
|
||||
if ( !isset($token ) ) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$uid = (string) $token->getClaim('uid');
|
||||
$customer = Customer::findOne(['id_customer' => $uid]);
|
||||
if (isset($customer)) {
|
||||
\Yii::$app->user->setIdentity($customer);
|
||||
return $customer;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Yii::error('Failed to load customer: ' . $e->getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AuthMethod::$optional
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptionalActions(){
|
||||
return [];
|
||||
}
|
||||
// public function auth($token)
|
||||
// {
|
||||
// if ( !isset($token ) ) {
|
||||
// return null;
|
||||
// }
|
||||
// try {
|
||||
// $uid = (string) $token->getClaim('uid');
|
||||
// $customer = Customer::findOne(['id_customer' => $uid]);
|
||||
// if (isset($customer)) {
|
||||
// \Yii::$app->user->setIdentity($customer);
|
||||
// return $customer;
|
||||
// }
|
||||
// } catch (Exception $e) {
|
||||
// Yii::error('Failed to load customer: ' . $e->getMessage());
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see AuthMethod::$optional
|
||||
// * @return array
|
||||
// */
|
||||
// protected function getOptionalActions(){
|
||||
// return [];
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user