<commit_before><?php if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

/**
 * Class Login
 */
class Login extends CI_Controller
{
    /**
     * controller index
     */
    public function index()
    {

        require(APPPATH . 'classes/openid.php');

        $openid = new LightOpenID($_SERVER['HTTP_HOST']);
        if (!$openid->mode) {
            // Didn't get login info from the OpenID provider yet / came from the login link
        $openid->identity = 'https://www.google.com/accounts/o8/id';
        $openid->required = array('namePerson/first', 'namePerson/last', 'contact/email');
        header('Location: ' . $openid->authUrl());
        } else if ($openid->mode == 'cancel') {
            // The user decided to cancel logging in, so we'll redirect to the home page instead
            redirect('/');
        } else {
            // The user has logged in and the user's info is ready
            if (!$openid->validate()) {
                // Authentication failed, try logging in again
                $this->login_failure('Authentication failed, try logging in again.');
            } else {
                // Authentication was successful

                // Get user attributes:
                $user_data = $openid->getAttributes();

                // Check to make sure that the user is logging in using a @ctemc.org account or email exception:
                $this->load->model('datamod');
                $domain_restriction = $this->datamod->getGlobalVar('domain_restriction');
                if ($domain_restriction == '' || (preg_match($domain_restriction, $user_data['contact/email'])) || $this->datamod->checkAllowedEmailException($user_data['contact/email'])) {
                    //echo "Welcome, " . " ` . $user_data['namePerson/first'] . ' ' . $user_data['namePerson/last'];

                    $fname = $user_data['namePerson/first'];
                    $lname = $user_data['namePerson/last'];
                    $email = $user_data['contact/email'];

                    // Load user ID if it exists
                    $user_id = $this->datamod->getUserId($email);
                    if ($user_id == false) {
                        $this->datamod->addUser($fname . " " . $lname, $email);
                        $user_id = $this->datamod->getUserId($email);//@todo addUser should return id
                    }
                    //check for admin permissions
                    if (in_array($user_data['contact/email'],$this->datamod->getGlobalVar('admin_users'))) //check against imported admin_users.config file
                        $admin = 'true';
                    else
                        $admin = 'false';

                    //set session info
                    $this->session->set_userdata(array('auth' => 'true', 'admin' => $admin, 'fname' => $fname, 'lname' => $lname,'email' => $email, 'id' => $user_id));

                    //if ($this->datamod->getPrivKey($user_id) == false)
                    //redirect(base_url('secretsanta/survey'));
                    redirect(base_url('/profile'));
                } else {
                    $this->login_failure('Please log in using an authorized email account or contact an administrator.');
                }

            }
        }
    }

    /**
     * Oauth2 compatible login
     * Rename to index after openid is deprecated
     */
    public function oauth2()
    {
        $this->load->model('datamod');
        $this->config->load('oauth');<commit_msg>Use oauth instead of openid.<commit_after><?php if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

/**
 * Class Login
 */
class Login extends CI_Controller
{
    /**
     * Openid login
     * Rename function to index() to use
     * No longer supported by google as of July, 2015
     * @deprecated
     */
    public function openid()
    {

        require(APPPATH . 'classes/openid.php');

        $openid = new LightOpenID($_SERVER['HTTP_HOST']);
        if (!$openid->mode) {
            // Didn't get login info from the OpenID provider yet / came from the login link
        $openid->identity = 'https://www.google.com/accounts/o8/id';
        $openid->required = array('namePerson/first', 'namePerson/last', 'contact/email');
        header('Location: ' . $openid->authUrl());
        } else if ($openid->mode == 'cancel') {
            // The user decided to cancel logging in, so we'll redirect to the home page instead
            redirect('/');
        } else {
            // The user has logged in and the user's info is ready
            if (!$openid->validate()) {
                // Authentication failed, try logging in again
                $this->login_failure('Authentication failed, try logging in again.');
            } else {
                // Authentication was successful

                // Get user attributes:
                $user_data = $openid->getAttributes();

                // Check to make sure that the user is logging in using a @ctemc.org account or email exception:
                $this->load->model('datamod');
                $domain_restriction = $this->datamod->getGlobalVar('domain_restriction');
                if ($domain_restriction == '' || (preg_match($domain_restriction, $user_data['contact/email'])) || $this->datamod->checkAllowedEmailException($user_data['contact/email'])) {
                    //echo "Welcome, " . " ` . $user_data['namePerson/first'] . ' ' . $user_data['namePerson/last'];

                    $fname = $user_data['namePerson/first'];
                    $lname = $user_data['namePerson/last'];
                    $email = $user_data['contact/email'];

                    // Load user ID if it exists
                    $user_id = $this->datamod->getUserId($email);
                    if ($user_id == false) {
                        $this->datamod->addUser($fname . " " . $lname, $email);
                        $user_id = $this->datamod->getUserId($email);//@todo addUser should return id
                    }
                    //check for admin permissions
                    if (in_array($user_data['contact/email'],$this->datamod->getGlobalVar('admin_users'))) //check against imported admin_users.config file
                        $admin = 'true';
                    else
                        $admin = 'false';

                    //set session info
                    $this->session->set_userdata(array('auth' => 'true', 'admin' => $admin, 'fname' => $fname, 'lname' => $lname,'email' => $email, 'id' => $user_id));

                    //if ($this->datamod->getPrivKey($user_id) == false)
                    //redirect(base_url('secretsanta/survey'));
                    redirect(base_url('/profile'));
                } else {
                    $this->login_failure('Please log in using an authorized email account or contact an administrator.');
                }

            }
        }
    }

    /**
     * Oauth2 compatible login
     */
    public function index()
    {
        $this->load->model('datamod');
        $this->config->load('oauth');
{'fraction_non_alphanumeric': 0.1414098775854791, 'fraction_numerical': 0.001266357112705783, 'mean_word_length': 1.7929273084479371, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 77, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1190046', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1846, 'n_words': 454}