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

class Auth extends CI_Controller
{

	function __construct()
	{
		parent::__construct();
		$this->load->database();
		$this->load->library(array('ion_auth', 'form_validation'));
		$this->load->helper(array('url', 'language'));
		//$this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth'));
		$this->form_validation->set_error_delimiters('<div class="text-danger">', '</div>');
		$this->lang->load('auth');
		$this->load->model('User_model');
	}

	// redirect if needed, otherwise display the user list
	function index()
	{

		if (!$this->ion_auth->logged_in()) {
			// redirect them to the login page
			redirect('auth/login', 'refresh');
		} else {
			// redirect them to the home page because they must be an administrator to view this
			redirect('dashboard', 'refresh');
		}

	}


	/**
	 * List of all registered users
	 *
	 * @load view
	 */

	function users_list()
	{
		if (!$this->ion_auth->logged_in()) {
			//redirect them to the login page
			redirect('auth/login', 'refresh');
		}

		//Displaying List of registered users/IF ADMIN
		$this->data['users'] = $this->User_model->get_users();
		$this->data['title'] = "Users List";
		$this->load->view('header', $this->data);
		//$this->load->view('auth/menu');
		$this->_render_page('auth/index');
		$this->load->view('footer');
	}

	function _render_page($view, $data = NULL, $returnhtml = FALSE)//I think this makes more sense
	{

		$this->viewdata = (empty($data)) ? $this->data : $data;

		$view_html = $this->load->view($view, $this->viewdata, $returnhtml);

		if ($returnhtml) return $view_html;//This will return html on 3rd argument being true
	}


	// log the user in

	/**
	 * Logged user profile
	 *
	 * @load view
	 */
	function profile()
	{
		//Specific user id of login in user
		$user_id = $this->session->userdata('user_id');

		//Displaying Profile of registered user
		$User = $this->User_model->find_by_id($user_id);
		$this->data['fname'] = $User->first_name . ' ' . $User->last_name;
		$this->data['username'] = $User->username;
		$this->data['status'] = $User->active;
		$this->data['phone'] = $User->phone;
		$this->data['email'] = $User->email;
		$date_string = "%d-%m-%Y  %h:%i %a";
		$this->data['created'] = mdate($date_string, $User->created_on);
		$this->data['last_login'] = mdate($date_string, $User->last_login);

		$this->data['title'] = 'User Information';
		$this->load->view('header', $this->data);
		//$this->load->view('profile/menu');
		$this->load->view('profile/user_info');
		$this->load->view('footer');
	}

	// log the user out

	function login()
	{
		$this->data['title'] = "Login";

		//validate form input
		$this->form_validation->set_rules('identity', 'Username', 'required');
		$this->form_validation->set_rules('password', 'Password', '<PASSWORD>');

		if ($this->form_validation->run() == TRUE) {
			// check to see if the user is logging in
			// check for "remember me"
			$remember = (bool)$this->input->post('remember');

			if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember)) {
				//if the login is successful
				//redirect them back to the home page
				$this->session->set_flashdata('message', $this->ion_auth->messages());<commit_msg>Added a check if user is already logged in the login page will redirect to dashboard<commit_after><?php defined('BASEPATH') OR exit('No direct script access allowed');

class Auth extends CI_Controller
{

	function __construct()
	{
		parent::__construct();
		$this->load->database();
		$this->load->library(array('ion_auth', 'form_validation'));
		$this->load->helper(array('url', 'language'));
		//$this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth'));
		$this->form_validation->set_error_delimiters('<div class="text-danger">', '</div>');
		$this->lang->load('auth');
		$this->load->model('User_model');

	}

	// redirect if needed, otherwise display the user list
	function index()
	{

		if (!$this->ion_auth->logged_in()) {
			// redirect them to the login page
			redirect('auth/login', 'refresh');
		} else {
			// redirect them to the home page because they must be an administrator to view this
			redirect('dashboard', 'refresh');
		}

	}


	/**
	 * List of all registered users
	 *
	 * @load view
	 */

	function users_list()
	{
		if (!$this->ion_auth->logged_in()) {
			//redirect them to the login page
			redirect('auth/login', 'refresh');
		}

		//Displaying List of registered users/IF ADMIN
		$this->data['users'] = $this->User_model->get_users();
		$this->data['title'] = "Users List";
		$this->load->view('header', $this->data);
		//$this->load->view('auth/menu');
		$this->_render_page('auth/index');
		$this->load->view('footer');
	}

	function _render_page($view, $data = NULL, $returnhtml = FALSE)//I think this makes more sense
	{

		$this->viewdata = (empty($data)) ? $this->data : $data;

		$view_html = $this->load->view($view, $this->viewdata, $returnhtml);

		if ($returnhtml) return $view_html;//This will return html on 3rd argument being true
	}


	// log the user in

	/**
	 * Logged user profile
	 *
	 * @load view
	 */
	function profile()
	{
		//Specific user id of login in user
		$user_id = $this->session->userdata('user_id');

		//Displaying Profile of registered user
		$User = $this->User_model->find_by_id($user_id);
		$this->data['fname'] = $User->first_name . ' ' . $User->last_name;
		$this->data['username'] = $User->username;
		$this->data['status'] = $User->active;
		$this->data['phone'] = $User->phone;
		$this->data['email'] = $User->email;
		$date_string = "%d-%m-%Y  %h:%i %a";
		$this->data['created'] = mdate($date_string, $User->created_on);
		$this->data['last_login'] = mdate($date_string, $User->last_login);

		$this->data['title'] = 'User Information';
		$this->load->view('header', $this->data);
		//$this->load->view('profile/menu');
		$this->load->view('profile/user_info');
		$this->load->view('footer');
	}

	// log the user out

	function login()
	{
		if ($this->ion_auth->logged_in()) {
			redirect('dashboard', 'refresh');
		}

		$this->data['title'] = "Login";

		//validate form input
		$this->form_validation->set_rules('identity', 'Username', 'required');
		$this->form_validation->set_rules('password', 'Password', '<PASSWORD>');

		if ($this->form_validation->run() == TRUE) {
			// check to see if the user is logging in
			// check for "remember me"
			$remember = (bool)$this->input->post('remember');

			if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember)) {
				//if the login is successful
				//redirect them back to the home page
				$this->session->set_flashdata('message', $this->ion_auth->messages());
{'fraction_non_alphanumeric': 0.20383727639930757, 'fraction_numerical': 0.00028851702250432774, 'mean_word_length': 4.28027418126428, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 185, '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': '2340891', 'n_tokens_mistral': 2495, 'n_tokens_neox': 2268, 'n_words': 502}