Setup Refined

This commit is contained in:
Velz2020 2022-12-20 23:50:30 +05:30
parent 9bb0b9d425
commit 108fa4d41c
11 changed files with 86 additions and 30 deletions

View File

@ -132,4 +132,4 @@
| |
| $autoload['model'] = array('first_model' => 'first'); | $autoload['model'] = array('first_model' => 'first');
*/ */
$autoload['model'] = array(); $autoload['model'] = array('auth/auth_model');

View File

@ -52,3 +52,7 @@
$route['default_controller'] = 'Backend'; $route['default_controller'] = 'Backend';
$route['404_override'] = ''; $route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE; $route['translate_uri_dashes'] = FALSE;
//modules routes
$route['logout'] = 'auth/logout';
$route['login'] = 'auth';

View File

@ -23,15 +23,17 @@ class Admin_Controller extends MY_Controller
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
if(!check_auth())
echo $copyright_from_mycontroller;die();
if(!$this->session->userdata('logged_in') == TRUE)
{ {
redirect('auth'); redirect('login');
} }
$global_data['settings'] = $this->auth_model->get_settings();
$global_data['business'] = $this->auth_model->get_business(0);
$this->load->vars($global_data);
$this->load->library('user_agent');
// $this->global_data['org_details'] = array('business_name' => 'XYZ');
// $this->layout->set('global_data',$this->global_data);
} }
} }

View File

@ -45,8 +45,8 @@ public function __construct()
$date = "$begin - $end"; $date = "$begin - $end";
// Copyright // Copyright
$this->global_data['copyright_from_mycontroller'] = $date; // $this->global_data['copyright_from_mycontroller'] = $date;
$this->load->vars($this->global_data); // $this->load->vars($this->global_data);
$this->load->module('layout'); $this->load->module('layout');
} }
} }

View File

@ -194,4 +194,44 @@ function get_primary_business()
} }
// get business
function get_business($uid)
{
// print_r($this->session->userdata());
if (($this->session->userdata('role') !== null) && $this->session->userdata('role') != 'sadmin') {
$this->db->select('b.*, t.name as country');
$this->db->from('business b');
if ($uid != 0) {
$this->db->where('b.uid', $uid);
}else{
$this->db->where('b.uid', $this->session->userdata('business_id'));
}
// $this->db->where('b.user_id', $this->session->userdata('id'));
$this->db->join('country t', 't.id = b.country', 'LEFT');
$query = $this->db->get();
$query = $query->row();
// print_r($this->db->last_query());//die();
return $query;
}
return array();
}
// get settings
function get_settings()
{
$this->db->select('s.*');
$this->db->from('settings s');
$query = $this->db->get();
$query = $query->row();
return $query;
}
} }

View File

@ -17,13 +17,13 @@ function check_auth()
{ {
// Get a reference to the controller object // Get a reference to the controller object
$ci =& get_instance(); $ci =& get_instance();
//return $ci->auth_model->is_logged_in(); return $ci->auth_model->is_logged_in();
if($ci->session->userdata('logged_in') == TRUE) // if($ci->session->userdata('logged_in') == TRUE)
{ // {
return true; // return true;
} // }
return false; // return false;
} }
} }

View File

@ -53,11 +53,11 @@ public function index()
public function authendicate() public function authendicate()
{ {
$user = $this->auth_model->validate_user(); $user = $this->auth_model->validate_user();
// print_r($user);die(); //print_r($user);die();
// echo hash_password('password');die(); // echo hash_password('password');die();
if (empty($user)) { if (empty($user)) {
redirect('auth'); redirect('login');
} }
// if (!empty($user) && $user->status == 0) { // if (!empty($user) && $user->status == 0) {
// // account pending // // account pending
@ -92,24 +92,25 @@ public function authendicate()
if(password_verify($this->input->post('password'), $user->password)) if(password_verify($this->input->post('password'), $user->password))
{ {
$data = array( $data = array(
'id' => $user_id, 'id' => $user->id,
'name' => $user->name, 'name' => $user->name,
//'thumb' => $user->thumb, //'thumb' => $user->thumb,
'email' =>$user->email, 'email' =>$user->email,
// 'role' =>$user->role, 'role' =>$user->role,
// 'parent' =>$user->id, 'action_permit' =>$user->action_permit,
'business_id' =>$user->business_id,
'logged_in' => TRUE 'logged_in' => TRUE
); );
$data = $this->security->xss_clean($data); $data = $this->security->xss_clean($data);
$this->session->set_userdata($data); $this->session->set_userdata($data);
redirect('dashboard'); redirect('dashboard');
} }
redirect('auth'); redirect('login');
} }
public function logout() public function logout()
{ {
$this->auth_model->logout(); $this->auth_model->logout();
redirect('auth'); redirect('login');
} }
} }

View File

@ -25,9 +25,9 @@ public function is_logged_in()
public function get_logged_user() public function get_logged_user()
{ {
if ($this->is_logged_in()) { if ($this->is_logged_in()) {
$this->db->select('u.*, c.name as country, c.currency_name, c.currency_code, c.currency_symbol'); $this->db->select('u.*');
$this->db->from('users as u'); $this->db->from('users as u');
$this->db->join('country as c', 'c.id = u.country', 'LEFT'); // $this->db->join('country as c', 'c.id = u.country', 'LEFT');
$this->db->where('u.id', $this->session->userdata('id')); $this->db->where('u.id', $this->session->userdata('id'));
$query = $this->db->get(); $query = $this->db->get();
return $query->row(); return $query->row();
@ -45,7 +45,7 @@ public function get_user($id)
//is admin //is admin
public function is_admin() public function is_admin()
{ {
get_header_info(); // get_header_info();
//check logged in //check logged in
if (!$this->is_logged_in()) { if (!$this->is_logged_in()) {
return false; return false;
@ -62,7 +62,7 @@ public function is_admin()
//is user //is user
public function is_user() public function is_user()
{ {
get_header_info(); // get_header_info();
//check logged in //check logged in
if (!$this->is_logged_in()) { if (!$this->is_logged_in()) {
return false; return false;

View File

@ -72,7 +72,7 @@
<div id="body"> <div id="body">
<form method="post" action="<?php echo base_url().'auth/authendicate'?> "> <form method="post" action="<?php echo base_url().'auth/authendicate'?> ">
<input type="text" value="test@test.com" name="user_name"> <input type="text" value="sadmin@test.com" name="user_name">
<input type="text" value="password" name="password"> <input type="text" value="password" name="password">
<!-- csrf token --> <!-- csrf token -->
<input type="text" name="<?php echo $this->security->get_csrf_token_name();?>" value="<?php echo $this->security->get_csrf_hash();?>"> <input type="text" name="<?php echo $this->security->get_csrf_token_name();?>" value="<?php echo $this->security->get_csrf_hash();?>">

View File

@ -82,9 +82,19 @@
{ {
echo '<h3>'.$address1.'</h3>'; echo '<h3>'.$address1.'</h3>';
} }
?> ?>
</div> </div>
<div>
<p>LOGGEDIN : <?php echo check_auth()?></p>
<p>IS_ADMIN : <?php echo is_admin()?></p>
<p>IS_USER : <?php echo is_user()?></p>
<p>USER : <?php print_r(user())?></p>
<p>SETTINGS : <?php print_r($settings) ?></p>
<p>BUSINESS : <?php print_r($business) ?></p>
</div>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p> <p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
</div> </div>

View File

@ -1,2 +1 @@
<h1>Head<?php echo $copyright_from_mycontroller; ?> <h1>Head</h1>
<br><br>Head :<?php echo $global_data['copyright_from_mycontroller']; ?></h1>