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

class Users extends Public_Controller
{
	function __construct()
	{
		parent::Public_Controller();
    $this->load->library('session');
		$this->load->library('user_lib');
		
		$this->load->model('users_m');
		$this->load->helper('user');
		
		$this->lang->load('user');
  }
	
  // AUTHORISATION SECTION -------------------------------------------------------------------------------------
	
  function login()
	{
		// Set the redirect page as soon as they get to login
		if(!$this->session->userdata('redirect_to')):
			$this->session->set_userdata('redirect_to', !empty($_SERVER['HTTP_REFFERER']) ? $_SERVER['HTTP_REFFERER'] : '');
		endif;
		
		// Call validation and set rules
		$this->load->library('validation');
    $rules['email'] = 'callback__check_login';
    $rules['password'] = '';
    $this->validation->set_rules($rules);
    $this->validation->set_fields();
        
    // If the validation worked, or the user is already logged in
    if ($this->validation->run() or $this->user_lib->logged_in()):
    	//$redirect_to = (($this->session->userdata('redirect_to')) ? $this->session->userdata('redirect_to') : '');
			//redirect($redirect_to, 'refresh');
			
			// TODO PJS Add login redirect - sends back to whatever page they were trying to get on
      redirect('');
    endif;
        
    $this->layout->create('login', $this->data);
	}
	
	function logout()
	{
		$this->user_lib->logout();
		$this->session->set_flashdata('success', $this->lang->line('user_logged_out'));
		redirect('');
	}
	
	function register()	
	{		
		$this->load->library('validation');
		
		$rules = array(
			'first_name'		=>	'required|alpha_dash',
			'last_name'			=>	($this->settings->item('require_lastname') ? 'required' : '').'alpha_dash',
			//'user_name'		=>	'required|alpha_numeric_dash|min_length[5]|max_length[20]',
			'password'			=>	'<PASSWORD>]',
			'confirm_password'	=>	'<PASSWORD>]',
			'email'				=>	'required|valid_email',
			'confirm_email'		=>	'required|valid_email|matches[email]'
		);
		
		$this->validation->set_rules($rules);
		$this->validation->set_fields();
		
		$email = $this->input->post('email');
		$password = $this->input->post('password');
		
		if ($this->validation->run()):

			// Try and create the user
			if($id = $this->user_lib->create($email, $password)):
				
				// Now they have been created, does the admin want activation emails to be sent out?
				if($this->settings->item('activation_email') == 1):
					
					// They do? Ok, send out an email to the user
					if($this->user_lib->registered_email($this->user_lib->user_data)):			
						$this->session->set_flashdata(array('notice'=> $this->lang->line('user_activation_code_sent_notice')));	
						redirect('users/activate/'.$id);
					endif;
				
				// or should we let the admin manually activate them?
				else:
					$this->session->set_flashdata(array('notice'=> $this->lang->line('user_activation_by_admin_notice')));	
					redirect('');
				endif;
			
			// Can't create the user, show why
			else:
				$this->data->error_string = $this->lang->line($this->user_lib->error_code);
			endif;
			
		else:
			// Return the validation error message or user_lib error
			$this->data->error_string = $this->validation->error_string;
		endif;
		
		$this->layout->title($this->lang->line('user_register_title'));
		$this->layout->create('register', $this->data);		
	}

	function activate($id = 0, $code = NULL)
	{
		// Get info from email
		if($this->input->post('email')):
			$this->data->activate_user = $this->users_m->getUser(array('email'=>$this->input->post('email')));
			$id = $this->data->user->id;
		else:
			$this->data->activate_user = $this->users_m->getUser(array('id'=>$id));<commit_msg>bug: Trying to get property of non-object Filename: controllers/users.php. Reported by MetehanArslan.<commit_after><?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Users extends Public_Controller
{
	function __construct()
	{
		parent::Public_Controller();
    $this->load->library('session');
		$this->load->library('user_lib');
		
		$this->load->model('users_m');
		$this->load->helper('user');
		
		$this->lang->load('user');
  }
	
  // AUTHORISATION SECTION -------------------------------------------------------------------------------------
	
  function login()
	{
		// Set the redirect page as soon as they get to login
		if(!$this->session->userdata('redirect_to')):
			$this->session->set_userdata('redirect_to', !empty($_SERVER['HTTP_REFFERER']) ? $_SERVER['HTTP_REFFERER'] : '');
		endif;
		
		// Call validation and set rules
		$this->load->library('validation');
    $rules['email'] = 'callback__check_login';
    $rules['password'] = '';
    $this->validation->set_rules($rules);
    $this->validation->set_fields();
        
    // If the validation worked, or the user is already logged in
    if ($this->validation->run() or $this->user_lib->logged_in()):
    	//$redirect_to = (($this->session->userdata('redirect_to')) ? $this->session->userdata('redirect_to') : '');
			//redirect($redirect_to, 'refresh');
			
			// TODO PJS Add login redirect - sends back to whatever page they were trying to get on
      redirect('');
    endif;
        
    $this->layout->create('login', $this->data);
	}
	
	function logout()
	{
		$this->user_lib->logout();
		$this->session->set_flashdata('success', $this->lang->line('user_logged_out'));
		redirect('');
	}
	
	function register()	
	{		
		$this->load->library('validation');
		
		$rules = array(
			'first_name'		=>	'required|alpha_dash',
			'last_name'			=>	($this->settings->item('require_lastname') ? 'required' : '').'alpha_dash',
			//'user_name'		=>	'required|alpha_numeric_dash|min_length[5]|max_length[20]',
			'password'			=>	'<PASSWORD>]',
			'confirm_password'	=>	'<PASSWORD>]',
			'email'				=>	'required|valid_email',
			'confirm_email'		=>	'required|valid_email|matches[email]'
		);
		
		$this->validation->set_rules($rules);
		$this->validation->set_fields();
		
		$email = $this->input->post('email');
		$password = $this->input->post('password');
		
		if ($this->validation->run()):

			// Try and create the user
			if($id = $this->user_lib->create($email, $password)):
				
				// Now they have been created, does the admin want activation emails to be sent out?
				if($this->settings->item('activation_email') == 1):
					
					// They do? Ok, send out an email to the user
					if($this->user_lib->registered_email($this->user_lib->user_data)):			
						$this->session->set_flashdata(array('notice'=> $this->lang->line('user_activation_code_sent_notice')));	
						redirect('users/activate/'.$id);
					endif;
				
				// or should we let the admin manually activate them?
				else:
					$this->session->set_flashdata(array('notice'=> $this->lang->line('user_activation_by_admin_notice')));	
					redirect('');
				endif;
			
			// Can't create the user, show why
			else:
				$this->data->error_string = $this->lang->line($this->user_lib->error_code);
			endif;
			
		else:
			// Return the validation error message or user_lib error
			$this->data->error_string = $this->validation->error_string;
		endif;
		
		$this->layout->title($this->lang->line('user_register_title'));
		$this->layout->create('register', $this->data);		
	}

	function activate($id = 0, $code = NULL)
	{
		// Get info from email
		if($this->input->post('email')):
			$this->data->activate_user = $this->users_m->getUser(array('email'=>$this->input->post('email')));
			$id = $this->data->activate_user->id;
		else:
			$this->data->activate_user = $this->users_m->getUser(array('id'=>$id));
{'fraction_non_alphanumeric': 0.21280209013716525, 'fraction_numerical': 0.0013063357282821686, 'mean_word_length': 3.5168141592920352, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 227, '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': '3099255', 'n_tokens_mistral': 2800, 'n_tokens_neox': 2415, 'n_words': 454}