| Total Complexity | 8 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class VerifyTwoFactorOtp |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Handle the incoming request. |
||
| 16 | * |
||
| 17 | * @param Request $request |
||
|
|
|||
| 18 | * @param Closure $next |
||
| 19 | * @return void |
||
| 20 | */ |
||
| 21 | public function handle($request, Closure $next) |
||
| 22 | { |
||
| 23 | if ($this->is2faEnabled()) { |
||
| 24 | $user = Auth::user(); |
||
| 25 | if ($user->otp_expiry > Carbon::now()) { |
||
| 26 | return $next($request); |
||
| 27 | } |
||
| 28 | |||
| 29 | $user->otp_token = Rakshak::generateOtp(); |
||
| 30 | $user->save(); |
||
| 31 | |||
| 32 | Rakshak::sendOtp($user); |
||
| 33 | |||
| 34 | return redirect(Rakshak::verifyOtpPath()); |
||
| 35 | } |
||
| 36 | |||
| 37 | return $next($request); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Determine whether the 2fa is enabled for the current user. |
||
| 42 | * |
||
| 43 | * @return bool |
||
| 44 | */ |
||
| 45 | private function is2faEnabled() |
||
| 57 | } |
||
| 58 | } |
||
| 60 |