<commit_before><commit_msg>add Register controller<commit_after><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class register extends CI_Controller {

	 private $vUsername='';
	 private $vNama='';
	 private $vEmail='';
	 private $vPassword1='';
	 private $vPassword2='';
	 private $status = array("STATUS"=>"");
	 function __construct()
	 {
		parent::__construct();
		$this->load->helper('url');
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->load->library('doctrine');
        $this->em = $this->doctrine->em;
		$this->load->library('session');
		
	}

	public function index()
	{
		$this->load->view('login_view');
		$this->form_validation->set_rules('register_username','Nama','required');
		$this->form_validation->set_rules('password2','Confirm Password','<PASSWORD>');
		$this->form_validation->set_rules('email','Email','required|valid_email');
		
		
		$this->vUsername=$this->input->post('register_username','true');
		$this->vPassword1=$this->input->post('password1','<PASSWORD>');
		$this->vNama=$this->input->post('register_nama','true');
		$this->vPassword2=$this->input->post('password2','<PASSWORD>');
		$this->vEmail=$this->input->post('email','true');
		
		if($this->form_validation->run()){
			if($this->cekUsername()){
				if($this->cekPassword()){
					$this->insertData();
					redirect(site_url('home'));
				}
			}
		}
		
		
	}
	private function cekEmail(){
		if($this->form_validation->valid_email($this->vEmail)){
			return true;
		}else{
			$this->status = array("STATUS"=>"Email Tidak Sama");
			json_encode ($this->status) ;
			return false;
		}
	}
	private function cekPassword(){
		if($this->vPassword1==$this->vPassword2){
			return true;
		}else{
			$this->status = array("STATUS"=>"Password Tidak Sama");
			json_encode ($this->status) ;
			return false;
			
		}
	}
	private function insertData(){
		$user = new Entity\User;
		$user->setUsername($this->vUsername);
		$user->setPassword(<PASSWORD>($this->v<PASSWORD>));
		$user->setNama($this->vNama);
		$user->setEmail($this->vEmail);
		$this->em->persist($user);
		$this->em->flush();
		
	}
	private function cekUsername(){
		$userRepository=$this->em->getRepository('Entity\User');
		$singleUser=$userRepository->findOneBy(array('username'=>$this->vUsername));
		if($singleUser!=null){
			return false;
		}else{
			$this->status = array("STATUS"=>"Username Sudah Ada");
			json_encode ($this->status) ;	
			return true;
		}
	}
	
}
{'fraction_non_alphanumeric': 0.21549636803874092, 'fraction_numerical': 0.0036319612590799033, 'mean_word_length': 5.075980392156863, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 81, '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': '5697988', 'n_tokens_mistral': 932, 'n_tokens_neox': 821, 'n_words': 114}