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

class User extends CI_Controller
{
	function __construct()
	{
		parent::__construct();
		$this->data['meta_title'] = "UCRInterest";
	}

	function login()
	{

		if($this->is_logged_in())
		{
			redirect('feed');
		}

		$this->load->library('form_validation');
		$this->form_validation->set_rules('email', 'Email', 'required|trim|callback_username_check');
		$this->form_validation->set_rules('password', 'Password', '<PASSWORD>');

		if($this->form_validation->run())
		{
			$data = array(
						'email' => $this->input->post('email'),
						'is_logged_in' => true
					);
			$this->session->set_userdata($data);
			redirect('profile');
		}

		$this->data['subview'] = 'user/login_view';
		$this->load->view('template/modal_layout', $this->data);
	}

	function register()
	{
		/**TODO:
		 *Have to check if session is still good. If it is then proceed to next page.
		 */
		if($this->is_logged_in())
		{
			redirect('profile');
		}

		$this->load->library('form_validation');
		$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]');
		$this->form_validation->set_rules('username', 'Username', 'trim|required|is_unique[users.username]');
		$this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
		$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
		$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[6]');
		$this->form_validation->set_rules('DOB', 'DOB', 'required');

		if($this->form_validation->run())
		{
			$this->load->model('user_model');
			$this->user_model->register_user();
			$data = array(
						'username' => $this->input->post('email'),
						'is_logged_in' => true
					);
			$this->session->set_userdata($data);
			redirect('feed');
		}
		
		$this->data['subview'] = 'user/registration_view';
		$this->load->view('template/modal_layout', $this->data);
	}

	function logout()
	{
		$this->session->sess_destroy();
		redirect('Welcome');
	}

	//This is used for the log in form validation
	function username_check()
	{
		$this->load->model('user_model');
		$result = $this->user_model->login();
		if($result)<commit_msg>registration<commit_after><?php if ( ! defined ('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller
{
	function __construct()
	{
		parent::__construct();
		$this->data['meta_title'] = "UCRInterest";
	}

	function login()
	{

		if($this->is_logged_in())
		{
			redirect('feed');
		}

		$this->load->library('form_validation');
		$this->form_validation->set_rules('email', 'Email', 'required|trim|callback_username_check');
		$this->form_validation->set_rules('password', 'Password', '<PASSWORD>');

		if($this->form_validation->run())
		{
			$data = array(
						'email' => $this->input->post('email'),
						'is_logged_in' => true
					);
			$this->session->set_userdata($data);
			redirect('profile');
		}

		$this->data['subview'] = 'user/login_view';
		$this->load->view('template/modal_layout', $this->data);
	}

	function register()
	{
		/**TODO:
		 *Have to check if session is still good. If it is then proceed to next page.
		 */
		if($this->is_logged_in())
		{
			redirect('profile');
		}

		$this->load->library('form_validation');
		$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]');
		$this->form_validation->set_rules('username', 'Username', 'trim|required|is_unique[users.username]');
		$this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
		$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
		$this->form_validation->set_rules('password', 'Password', '<PASSWORD>|min_<PASSWORD>[6]');
		$this->form_validation->set_rules('DOB', 'DOB', 'required');

		if($this->form_validation->run())
		{
			$this->load->model('user_model');
			$this->user_model->register_user();
			$data = array(
						'email' => $this->input->post('email'),
						'is_logged_in' => true
					);
			$this->session->set_userdata($data);
			redirect('feed');
		}
		
		$this->data['subview'] = 'user/registration_view';
		$this->load->view('template/modal_layout', $this->data);
	}

	function logout()
	{
		$this->session->sess_destroy();
		redirect('Welcome');
	}

	//This is used for the log in form validation
	function username_check()
	{
		$this->load->model('user_model');
		$result = $this->user_model->login();
		if($result)
{'fraction_non_alphanumeric': 0.20646160655012172, 'fraction_numerical': 0.0004425757911042266, 'mean_word_length': 4.908496732026144, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 121, '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': '1860406', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1521, 'n_words': 235}