<commit_before><?php

namespace Bootstrap\Support\Auth;

use Bootstrap\Facades\Session;
use Bootstrap\Facades\Security;
use Bootstrap\Facades\Response;

class Auth
{
    /**
     *
     */
    public function attempt($records)
    {
        $password_field = config()->app->auth->password_field;
        if (isset( $records[ $password_field ] ) == false) {
            throw new Exception('Password field not found!');
        }


        # ---- get the password information
        $password = $records[ $password_field ];
        unset( $records[ $password_field ] );


        # ---- build the conditions
        $conditions = null;
        $first = true;
        foreach ($records as $key => $record) {

            if (!$first) {
                $conditions .= 'AND';
            }

            $conditions .= " {$key} = :{$key}: ";
            $first = false;
        }


        # ---- find the informations provided in the $records
        $auth_model = config()->app->auth->model;
        $records =
            $auth_model::find([
                $conditions,
                'bind' => $records,
            ])->getFirst();


        # ---- check if there is no record, then return false
        if (!$records) {
            return false;
        }


        # ---- now check if the password given is matched with the
        # existing password recorded.
        if (Security::checkHash($password, $records->{$password_field})) {
            Session::set('isAuthenticated', true);
            Session::set('user', $records);

            return true;
        }

        return false;
    }


    /**
     *
     */
    public function redirectIntended()
    {
        $redirect_to = config()->app->auth->auth_redirect;

        return Response::redirect($redirect_to);
    }


    /**
     *
     */
    public function check()
    {
        if (Session::has('isAuthenticated')) {<commit_msg>trimming comments<commit_after><?php

namespace Bootstrap\Support\Auth;

use Bootstrap\Facades\Session;
use Bootstrap\Facades\Security;
use Bootstrap\Facades\Response;

class Auth
{
    /**
     *
     */
    public function attempt($records)
    {
        $password_field = config()->app->auth->password_field;
        if (isset( $records[ $password_field ] ) == false) {
            throw new Exception('Password field not found!');
        }


        # - get the password information
        $password = $records[ $password_field ];
        unset( $records[ $password_field ] );


        # - build the conditions
        $conditions = null;
        $first = true;
        foreach ($records as $key => $record) {

            if (!$first) {
                $conditions .= 'AND';
            }

            $conditions .= " {$key} = :{$key}: ";
            $first = false;
        }


        # - find the informations provided in the $records
        $auth_model = config()->app->auth->model;
        $records =
            $auth_model::find([
                $conditions,
                'bind' => $records,
            ])->getFirst();


        # - check if there is no record, then return false
        if (!$records) {
            return false;
        }


        # - now check if the password given is matched with the
        # existing password recorded.
        if (Security::checkHash($password, $records->{$password_field})) {
            Session::set('isAuthenticated', true);
            Session::set('user', $records);

            return true;
        }

        return false;
    }


    /**
     *
     */
    public function redirectIntended()
    {
        $redirect_to = config()->app->auth->auth_redirect;

        return Response::redirect($redirect_to);
    }


    /**
     *
     */
    public function check()
    {
        if (Session::has('isAuthenticated')) {
{'fraction_non_alphanumeric': 0.13623188405797101, 'fraction_numerical': 0.0, 'mean_word_length': 1.7250538406317302, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '2252238', 'n_tokens_mistral': 1040, 'n_tokens_neox': 990, 'n_words': 245}