mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-08-14 07:48:37 +02:00
Fix migrations
This commit is contained in:
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Classes\Options;
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
@ -31,17 +30,18 @@ class SplitTwofaccountsUriInMultipleColumns extends Migration
|
|||||||
|
|
||||||
|
|
||||||
$twofaccounts = DB::table('twofaccounts')->select('id', 'legacy_uri')->get();
|
$twofaccounts = DB::table('twofaccounts')->select('id', 'legacy_uri')->get();
|
||||||
|
$settingService = resolve('App\Services\SettingServiceInterface');
|
||||||
|
|
||||||
foreach ($twofaccounts as $twofaccount) {
|
foreach ($twofaccounts as $twofaccount) {
|
||||||
try {
|
try {
|
||||||
$legacy_uri = Options::get('useEncryption') ? Crypt::decryptString($twofaccount->legacy_uri) : $twofaccount->legacy_uri;
|
$legacy_uri = $settingService->get('useEncryption') ? Crypt::decryptString($twofaccount->legacy_uri) : $twofaccount->legacy_uri;
|
||||||
$token = \OTPHP\Factory::loadFromProvisioningUri($legacy_uri);
|
$token = \OTPHP\Factory::loadFromProvisioningUri($legacy_uri);
|
||||||
|
|
||||||
$affected = DB::table('twofaccounts')
|
$affected = DB::table('twofaccounts')
|
||||||
->where('id', $twofaccount->id)
|
->where('id', $twofaccount->id)
|
||||||
->update([
|
->update([
|
||||||
'otp_type' => get_class($token) === 'OTPHP\TOTP' ? 'totp' : 'hotp',
|
'otp_type' => get_class($token) === 'OTPHP\TOTP' ? 'totp' : 'hotp',
|
||||||
'secret' => Options::get('useEncryption') ? Crypt::encryptString($token->getSecret()) : $token->getSecret(),
|
'secret' => $settingService->get('useEncryption') ? Crypt::encryptString($token->getSecret()) : $token->getSecret(),
|
||||||
'algorithm' => $token->getDigest(),
|
'algorithm' => $token->getDigest(),
|
||||||
'digits' => $token->getDigits(),
|
'digits' => $token->getDigits(),
|
||||||
'period' => $token->hasParameter('period') ? $token->getParameter('period') : null,
|
'period' => $token->hasParameter('period') ? $token->getParameter('period') : null,
|
||||||
|
@ -26,9 +26,6 @@ class ChangeAccountNotNullableTwofaccountsTable extends Migration
|
|||||||
*/
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
Schema::table('twofaccounts', function (Blueprint $table) {
|
//
|
||||||
$table->text('account')->nullable()->change();
|
|
||||||
$table->string('service')->nullable(false)->change();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user