<commit_before><?php

namespace Project\Base\Controller\auth\google;

use Project\Base\Session;

class callback
{
    public function doGet($view, $params)
    { 
        $this->validate();

        // Try to get an access token (using the authorization code grant)
        $code = filter_input(INPUT_GET, 'code');
        $provider = $this->getProvider();
        $token = $provider->getAccessToken('authorization_code', ['code' => $code]);

        // Optional: Now you have a token you can look up a users profile data
        // We got an access token, let's now get the owner details
        $ownerDetails = $provider->getResourceOwner($token);

        $id = $ownerDetails->getID();
        $user = \Project\Base\Mongo::findDoc("users", ['id' => $id]);
        if ($user == null) $user = new \Project\Base\MongoDoc("users");

        $user->set("id", $id);
        $user->set("name", $ownerDetails->getName());
        $user->set("email", $ownerDetails->getEmail());
        $user->set("image", $ownerDetails->getAvatar());
        $user->set("oauth2", "google");
        $user->save();

        Session::getSession()->set("userID", $id);
        $view->redirect('/', 302);
    }

    private function validate()
    {
        $session = Session::getSession();<commit_msg>passing view through<commit_after><?php

namespace Project\Base\Controller\auth\google;

use Project\Base\Session;

class callback
{
    public function doGet($view, $params)
    { 
        $this->validate($view);

        // Try to get an access token (using the authorization code grant)
        $code = filter_input(INPUT_GET, 'code');
        $provider = $this->getProvider();
        $token = $provider->getAccessToken('authorization_code', ['code' => $code]);

        // Optional: Now you have a token you can look up a users profile data
        // We got an access token, let's now get the owner details
        $ownerDetails = $provider->getResourceOwner($token);

        $id = $ownerDetails->getID();
        $user = \Project\Base\Mongo::findDoc("users", ['id' => $id]);
        if ($user == null) $user = new \Project\Base\MongoDoc("users");

        $user->set("id", $id);
        $user->set("name", $ownerDetails->getName());
        $user->set("email", $ownerDetails->getEmail());
        $user->set("image", $ownerDetails->getAvatar());
        $user->set("oauth2", "google");
        $user->save();

        Session::getSession()->set("userID", $id);
        $view->redirect('/', 302);
    }

    private function validate($view)
    {
        $session = Session::getSession();
{'fraction_non_alphanumeric': 0.17644772638942868, 'fraction_numerical': 0.003109211037699184, 'mean_word_length': 2.8475336322869955, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3002762', 'n_tokens_mistral': 758, 'n_tokens_neox': 735, 'n_words': 183}