Setup Refined
This commit is contained in:
parent
9bb0b9d425
commit
108fa4d41c
@ -132,4 +132,4 @@
|
||||
|
|
||||
| $autoload['model'] = array('first_model' => 'first');
|
||||
*/
|
||||
$autoload['model'] = array();
|
||||
$autoload['model'] = array('auth/auth_model');
|
||||
|
||||
@ -52,3 +52,7 @@
|
||||
$route['default_controller'] = 'Backend';
|
||||
$route['404_override'] = '';
|
||||
$route['translate_uri_dashes'] = FALSE;
|
||||
|
||||
//modules routes
|
||||
$route['logout'] = 'auth/logout';
|
||||
$route['login'] = 'auth';
|
||||
|
||||
@ -23,15 +23,17 @@ class Admin_Controller extends MY_Controller
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if(!check_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');
|
||||
|
||||
|
||||
echo $copyright_from_mycontroller;die();
|
||||
if(!$this->session->userdata('logged_in') == TRUE)
|
||||
{
|
||||
redirect('auth');
|
||||
}
|
||||
|
||||
// $this->global_data['org_details'] = array('business_name' => 'XYZ');
|
||||
// $this->layout->set('global_data',$this->global_data);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,8 +45,8 @@ public function __construct()
|
||||
$date = "$begin - $end";
|
||||
|
||||
// Copyright
|
||||
$this->global_data['copyright_from_mycontroller'] = $date;
|
||||
$this->load->vars($this->global_data);
|
||||
// $this->global_data['copyright_from_mycontroller'] = $date;
|
||||
// $this->load->vars($this->global_data);
|
||||
$this->load->module('layout');
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -17,13 +17,13 @@ function check_auth()
|
||||
{
|
||||
// Get a reference to the controller object
|
||||
$ci =& get_instance();
|
||||
//return $ci->auth_model->is_logged_in();
|
||||
return $ci->auth_model->is_logged_in();
|
||||
|
||||
if($ci->session->userdata('logged_in') == TRUE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
// if($ci->session->userdata('logged_in') == TRUE)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -53,11 +53,11 @@ public function index()
|
||||
public function authendicate()
|
||||
{
|
||||
$user = $this->auth_model->validate_user();
|
||||
// print_r($user);die();
|
||||
//print_r($user);die();
|
||||
// echo hash_password('password');die();
|
||||
|
||||
if (empty($user)) {
|
||||
redirect('auth');
|
||||
redirect('login');
|
||||
}
|
||||
// if (!empty($user) && $user->status == 0) {
|
||||
// // account pending
|
||||
@ -92,24 +92,25 @@ public function authendicate()
|
||||
if(password_verify($this->input->post('password'), $user->password))
|
||||
{
|
||||
$data = array(
|
||||
'id' => $user_id,
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
//'thumb' => $user->thumb,
|
||||
'email' =>$user->email,
|
||||
// 'role' =>$user->role,
|
||||
// 'parent' =>$user->id,
|
||||
'role' =>$user->role,
|
||||
'action_permit' =>$user->action_permit,
|
||||
'business_id' =>$user->business_id,
|
||||
'logged_in' => TRUE
|
||||
);
|
||||
$data = $this->security->xss_clean($data);
|
||||
$this->session->set_userdata($data);
|
||||
redirect('dashboard');
|
||||
}
|
||||
redirect('auth');
|
||||
redirect('login');
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
$this->auth_model->logout();
|
||||
redirect('auth');
|
||||
redirect('login');
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,9 +25,9 @@ public function is_logged_in()
|
||||
public function get_logged_user()
|
||||
{
|
||||
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->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'));
|
||||
$query = $this->db->get();
|
||||
return $query->row();
|
||||
@ -45,7 +45,7 @@ public function get_user($id)
|
||||
//is admin
|
||||
public function is_admin()
|
||||
{
|
||||
get_header_info();
|
||||
// get_header_info();
|
||||
//check logged in
|
||||
if (!$this->is_logged_in()) {
|
||||
return false;
|
||||
@ -62,7 +62,7 @@ public function is_admin()
|
||||
//is user
|
||||
public function is_user()
|
||||
{
|
||||
get_header_info();
|
||||
// get_header_info();
|
||||
//check logged in
|
||||
if (!$this->is_logged_in()) {
|
||||
return false;
|
||||
|
||||
@ -72,7 +72,7 @@
|
||||
|
||||
<div id="body">
|
||||
<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">
|
||||
<!-- csrf token -->
|
||||
<input type="text" name="<?php echo $this->security->get_csrf_token_name();?>" value="<?php echo $this->security->get_csrf_hash();?>">
|
||||
|
||||
@ -82,9 +82,19 @@
|
||||
{
|
||||
echo '<h3>'.$address1.'</h3>';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
</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>
|
||||
</div>
|
||||
|
||||
@ -1,2 +1 @@
|
||||
<h1>Head<?php echo $copyright_from_mycontroller; ?>
|
||||
<br><br>Head :<?php echo $global_data['copyright_from_mycontroller']; ?></h1>
|
||||
<h1>Head</h1>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user