diff --git a/app/Console/Commands/UpdateKey.php b/app/Console/Commands/UpdateKey.php index 4bf51c28ef2e..1c2d21eb5a30 100644 --- a/app/Console/Commands/UpdateKey.php +++ b/app/Console/Commands/UpdateKey.php @@ -6,7 +6,9 @@ use Illuminate\Console\Command; use Symfony\Component\Console\Input\InputOption; use App\Models\AccountGateway; use App\Models\BankAccount; +use App\Models\User; use Artisan; +use Crypt; use Illuminate\Encryption\Encrypter; use Laravel\LegacyEncrypter\McryptEncrypter; @@ -42,6 +44,7 @@ class UpdateKey extends Command // load the current values $gatewayConfigs = []; $bankUsernames = []; + $twoFactorSecrets = []; foreach (AccountGateway::all() as $gateway) { if ($legacy) { @@ -59,6 +62,14 @@ class UpdateKey extends Command } } + foreach (User::where('google_2fa_secret', '!=', '')->get() as $user) { + if ($legacy) { + $twoFactorSecrets[$user->id] = $legacy->decrypt($user->google_2fa_secret); + } else { + $twoFactorSecrets[$user->id] = Crypt::decrypt($user->google_2fa_secret); + } + } + // check if we can write to the .env file $envPath = base_path() . '/.env'; $envWriteable = file_exists($envPath) && @fopen($envPath, 'a'); @@ -86,6 +97,12 @@ class UpdateKey extends Command $bank->save(); } + foreach (User::where('google_2fa_secret', '!=', '')->get() as $user) { + $secret = $twoFactorSecrets[$user->id]; + $user->google_2fa_secret = $crypt->encrypt($secret); + $user->save(); + } + $message = date('r') . ' Successfully updated '; if ($envWriteable) { if ($legacy) { diff --git a/app/Ninja/Repositories/AccountRepository.php b/app/Ninja/Repositories/AccountRepository.php index 4b5de57d4b3f..36ce1564d5c3 100644 --- a/app/Ninja/Repositories/AccountRepository.php +++ b/app/Ninja/Repositories/AccountRepository.php @@ -510,7 +510,7 @@ class AccountRepository public function registerNinjaUser($user) { - if ($user->email == TEST_USERNAME) { + if (! $user || $user->email == TEST_USERNAME) { return false; }