HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: /var/www/html/pmw24/pmw_live_testing/app/application/controllers/customer/Login.php
<?php

defined('BASEPATH') OR exit('No direct script access allowed');



class Login extends MY_Controller {

	public function __construct() {

		parent::__construct();

		//print_r($this->admin);die;

		$this->load->model('admin/mcustomer');

		$this->load->library('session');

	}

	public function index(){
		$data=array();
		$this->load->view('customer/login', $data);	
	}

		

	public function dashboard() { //echo 'aa';die;

		$data['content'] = 'customer/index'; 

		$this->load->view('customer/layouts/index', $data);		

	}

	

	



	

	

	

	public function add_customer(){

		

		if($this->input->post()){

			

			$condition=array('email'=>$this->input->post('email'));

			$check_email = $this->mcustomer->getRow('customer',$condition);

			

			if(empty($check_email)){	

					

				$customer_data['customer_type']=$this->input->post('customer_type');

				if($this->input->post('customer_type') == 'B'){

					$customer_data['business_name']=$this->input->post('business_name');

				}

				$customer_data['first_name']=$this->input->post('first_name');

				$customer_data['middle_name']=$this->input->post('middle_name');

				$customer_data['last_name']=$this->input->post('last_name');

				$customer_data['abn']=$this->input->post('abn');

				$customer_data['landline_no']=$this->input->post('landline_no');

				$customer_data['mobile']=$this->input->post('mobile');

				$customer_data['email']=$this->input->post('email');

				$customer_data['flat_no']=$this->input->post('flat_no');

				$customer_data['street_no']=$this->input->post('street_no');

				$customer_data['street_name']=$this->input->post('street_name');

				$customer_data['suburb']=$this->input->post('suburb');

				$customer_data['state']=$this->input->post('state');

				$customer_data['pin']=$this->input->post('pin');

				$customer_data['created_by']=0;

				$customer_data['created_ts']=date('Y-m-d H:i:s');

				 

				$customer_id = $this->mcustomer->add($customer_data);

				

				if(!empty($customer_id)){

					

					$full_name = $this->input->post('first_name').' '.(!empty($this->input->post('middle_name'))?$this->input->post('middle_name').' ':'').$this->input->post('last_name');

					$mail_temp = file_get_contents('./global/mail/registration_template_customer.html');						

					$mail_temp=str_replace("{name}",$full_name,$mail_temp);

					

					$mail_temp=str_replace("{company_name}","PUNJAB MOTOR WORKSHOP",$mail_temp);

					$mail_temp=str_replace("{company_phone}","+61 3 9540 8998",$mail_temp);

					$mail_temp=str_replace("{company_email}","punjabmotor@hotmail.com",$mail_temp);

					$mail_temp=str_replace("{current_year}",date('Y'),$mail_temp);

					$mail_temp=str_replace("{logo}",LOGOURL,$mail_temp);

					$mail_temp=str_replace("{web_url}",WEBSITE_URL,$mail_temp);

					

							

					$data['to']=$this->input->post('email');

					$data['name']='PUNJAB MOTOR WORKSHOP';

					$data['subject']='PUNJAB MOTOR WORKSHOP REGISTRATION';

					$data['message']=$mail_temp;

					$this->sendMail($data);

				}

				

				$return_data = array('status'=>true,'msg'=>'Registration successful','customer_id'=>$customer_id);

				

			}else{



				$return_data = array('status'=>false,'msg'=>'Email already exist','customer_id'=>'');

			}

		

		}else{

			$return_data = array('status'=>false,'msg'=>'Please fill out the fields','customer_id'=>'');

		}

		echo json_encode($return_data);

	}



	

	private function sendMail($data){

		$config['protocol']    	= 'smtp';

        $config['protocol']      = 'smtp';

        $config['smtp_host']     = 'ssl://mail.fitser.com';

        $config['smtp_port']     = '465';  

        $config['smtp_user']     = 'test123@fitser.com';

        $config['smtp_pass']     = 'Test123@';

        $config['charset']    	= 'utf-8';

        $config['newline']    	= "\r\n";

        $config['mailtype'] 	= 'html';

        $config['validation'] 	= TRUE;   



        $this->email->initialize($config);



        $this->email->set_crlf( "\r\n" );



        $this->email->from('info@punjabmotor.com', 'PUNJAB MOTOR WORKSHOP');

        $this->email->to($data['to']); 



        $this->email->subject($data['subject']);

        $this->email->message($data['message']);  



        $this->email->send();

		return true;   	

    } 



    function customer_login(){



		if($this->input->post()){

			

			$condition=array('UPPER(TRIM(email))'=>strtoupper($this->input->post('email')),'password'=>md5($this->input->post('pwd')));

			$check_login_credential = $this->mcustomer->getRow('customer',$condition);

			//echo $this->db->last_query();die;

			if(!empty($check_login_credential)){	

					

				if($check_login_credential['status'] == 0){

					

					$return_data = array('status'=>true,'msg'=>'Login credential not approved by admin','customer_data'=>array());

				

				}elseif($check_login_credential['status'] == 1){

					$this->session->set_userdata('customer_data',$check_login_credential);

					//echo '<pre>';print_r($this->session->userdata('customer_data'));die;

					$return_data = array('status'=>true,'msg'=>'Login successful','customer_data'=>array());

				

				} else{

					$return_data = array('status'=>true,'msg'=>'You are blocked by admin','customer_data'=>array());	



				}

			}else{



				$return_data = array('status'=>false,'msg'=>'Invalid login credential','customer_data'=>array());

			}

		

		}else{

			$return_data = array('status'=>false,'msg'=>'Please fill out the fields','customer_data'=>array());

		}

		echo json_encode($return_data);

	}





	function forgot_password(){



		if($this->input->post()){

			

			$condition=array('UPPER(email)'=>strtoupper($this->input->post('forgot_pw_email')));

			$check_login_credential = $this->mcustomer->getRow('customer',$condition);

			

			if(!empty($check_login_credential)){	

					

					$encoded_key = base64_encode(rand());

					$customer_data['recovery_key'] = $encoded_key;

					$this->mcustomer->update(array('customer_id'=>$check_login_credential['customer_id']), $customer_data);

				

					$full_name = $check_login_credential['first_name'].' '.(!empty($check_login_credential['middle_name'])?$check_login_credential['middle_name'].' ':'').$check_login_credential['last_name'];

					$mail_temp = file_get_contents('./global/mail/forgotpassword_template.html');						

					$mail_temp=str_replace("{name}",$full_name,$mail_temp);

					

					$mail_temp=str_replace("{company_name}","PUNJAB MOTOR WORKSHOP",$mail_temp);

					$mail_temp=str_replace("{company_phone}","+61 3 9540 8998",$mail_temp);

					$mail_temp=str_replace("{company_email}","punjabmotor@hotmail.com",$mail_temp);

					$mail_temp=str_replace("{current_year}",date('Y'),$mail_temp);

					$mail_temp=str_replace("{logo}",LOGOURL,$mail_temp);

					$mail_temp=str_replace("{web_url}",WEBSITE_URL,$mail_temp);

					$link = base_url('recover-password/' . $encoded_key);

					$mail_temp=str_replace("{link}",$link,$mail_temp);

					

					

							

					$data['to']=$check_login_credential['email'];

					$data['name']='PUNJAB MOTOR WORKSHOP';

					$data['subject']='Forgot Password';

					$data['message']=$mail_temp;

					$this->sendMail($data);

					$return_data = array('status'=>true,'msg'=>'Please check your mail, a link will be sent for reset your password','customer_data'=>array());

			

			

			}else{



				$return_data = array('status'=>false,'msg'=>'This email does not exist in our database','customer_data'=>array());

			}

		

		}else{

			$return_data = array('status'=>false,'msg'=>'Please fill out the fields','customer_data'=>array());

		}

		echo json_encode($return_data);

	}

}