From 108fa4d41caeddd65dc1a690fa8fa90ad9777695 Mon Sep 17 00:00:00 2001 From: Velz2020 Date: Tue, 20 Dec 2022 23:50:30 +0530 Subject: [PATCH] Setup Refined --- application/config/testing/autoload.php | 2 +- application/config/testing/routes.php | 4 ++ application/core/Admin_Controller.php | 16 ++++---- application/core/MY_Controller.php | 4 +- application/core/MY_Model.php | 40 +++++++++++++++++++ application/helpers/custom_helper.php | 12 +++--- application/modules/Auth/controllers/Auth.php | 15 +++---- .../modules/Auth/models/Auth_model.php | 8 ++-- application/modules/Auth/views/login.php | 2 +- .../modules/Dashboard/views/dashboard.php | 10 +++++ .../modules/Layout/views/includes/head.php | 3 +- 11 files changed, 86 insertions(+), 30 deletions(-) diff --git a/application/config/testing/autoload.php b/application/config/testing/autoload.php index 4e42090..1eac0b5 100644 --- a/application/config/testing/autoload.php +++ b/application/config/testing/autoload.php @@ -132,4 +132,4 @@ | | $autoload['model'] = array('first_model' => 'first'); */ -$autoload['model'] = array(); +$autoload['model'] = array('auth/auth_model'); diff --git a/application/config/testing/routes.php b/application/config/testing/routes.php index 42d0e8c..f17dbb6 100644 --- a/application/config/testing/routes.php +++ b/application/config/testing/routes.php @@ -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'; diff --git a/application/core/Admin_Controller.php b/application/core/Admin_Controller.php index 9e3213f..e518d3a 100644 --- a/application/core/Admin_Controller.php +++ b/application/core/Admin_Controller.php @@ -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); } } diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 6cb17d2..169be10 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -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'); } } diff --git a/application/core/MY_Model.php b/application/core/MY_Model.php index 5b0e135..31df90c 100644 --- a/application/core/MY_Model.php +++ b/application/core/MY_Model.php @@ -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; + } + + } diff --git a/application/helpers/custom_helper.php b/application/helpers/custom_helper.php index c05f980..60fd501 100644 --- a/application/helpers/custom_helper.php +++ b/application/helpers/custom_helper.php @@ -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; } } diff --git a/application/modules/Auth/controllers/Auth.php b/application/modules/Auth/controllers/Auth.php index 234c08b..fbafb17 100644 --- a/application/modules/Auth/controllers/Auth.php +++ b/application/modules/Auth/controllers/Auth.php @@ -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'); } } diff --git a/application/modules/Auth/models/Auth_model.php b/application/modules/Auth/models/Auth_model.php index 67430f1..d8d874f 100644 --- a/application/modules/Auth/models/Auth_model.php +++ b/application/modules/Auth/models/Auth_model.php @@ -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; diff --git a/application/modules/Auth/views/login.php b/application/modules/Auth/views/login.php index c925f27..d67de15 100644 --- a/application/modules/Auth/views/login.php +++ b/application/modules/Auth/views/login.php @@ -72,7 +72,7 @@
- + diff --git a/application/modules/Dashboard/views/dashboard.php b/application/modules/Dashboard/views/dashboard.php index 45a6518..e414ede 100644 --- a/application/modules/Dashboard/views/dashboard.php +++ b/application/modules/Dashboard/views/dashboard.php @@ -82,9 +82,19 @@ { echo '

'.$address1.'

'; } + + ?>
+
+

LOGGEDIN :

+

IS_ADMIN :

+

IS_USER :

+

USER :

+

SETTINGS :

+

BUSINESS :

+
diff --git a/application/modules/Layout/views/includes/head.php b/application/modules/Layout/views/includes/head.php index 542b736..9db6919 100644 --- a/application/modules/Layout/views/includes/head.php +++ b/application/modules/Layout/views/includes/head.php @@ -1,2 +1 @@ -

Head -

Head :

\ No newline at end of file +

Head