<commit_before><?php
namespace Hook\Auth\Providers;

use Hook\Exceptions\ForbiddenException;
use Hook\Model\Auth as Auth;

class Facebook extends Base
{
    public function register($data)
    {
        $data = $this->requestFacebookGraph($data);

        $user = null;
        try {
            $user = $this->find('facebook_id', $data);
        } catch (\Illuminate\Database\QueryException $e) {}

        if (!$user) {
            $user = Auth::create($data);
        }

        return $user->dataWithToken();
    }

    public function login($data)
    {
        $userdata = null;
        if ($user = $this->find('facebook_id', $this->requestFacebookGraph($data))) {
            $userdata = $user->dataWithToken();
        }

        return $userdata;
    }

    protected function requestFacebookGraph($data)
    {
        // validate accessToken
        if (!isset($data['accessToken'])) {
            throw new ForbiddenException(__CLASS__ . ": you must provide user 'accessToken'.");
        }

        $access_token = $data['accessToken'];<commit_msg>fix facebook registration with guarded fields<commit_after><?php
namespace Hook\Auth\Providers;

use Hook\Exceptions\ForbiddenException;
use Hook\Model\Auth as Auth;

class Facebook extends Base
{
    public function register($data)
    {
        $data = $this->requestFacebookGraph($data);

        $user = null;
        try {
            $user = $this->find('facebook_id', $data);
        } catch (\Illuminate\Database\QueryException $e) {}

        if (!$user) {
            // create a new user
            $user = new Auth;
            $user->email = $data['email'];
            $user->fill($data);
            $user->save();
        }

        return $user->dataWithToken();
    }

    public function login($data)
    {
        $userdata = null;
        if ($user = $this->find('facebook_id', $this->requestFacebookGraph($data))) {
            $userdata = $user->dataWithToken();
        }

        return $userdata;
    }

    protected function requestFacebookGraph($data)
    {
        // validate accessToken
        if (!isset($data['accessToken'])) {
            throw new ForbiddenException(__CLASS__ . ": you must provide user 'accessToken'.");
        }

        $access_token = $data['accessToken'];
{'fraction_non_alphanumeric': 0.13884007029876977, 'fraction_numerical': 0.0, 'mean_word_length': 2.2435897435897436, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '645110', 'n_tokens_mistral': 636, 'n_tokens_neox': 625, 'n_words': 139}