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


class Puser extends CI_Controller {


	public function __construct()
	{
		parent::__construct();
		$this->load->model("user_model");
	}

	public function index()
	{
		$this->load->view('portalview/user/login');
	}

	public function plogin()
	{
	   
		//$this->user_model->check_plogin();
		
		if($this->input->post())					
		{
		$username = $this->input->post('username',true);
		$password = $this->input->post('password',true);
	    
		$this->user_model->portal_login($username,$password);
		}
	}


	public function update_password()
	{
		$data['title'] = "Update Password";
		$data['userInfo'] =  $this->user_model->userInfo("first_name,last_name");
		$data['main']= "portalview/user/updatePassword_view";
		$this->load->view('portalview/includes/main', $data);
	}



	public function change_password()
	{
		$opass= $this->input->post('old_password');
		$npass=$this->input->post('new_password');
		$cpass=$this->input->post('confirm_password');
		
	   
		$this->db->select('password');
		$this->db->from('admin');
		$this->db->where('id',$this->user_model->userInfo()['id']);
		$this->db->where('password',md5($opass));
		$query = $this->db->get();
		        
	        if($query->num_rows()==1){
	            $data = array('password' => md5($npass));
	            $this->db->where('id', $this->user_model->userInfo()['id']);
	            $this->db->update('admin', $data); 
	            $this->session->set_flashdata('msg', 'Your password has been Updated !');
	            redirect('User/update_password');
	        }else{
	
		$this->session->set_flashdata('err-msg', 'The password you entered is not correct !');
		redirect('Portal/User/update_password');
	
	        }
	   
	}


	public function logout()
	{
	   
          $this->user_model->portal_logout();
	}





}

/* End of file User.php */
/* Location: ./application/controllers/User.php */
