for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @link https://github.com/vuongxuongminh/yii2-mfa
* @copyright Copyright (c) 2019 Vuong Xuong Minh
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
*/
namespace vxm\mfa;
use yii\base\InvalidCallException;
use yii\base\Widget;
use yii\helpers\Html;
* Class QrCodeWidget provide a qr code for authenticator like google authenticator of current logged in user.
*
* @author Vuong Minh <[email protected]>
* @since 1.0.0
class QrCodeWidget extends Widget
{
use EnsureUserBehaviorAttachedTrait;
* @var array HTML img tag attributes.
public $options = [];
* @var string an issuer will show in authenticator application. If not set an application name will be use to set by default.
public $issuer;
* @var string a label will show in authenticator application.
public $label;
* @var string a image will show in authenticator application.
public $image;
* @inheritDoc
public function init()
$this->ensureUserBehaviorAttached();
parent::init();
}
* @throws InvalidCallException
public function run()
$params = [];
if ($this->issuer) {
$params['issuer'] = $this->issuer;
if ($this->label) {
$params['label'] = $this->label;
if ($this->image) {
$params['image'] = $this->image;
$uri = $this->user->getQrCodeUri($params);
if ($uri) {
return Html::img($uri, $this->options);
} else {
throw new InvalidCallException('Current user is guest, can not render qr code!');