Close #15 added two factor authentication

This commit is contained in:
Antonio Ramirez
2017-09-21 17:48:01 +02:00
parent 5ee4c91e03
commit 308b6a0b2c
15 changed files with 1596 additions and 737 deletions

View File

@ -0,0 +1,46 @@
<?php
namespace Da\User\Service;
use Da\TwoFA\Manager;
use Da\TwoFA\Service\QrCodeDataUriGeneratorService;
use Da\TwoFA\Service\TOTPSecretKeyUriGeneratorService;
use Da\User\Contracts\ServiceInterface;
use Da\User\Model\User;
use Yii;
class TwoFactorQrCodeUriGeneratorService implements ServiceInterface
{
/**
* @var User
*/
protected $user;
/**
* TwoFactorQrCodeUriGeneratorService constructor.
*
* @param User $user
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* @inheritdoc
*/
public function run()
{
$user = $this->user;
if (!$user->auth_tf_key) {
$user->auth_tf_key = (new Manager())->generateSecretKey();
$user->updateAttributes(['auth_tf_key']);
}
$totpUri = (new TOTPSecretKeyUriGeneratorService(Yii::$app->name, $user->email, $user->auth_tf_key))->run();
$dataUri = (new QrCodeDataUriGeneratorService($totpUri))->run();
return $dataUri;
}
}