<commit_before><?php

declare(strict_types=1);

namespace Cortex\Fort\Http\Middleware;

use Closure;

class Reauthenticate
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request  $request
     * @param \Closure                  $next
     * @param string                    $type
     * @param string|null               $session_name
     * @param int|null                  $timeout
     * @param bool                      $renew
     *
     * @return mixed
     */
    public function handle($request, Closure $next, $type='password', $session_name=null, $timeout=null, $renew=false)
    {

        $timeout = $timeout ?? config('cortex.fort.reauthentication.timeout');

        if( is_null($session_name) || empty($session_name) ) {
            $session_name = 'cortex.fort.reauthentication.'.$request->route()->getName();
        } else {
            $session_name = 'cortex.fort.reauthentication.'.$session_name;
        }

        if( is_null( session( $session_name ) ) || time() - session( $session_name ) >= $timeout ) {

            session()->forget( $session_name );
            session()->put('rinvex.fort.twofactor.totp', true);
            session()->put('cortex.fort.reauthentication.intended', $request->url());
            session()->put('cortex.fort.reauthentication.session_name', $session_name);

            return view('cortex/fort::frontarea.common.reauthentication.'.$type);
        }

        if( $renew ) {
            session()->put($session_name, time());
        }

        return $next($request);
    }
}<commit_msg>Clean & simplify Reauthenticate middleware<commit_after><?php

declare(strict_types=1);

namespace Cortex\Fort\Http\Middleware;

use Closure;

class Reauthenticate
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure                 $next
     * @param string                   $type
     * @param int                      $timeout
     * @param bool                     $renew
     *
     * @return mixed
     */
    public function handle($request, Closure $next, $type = 'password', $timeout = null, $renew = false)
    {
        $timeout = $timeout ?? config('cortex.fort.reauthentication.timeout');
        $session_name = 'cortex.fort.reauthentication.'.$request->route()->getName();
       
        if(is_null(session($session_name)) || time() - session($session_name) >= $timeout) {
            session()->forget($session_name);
            session()->put('cortex.fort.reauthentication.intended', $request->url());
            session()->put('cortex.fort.reauthentication.session_name', $session_name);

            return view('cortex/fort::frontarea.common.reauthentication.'.$type);
        }

        ! $renew || session()->put($session_name, time());

        return $next($request);
    }
}
{'fraction_non_alphanumeric': 0.148109243697479, 'fraction_numerical': 0.0007002801120448179, 'mean_word_length': 2.2539863325740317, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3090685', 'n_tokens_mistral': 842, 'n_tokens_neox': 799, 'n_words': 140}