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

/*********************** 
    Referenced from: 
    https://github.com/EllisLab/CodeIgniter/wiki/Persona-Login
***********************/

class Authentication {

    private $CI;
    private $email;

    function __construct() {
        // get super object
        $this->CI =& get_instance();

        // set email
        $this->email = $this->CI->session->userdata('email');
    }

    /** get email
     *
     * \return  email address if set, otherwise false
     */
    public function get_email() {
        return $this->email;
    }

    public function login($assertion) {
        // verify assertion
        $result = $this->verify_assertion($assertion);
        
        // check for success
        if ($result->status === 'okay') {
            $this->email = $result->email;
            $this->CI->session->set_userdata(array('email' => $result->email));
        } else {
            log_message('error', 'Persona '.$result->status.': '.$result->reason);
            return $result->reason;
        }
    }

    public function logout() {
        // logout
        $this->email = false;
        $this->CI->session->sess_destroy();
    }

    private function verify_assertion($assertion) {
        $audience = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'];
        $postdata = 'assertion=' . urlencode($assertion) . '&audience=' . urlencode($audience);

        $this->CI->load->helper('post');
        $result = post_request('https://verifier.login.persona.org/verify',$postdata);

        return json_decode($result);
    }
}<commit_msg>added login result error print<commit_after><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*********************** 
    Referenced from: 
    https://github.com/EllisLab/CodeIgniter/wiki/Persona-Login
***********************/

class Authentication {

    private $CI;
    private $email;

    function __construct() {
        // get super object
        $this->CI =& get_instance();

        // set email
        $this->email = $this->CI->session->userdata('email');
    }

    /** get email
     *
     * \return  email address if set, otherwise false
     */
    public function get_email() {
        return $this->email;
    }

    public function login($assertion) {
        // verify assertion
        $result = $this->verify_assertion($assertion);
        
        // check for success
        if ($result->status === 'okay') {
            $this->email = $result->email;
            $this->CI->session->set_userdata(array('email' => $result->email));
        } else {
            log_message('error', 'Persona '.$result->status.': '.$result->reason);
            return $result->reason;
        }
    }

    public function logout() {
        // logout
        $this->email = false;
        $this->CI->session->sess_destroy();
    }

    private function verify_assertion($assertion) {
        $audience = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'];
        $postdata = 'assertion=' . urlencode($assertion) . '&audience=' . urlencode($audience);
        echo $audience;

        $this->CI->load->helper('post');
        $result = post_request('https://verifier.login.persona.org/verify',$postdata);

        return json_decode($result);
    }
}
{'fraction_non_alphanumeric': 0.18943641192092062, 'fraction_numerical': 0.0, 'mean_word_length': 2.3597621407333995, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 6, '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': '3003222', 'n_tokens_mistral': 992, 'n_tokens_neox': 962, 'n_words': 188}