Skip to content

Commit

Permalink
Fix #71 - Cannot view old TOTP entries on latest Docker Image
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubka committed May 11, 2022
1 parent a75ea1b commit 42c3bd8
Showing 1 changed file with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ class ChangeNullableInTwofaccountsTable extends Migration
*/
public function up()
{
Schema::table('twofaccounts', function (Blueprint $table) {
$table->text('account')->nullable(false)->change();
$table->string('service')->nullable()->change();
$table->string('otp_type', 10)->nullable(false)->change();
$table->text('secret')->nullable(false)->change();
$table->string('algorithm', 20)->nullable(false)->change();
$table->unsignedSmallInteger('digits')->nullable(false)->change();
});


$twofaccounts = DB::table('twofaccounts')->select('id', 'legacy_uri')->get();
$settingService = resolve('App\Services\SettingService');

Expand All @@ -48,8 +38,39 @@ public function up()
catch(Exception $ex)
{
Log::error($ex->getMessage());
Log::error("TwoFAccount with id #" . $twofaccount->id . " could not be splited");
}
}

$twofaccounts = DB::table('twofaccounts')
->whereNull('account')
->orWhereNull('otp_type')
->orWhereNull('secret')
->orWhereNull('algorithm')
->orWhereNull('digits')
->get();

foreach ($twofaccounts as $twofaccount) {

$affected = DB::table('twofaccounts')
->where('id', $twofaccount->id)
->update([
'account' => $twofaccount->account === null ? 'account (invalid)' : $twofaccount->account + ' (invalid)',
'otp_type' => $twofaccount->otp_type === null ? 'totp' : $twofaccount->otp_type,
'secret' => $twofaccount->secret === null ? 'secret' : $twofaccount->secret,
'algorithm' => $twofaccount->algorithm === null ? 'sha1' : $twofaccount->algorithm,
'digits' => $twofaccount->digits === null ? 6 : $twofaccount->digits,
]);
}

Schema::table('twofaccounts', function (Blueprint $table) {
$table->text('account')->nullable(false)->change();
$table->string('service')->nullable()->change();
$table->string('otp_type', 10)->nullable(false)->change();
$table->text('secret')->nullable(false)->change();
$table->string('algorithm', 20)->nullable(false)->change();
$table->unsignedSmallInteger('digits')->nullable(false)->change();
});
}

/**
Expand Down

0 comments on commit 42c3bd8

Please sign in to comment.