<commit_before><?php

declare(strict_types=1);

namespace Cortex\Fort\Http\Controllers\Frontend;

use Exception;
use Cortex\Fort\Models\Role;
use Cortex\Fort\Models\User;
use Illuminate\Http\Request;
use Laravel\Socialite\Facades\Socialite;

class SocialAuthenticationController extends AuthenticationController
{
    /**
     * Redirect to Github for authentication.
     *
     * @return \Illuminate\Http\Response
     */
    public function redirectToGithub()
    {
        return Socialite::driver('github')->redirect();
    }

    /**
     * Handle Github authentication callback.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Cortex\Fort\Models\User $user
     *
     * @return \Illuminate\Http\Response
     */
    public function handleGithubCallback(Request $request, User $user)
    {
        try {
            $githubUser = Socialite::driver('github')->user();
        } catch (Exception $e) {
            return intend([
                'url' => route('frontend.auth.social.github'),
            ]);
        }

        $result = User::whereHas(['socialites', function ($query) use ($githubUser) {
            $query->where('provider', 'github');
            $query->where('provider_uid', $githubUser->id);
        }])->first();

        if (! $result) {
            // Prepare registration data
            $data = [
                'email' => $githubUser->email,
                'username' => $githubUser->username,
                'password' => <PASSWORD>(),
                'is_active' => ! config('rinvex.fort.registration.moderated'),
            ];

            // Fire the register start event
            event('rinvex.fort.register.social.start', [$data]);

            // Create user
            $result = $user->create($data);

            // Attach default role to the registered user
            if ($defaultRole = config('rinvex.fort.registration.default_role')) {
                if ($defaultRole = Role::where('slug', $defaultRole)->first()) {
                    $result->roles()->attach($defaultRole);<commit_msg>Enforce consistent eloquent builder usage<commit_after><?php

declare(strict_types=1);

namespace Cortex\Fort\Http\Controllers\Frontend;

use Exception;
use Cortex\Fort\Models\Role;
use Cortex\Fort\Models\User;
use Illuminate\Http\Request;
use Laravel\Socialite\Facades\Socialite;
use Illuminate\Database\Eloquent\Builder;

class SocialAuthenticationController extends AuthenticationController
{
    /**
     * Redirect to Github for authentication.
     *
     * @return \Illuminate\Http\Response
     */
    public function redirectToGithub()
    {
        return Socialite::driver('github')->redirect();
    }

    /**
     * Handle Github authentication callback.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Cortex\Fort\Models\User $user
     *
     * @return \Illuminate\Http\Response
     */
    public function handleGithubCallback(Request $request, User $user)
    {
        try {
            $githubUser = Socialite::driver('github')->user();
        } catch (Exception $e) {
            return intend([
                'url' => route('frontend.auth.social.github'),
            ]);
        }

        $result = User::whereHas(['socialites', function (Builder $builder) use ($githubUser) {
            $builder->where('provider', 'github');
            $builder->where('provider_uid', $githubUser->id);
        }])->first();

        if (! $result) {
            // Prepare registration data
            $data = [
                'email' => $githubUser->email,
                'username' => $githubUser->username,
                'password' => <PASSWORD>(),
                'is_active' => ! config('rinvex.fort.registration.moderated'),
            ];

            // Fire the register start event
            event('rinvex.fort.register.social.start', [$data]);

            // Create user
            $result = $user->create($data);

            // Attach default role to the registered user
            if ($defaultRole = config('rinvex.fort.registration.default_role')) {
                if ($defaultRole = Role::where('slug', $defaultRole)->first()) {
                    $result->roles()->attach($defaultRole);
{'fraction_non_alphanumeric': 0.14035087719298245, 'fraction_numerical': 0.000474158368895211, 'mean_word_length': 2.2034927866362946, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, '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': '1462763', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1123, 'n_words': 224}