thinkstudeo /
laravel-rakshak
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Thinkstudeo\Rakshak\Http\Controllers; |
||
| 4 | |||
| 5 | use Illuminate\Http\Request; |
||
| 6 | use Illuminate\Support\Carbon; |
||
| 7 | |||
| 8 | class TwoFactorController extends Controller |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Show the form to confirm the otp. |
||
| 12 | * |
||
| 13 | * @return View |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 14 | */ |
||
| 15 | public function showOtpForm() |
||
| 16 | { |
||
| 17 | return view('rakshak::otp.verify'); |
||
|
0 ignored issues
–
show
|
|||
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Verify the otp entered by the user with the value from the database. |
||
| 22 | * When verified redirect the user to the intended page. |
||
| 23 | * |
||
| 24 | * @param Request $request |
||
| 25 | * @return void |
||
| 26 | */ |
||
| 27 | public function verifyOtp(Request $request) |
||
| 28 | { |
||
| 29 | $request->validate(['otp' => 'required']); |
||
| 30 | $user = auth()->user(); |
||
| 31 | if ($request->otp === $user->otp_token) { |
||
| 32 | $user->otp_expiry = Carbon::now()->addMinutes(config('session.lifetime')); |
||
| 33 | $user->save(); |
||
| 34 | |||
| 35 | return redirect($request->session()->previousUrl()); |
||
|
0 ignored issues
–
show
|
|||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 |