Skip to content

Commit 5e9204d

Browse files
committed
WIP - 2FA Setup, Enable and disable can now be done using api call. #13
1 parent 28ff6d5 commit 5e9204d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Http/Controllers/TwoFactorAuthenticationController.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public function setupTwoFactorAuthentication(Request $request)
3535
);
3636

3737
$barcode = $totp->getQrCodeUri();
38+
39+
// Return Barcode image if ajax Request
40+
if($request->ajax())
41+
{
42+
return $barcode;
43+
}
3844
return view('2fa::setup', compact('barcode', 'user'));
3945
}
4046

@@ -51,6 +57,14 @@ public function enableTwoFactorAuthentication(Request $request)
5157
$user->is_two_factor_enabled = 1;
5258
$user->update();
5359

60+
if ($request-ajax()) {
61+
return [
62+
'data' => [
63+
'message' => 'success',
64+
'description' => '2FA Enabled'
65+
]
66+
];
67+
}
5468
return redirect('home');
5569
}
5670

@@ -68,6 +82,14 @@ public function disableTwoFactorAuthentication(Request $request)
6882
$user->two_factor_secret_key = null;
6983
$user->update();
7084

85+
if ($request-ajax()) {
86+
return [
87+
'data' => [
88+
'message' => 'success',
89+
'description' => '2FA Disabled'
90+
]
91+
];
92+
}
7193
return redirect('home');
7294
}
7395

0 commit comments

Comments
 (0)