233 lines
6.7 KiB
PHP
233 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
use App\Models\ClientModel;
|
|
use App\Models\ClientDocsModel;
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
|
|
class ClientController extends BaseController
|
|
{
|
|
public $session;
|
|
protected $ClientModel;
|
|
protected $ClientDocsModel;
|
|
|
|
use ResponseTrait;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->session = session();
|
|
$this->ClientModel = new ClientModel();
|
|
$this->ClientDocsModel = new ClientDocsModel();
|
|
|
|
}
|
|
|
|
|
|
public function login()
|
|
{
|
|
if($this->session->has('is_client_logged_in')){ return redirect()->to(base_url().'client_home'); }
|
|
if($this->request->getmethod() == 'POST')
|
|
{
|
|
$pan_no = $this->request->getPost('pan_no');
|
|
$clientdata = $this->ClientModel->where('pan_no', $pan_no)->first();
|
|
|
|
if($clientdata)
|
|
{
|
|
if($clientdata['is_active'] == 0)
|
|
{
|
|
$this->session->setTempdata('error','Client Deactivated',3);
|
|
return redirect()->to(base_url());
|
|
}
|
|
|
|
|
|
$this->session->set('is_client_logged_in',$clientdata['client_id']);
|
|
// $this->session->set('logged_in_client_name',$clientdata['org_name']);
|
|
|
|
return redirect()->to(base_url().'client_home');
|
|
|
|
|
|
}else{
|
|
$this->session->setTempdata('error','Email or Password is invalid',3);
|
|
return redirect()->to(base_url());
|
|
}
|
|
|
|
}
|
|
//get method
|
|
return view('client_login');
|
|
}
|
|
|
|
public function client_logout()
|
|
{
|
|
session()->remove('is_client_logged_in');
|
|
session()->destroy();
|
|
return redirect()->to(base_url());
|
|
}
|
|
|
|
|
|
public function client_home(){
|
|
$client_id =$this->session->get('is_client_logged_in');
|
|
|
|
$data['doc_list'] = $this->ClientDocsModel->getTemplate($client_id);
|
|
// print_r($data['doc_list']);die;
|
|
|
|
$clientdata = $this->ClientModel->where('client_id', $client_id)->get()->getRow();
|
|
|
|
if($clientdata){
|
|
echo view('layout/header', ['Data'=>$clientdata]);
|
|
echo view('client_home',$data);
|
|
echo view('layout/footer');
|
|
}
|
|
}
|
|
|
|
|
|
public function client_profile()
|
|
{
|
|
if(!$this->session->has('is_client_logged_in')){ return redirect()->to(base_url()); }
|
|
if($this->request->getmethod() == 'POST')
|
|
{
|
|
//update client profile
|
|
$clientData = $this->request->getVar();
|
|
|
|
$clientData['updated_by'] = $this->session->get('is_client_logged_in');
|
|
$client_id = $this->request->getVar('client_id');
|
|
$this->ClientModel->where('client_id', $client_id )->set($clientData)->update();
|
|
|
|
echo true;
|
|
}else{
|
|
$clientdata = $this->ClientModel->where('client_id',$this->session->get('is_client_logged_in'))->get()->getRow();
|
|
echo view('layout/header', ['Data'=>$clientdata]);
|
|
echo view('client_profile',['client'=>$clientdata]);
|
|
echo view('layout/footer');
|
|
}
|
|
}
|
|
|
|
public function change_client_password($client_id)
|
|
{
|
|
$old_password =$this->request->getVar('old_password');
|
|
$new_password =$this->request->getVar('new_password');
|
|
$confirm_password =$this->request->getVar('confirm_password');
|
|
|
|
|
|
$client = $this->ClientModel->where('client_id',$client_id)->first();
|
|
$data_old_password = $client['password'];
|
|
|
|
if (!password_verify($old_password, $data_old_password)) {
|
|
$response = array(
|
|
'status' => 'error',
|
|
'message' => 'Old Password Not Match...'
|
|
);
|
|
return json_encode($response);
|
|
}
|
|
|
|
if($new_password != $confirm_password){
|
|
$response = array(
|
|
'status' => 'error',
|
|
'message' => 'New Password And Confirm Password Not Match...'
|
|
);
|
|
return json_encode($response);
|
|
}
|
|
|
|
//$hashedPassword = password_hash($new_password, PASSWORD_DEFAULT);
|
|
$data['password'] = $new_password;
|
|
|
|
if ($this->ClientModel->update($client_id, $data)) {
|
|
$response = array(
|
|
'status' => 'success',
|
|
'message' => 'Password Change Succuessfully'
|
|
);
|
|
return json_encode($response);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public function generate_otp()
|
|
{
|
|
try {
|
|
$pan_no = $this->request->getPost('pan_no');
|
|
|
|
$client_data = $this->ClientModel->where('pan_no', $pan_no )->first();
|
|
|
|
if($client_data){
|
|
|
|
$id = $client_data['client_id'];
|
|
|
|
$data = [
|
|
'otp' => '123456'
|
|
];
|
|
$update = $this->ClientModel->update($id , $data);
|
|
|
|
if($update){
|
|
return json_encode(true);
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
} catch (\Exception $e) {
|
|
// Handle any exceptions that occur during execution
|
|
return $this->respond(['status' => 'error', 'code' => 500, 'message' => $e->getMessage()], 500);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function verify_otp()
|
|
{
|
|
try {
|
|
$pan_no = $this->request->getPost('pan_no');
|
|
$otp = $this->request->getPost('otp');
|
|
|
|
$client_data = $this->ClientModel->where('pan_no', $pan_no )->where('otp', $otp)->first();
|
|
$data = ['otp' =>''];
|
|
|
|
if($client_data){
|
|
$id = $client_data['client_id'];
|
|
$update = $this->ClientModel->update($id , $data);
|
|
if($update){
|
|
return json_encode(true);
|
|
}
|
|
} else {
|
|
$client_data = $this->ClientModel->where('pan_no', $pan_no )->first();
|
|
$id = $client_data['client_id'];
|
|
|
|
$update = $this->ClientModel->update($id , $data);
|
|
|
|
|
|
return false;
|
|
}
|
|
} catch (\Exception $e) {
|
|
// Handle any exceptions that occur during execution
|
|
return $this->respond(['status' => 'error', 'code' => 500, 'message' => $e->getMessage()], 500);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public function status_client()
|
|
{
|
|
try {
|
|
$client_id = $this->request->getPost('client_id');
|
|
$is_active = $this->request->getPost('is_active');
|
|
$data = [
|
|
'is_active' => $is_active
|
|
];
|
|
|
|
$updated = $this->ClientModel->update($client_id, $data);
|
|
|
|
if ($updated) {
|
|
return $this->respond(['status' => 'success','code' => 200,'data' => true],200);
|
|
} else {
|
|
$result = "No Match's";
|
|
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
|
|
}
|
|
} catch (\Exception $exception) {
|
|
return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|