<commit_before><?php

/*
 * NOTICE OF LICENSE
 *
 * Part of the Rinvex Fort Package.
 *
 * This source file is subject to The MIT License (MIT)
 * that is bundled with this package in the LICENSE file.
 *
 * Package: Rinvex Fort Package
 * License: The MIT License (MIT)
 * Link:    https://rinvex.com
 */

namespace Rinvex\Fort\Http\Controllers\Frontend;

use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;
use Illuminate\Database\Eloquent\Builder;
use Rinvex\Fort\Contracts\UserRepositoryContract;

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 \Rinvex\Fort\Contracts\UserRepositoryContract $userRepository
     *
     * @return \Illuminate\Http\Response
     */
    public function handleGithubCallback(Request $request, UserRepositoryContract $userRepository)
    {
        try {
            $githubUser = Socialite::driver('github')->user();
        } catch (Exception $e) {
            return intend([
                'route' => 'rinvex.fort.frontend.auth.social.github',
            ]);
        }

        $user = app('rinvex.fort.user')->whereHas('socialites', function (Builder $query) use ($githubUser) {
            $query->where('provider', 'github')->where('provider_uid', $githubUser->id);
        })->first();

        if (! $user) {
            // Prepare registration data
            $input = $request->except(['_method', '_token']) + [
                'email'    => $githubUser->email,
                'username' => $githubUser->username,
                'password' => <PASSWORD>(),
                'active'   => ! config('rinvex.fort.registration.moderated'),
            ];

            // Fire the register start event<commit_msg>fix for social auth<commit_after><?php

/*
 * NOTICE OF LICENSE
 *
 * Part of the Rinvex Fort Package.
 *
 * This source file is subject to The MIT License (MIT)
 * that is bundled with this package in the LICENSE file.
 *
 * Package: Rinvex Fort Package
 * License: The MIT License (MIT)
 * Link:    https://rinvex.com
 */

namespace Rinvex\Fort\Http\Controllers\Frontend;

use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;
use Illuminate\Database\Eloquent\Builder;
use Rinvex\Fort\Contracts\UserRepositoryContract;

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 \Rinvex\Fort\Contracts\UserRepositoryContract $userRepository
     *
     * @return \Illuminate\Http\Response
     */
    public function handleGithubCallback(Request $request, UserRepositoryContract $userRepository)
    {
        try {
            $githubUser = Socialite::driver('github')->user();
        } catch (Exception $e) {
            return intend([
                'route' => 'rinvex.fort.frontend.auth.social.github',
            ]);
        }

        $user = app('rinvex.fort.user')->findWhereHas(['socialites', function ($query) use ($githubUser) {
			$query->where('provider', 'github');
			$query->where('provider_uid', $githubUser->id);
		}])->first();

        if (! $user) {
            // Prepare registration data
            $input = $request->except(['_method', '_token']) + [
                'email'    => $githubUser->email,
                'username' => $githubUser->username,
                'password' => <PASSWORD>(),
                'active'   => ! config('rinvex.fort.registration.moderated'),
            ];

            // Fire the register start event
{'fraction_non_alphanumeric': 0.12884888678351492, 'fraction_numerical': 0.0, 'mean_word_length': 2.4728618421052633, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, 'https://': 2, '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': '4895675', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1154, 'n_words': 264}