<commit_before><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace App\Http\Middleware;

use App\Libraries\UserVerification;
use App\Models\User;
use Closure;
use Illuminate\Contracts\Auth\Guard as AuthGuard;
use Illuminate\Http\Request;

class VerifyUser
{
    protected ?User $user;

    public function __construct(AuthGuard $auth)
    {
        $this->user = $auth->user();
    }

    public function handle(Request $request, Closure $next)
    {
        if (
            $this->user !== null
            && !$this->user->isSessionVerified()
            && !$this->alwaysSkipVerification()
            && $this->requiresVerification($request)
        ) {
            return UserVerification::fromCurrentRequest()->initiate();
        }

        return $next($request);
    }

    public function requiresVerification($request)
    {
        return true;
    }

    private function alwaysSkipVerification()
    {
        $currentRouteData = app('route-section')->getCurrent();
        $currentRoute = "{$currentRouteData['controller']}@{$currentRouteData['action']}";

        static $routes = [
            'account_controller@reissue_code',
            'account_controller@verify',
            'account_controller@verify_link',
            'notifications_controller@endpoint',
            'sessions_controller@destroy',
            'sessions_controller@store',
            'wiki_controller@image',
            'wiki_controller@show',
            'wiki_controller@sitemap',
            'wiki_controller@suggestions',
        ];

        return in_array($currentRoute, $routes, true);
    }
}<commit_msg>Use array key lookup for verification route check<commit_after><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace App\Http\Middleware;

use App\Libraries\UserVerification;
use App\Models\User;
use Closure;
use Illuminate\Contracts\Auth\Guard as AuthGuard;
use Illuminate\Http\Request;

class VerifyUser
{
    const SKIP_VERIFICATION_ROUTES = [
        'account_controller@reissue_code' => true,
        'account_controller@verify' => true,
        'account_controller@verify_link' => true,
        'notifications_controller@endpoint' => true,
        'sessions_controller@destroy' => true,
        'sessions_controller@store' => true,
        'wiki_controller@image' => true,
        'wiki_controller@show' => true,
        'wiki_controller@sitemap' => true,
        'wiki_controller@suggestions' => true,
    ];

    protected ?User $user;

    public function __construct(AuthGuard $auth)
    {
        $this->user = $auth->user();
    }

    public function handle(Request $request, Closure $next)
    {
        if (
            $this->user !== null
            && !$this->user->isSessionVerified()
            && !$this->alwaysSkipVerification()
            && $this->requiresVerification($request)
        ) {
            return UserVerification::fromCurrentRequest()->initiate();
        }

        return $next($request);
    }

    public function requiresVerification($request)
    {
        return true;
    }

    private function alwaysSkipVerification()
    {
        $currentRouteData = app('route-section')->getCurrent();
        $currentRoute = "{$currentRouteData['controller']}@{$currentRouteData['action']}";

        return isset(static::SKIP_VERIFICATION_ROUTES[$currentRoute]);
    }
}
{'fraction_non_alphanumeric': 0.12102621305075292, 'fraction_numerical': 0.0011154489682097045, 'mean_word_length': 2.807855626326964, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, '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': '6626310', 'n_tokens_mistral': 1000, 'n_tokens_neox': 989, 'n_words': 209}