Skip to content

Commit 33fe359

Browse files
committed
TwoFactorAuthenticationController - Small pick - Using Coalescing operator instead of ternery operator now.
1 parent 867a608 commit 33fe359

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

database/migrations/2017_03_18_000012_add_two_factor_authentication_required_fields.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function up()
1515
{
1616
Schema::table('users', function (Blueprint $table) {
1717
$table->smallInteger('is_two_factor_enabled')->default(0)->before('create_at');
18-
$table->string('two_factor_secret_key')->nullable()->after('is_2fa_enabled');
18+
$table->string('two_factor_secret_key')->nullable()->default(null)->after('is_2fa_enabled');
1919
});
2020
}
2121

src/Http/Controllers/TwoFactorAuthenticationController.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,18 @@ class TwoFactorAuthenticationController extends Controller implements TwoFactorA
2323
public function setupTwoFactorAuthentication(Request $request)
2424
{
2525
$user = User::find($request->user()->id);
26-
$user->two_factor_secret_key !== '' ? $secret_key = $user->two_factor_secret_key : $secret_key = $this->base32EncodedString(config('2fa-config.number_of_digits'));
27-
$user->two_factor_secret_key = $secret_key;
26+
$user->two_factor_secret_key = $user->two_factor_secret_key ?? $this->base32EncodedString(config('2fa-config.number_of_digits'));
2827
$user->update();
28+
2929
$totp = new TOTP(
3030
config('2fa-config.account_name'),
31-
$secret_key,
31+
$user->two_factor_secret_key,
3232
10,
3333
config('2fa-config.digest_algorithm'),
3434
config('2fa-config.number_of_digits')
3535
);
3636

3737
$barcode = $totp->getQrCodeUri();
38-
3938
return view('2fa::setup', compact('barcode', 'user'));
4039
}
4140

@@ -66,7 +65,7 @@ public function disableTwoFactorAuthentication(Request $request)
6665
{
6766
$user = User::find($request->user()->id);
6867
$user->is_two_factor_enabled = 0;
69-
$user->two_factor_secret_key = '';
68+
$user->two_factor_secret_key = null;
7069
$user->update();
7170

7271
return redirect('home');

0 commit comments

Comments
 (0)