Merge branch 'develop' into feature/vuejs

This commit is contained in:
Dane Everitt 2019-05-01 20:57:49 -07:00
commit 5c99cae779
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
8 changed files with 187 additions and 30 deletions

View file

@ -9,21 +9,27 @@
namespace Pterodactyl\Services\Users;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Pterodactyl\Models\User;
use PragmaRX\Google2FA\Google2FA;
use PragmaRX\Google2FAQRCode\Google2FA;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Encryption\Encrypter;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
class TwoFactorSetupService
{
/**
* @var \Illuminate\Contracts\Config\Repository
*/
private $config;
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
private $encrypter;
/**
* @var \PragmaRX\Google2FA\Google2FA
* @var PragmaRX\Google2FAQRCode\Google2FA
*/
private $google2FA;
@ -35,15 +41,18 @@ class TwoFactorSetupService
/**
* TwoFactorSetupService constructor.
*
* @param \Illuminate\Contracts\Config\Repository $config
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
* @param \PragmaRX\Google2FA\Google2FA $google2FA
* @param PragmaRX\Google2FAQRCode\Google2FA $google2FA
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
*/
public function __construct(
ConfigRepository $config,
Encrypter $encrypter,
Google2FA $google2FA,
UserRepositoryInterface $repository
) {
$this->config = $config;
$this->encrypter = $encrypter;
$this->google2FA = $google2FA;
$this->repository = $repository;
@ -61,8 +70,8 @@ class TwoFactorSetupService
*/
public function handle(User $user): Collection
{
$secret = $this->google2FA->generateSecretKey(config('pterodactyl.auth.2fa.bytes'));
$image = $this->google2FA->getQRCodeGoogleUrl(config('app.name'), $user->email, $secret);
$secret = $this->google2FA->generateSecretKey($this->config->get('pterodactyl.auth.2fa.bytes'));
$image = $this->google2FA->getQRCodeInline($this->config->get('app.name'), $user->email, $secret);
$this->repository->withoutFreshModel()->update($user->id, [
'totp_secret' => $this->encrypter->encrypt($secret),