diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 245b5619..13adcec8 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -29,22 +29,31 @@ $routes->set404Override(); // We get a performance increase by specifying the default // route since we don't have to scan directories. -$routes->get('/', 'Authentication::index'); -$routes->post('login/', 'Authentication::login'); +# Authentication Routes +$routes->get('/', 'Authentication::index'); +$routes->get('login/', 'Authentication::index'); +$routes->post('authenticate/', 'Authentication::authenticate'); +$routes->get('logout/', 'Authentication::logout'); + +# Dashboard Routes $routes->get('dashboard/', 'Home::index'); -$routes->get("user_list/", "Home::user_list"); -$routes->get("add_user/", "Home::add_user"); -$routes->get("edit_user/", "Home::edit_user"); -$routes->get("book_list/", "Home::book_list"); -$routes->get("add_book/", "Home::add_book"); -$routes->get("edit_book/", "Home::edit_book"); + +# Users Routes +$routes->get("user_list/", "Users::index"); +$routes->get("user_page/(:any)", "Users::user_page/$1"); +$routes->post("user_synchronization", "Users::user_synchronization"); + +# Books Routes +$routes->get("book_list/", "Books::index"); +$routes->get("add_book/", "Books::add_book"); +$routes->get("edit_book/", "Books::edit_book"); + $routes->get("subscribers_list/", "Home::subscribers_list"); $routes->get("add_subscribers/", "Home::add_subscribers"); $routes->get("edit_subscribers/", "Home::edit_subscribers"); $routes->get("business_list/", "Business::add_bussiness"); $routes->get("new_bussiness/", "Business::new_bussiness"); -$routes->get('dashboard/', 'Home::auth_user'); diff --git a/app/Controllers/Authentication.php b/app/Controllers/Authentication.php index 211ac50d..74833057 100755 --- a/app/Controllers/Authentication.php +++ b/app/Controllers/Authentication.php @@ -1,7 +1,10 @@ 'required', 'password' => 'required', ]; if ($this->validate($rules)) { - // Process login logic + $username = $this->request->getPost('username'); $password = $this->request->getPost('password'); + + $user = $auth_model->where('email', $username)->first(); + + if(is_null($user)) { + return redirect()->back()->with('error', 'Invalid username or password.'); + } + + $pwd_verify = password_verify((string)$password, $user['password']); + + if(!$pwd_verify) { + return redirect()->back()->with('error', 'Invalid username or password.'); + } // You can implement your authentication logic here // For example, check against a database, validate credentials, etc. - if ($this->authenticate($username, $password)) { + if ($username === $user['email'] && $pwd_verify) { + // Redirect to a dashboard or other protected area + $session = \Config\Services::session(); + $session->set('user_id', $user['user_id']); + $session->set('user_name', $user['first_name']." ".$user['last_name']); + $session->set('user_role', $user['role']); + $session->set('business_id', $user['business_id']); + + // $cookie = \Config\Services::cookie(); + // $cookie->setCookie('remember_username', 'Sri Harsha', 3600); // Cookie expires in 1 hour + return redirect()->to('dashboard'); } else { // Invalid credentials, display error message @@ -43,12 +68,75 @@ class Authentication extends BaseController } } - // Example authentication method, replace with your own logic - private function authenticate($username, $password) + + public function logout() { - // Implement your authentication logic here - // Return true if authentication is successful, false otherwise - // For example, you can compare against a database record - return ($username === 'admin@vbbook.com' && $password === 'test1234'); + + // Clear session and cookies + $session = \Config\Services::session(); + $session->remove('user_id'); + $session->destroy(); + + // $cookie = \Config\Services::cookie(); + // $remembered_username = $cookie->getCookie('remember_username'); + // $cookie->delete('remember_username'); + + // Redirect to a logout confirmation page or login page + return redirect()->to('/login'); // Replace with your login route } + + public function lockscreen() + { + // Load the session library + $session = \Config\Services::session(); + + // Check if the session is locked + if ($session->get('session_locked')) { + // Load the lock screen view + return view('lock_screen'); + } else { + // Redirect the user to their previous page or dashboard + return redirect()->to('dashboard'); // Replace with appropriate URL + } + } + + public function lock() + { + // Load the session library + $session = \Config\Services::session(); + + // Set the session_locked flag + $session->set('session_locked', true); + + // Redirect the user to the lock screen + return redirect()->to('lockscreen'); // Replace with your lock screen URL + } + + public function unlock() + { + // Load the session library + $session = \Config\Services::session(); + + // Check password logic + $password = $this->request->getPost('password'); + + if ($this->checkPassword($password)) { + // Unlock the session + $session->remove('session_locked'); + return redirect()->to('dashboard'); // Redirect to dashboard + } else { + // Incorrect password, show error + return redirect()->back()->with('error', 'Incorrect password.'); + } + } + + // Replace with your password checking logic + private function checkPassword($password) + { + // Implement your password validation logic here + // For example, compare against a stored hash + return $password === 'correct_password'; + } + + } \ No newline at end of file diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index e31ad974..8f92bffe 100755 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -8,6 +8,7 @@ use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; +use App\Models\AuthenticationModel; /** * Class BaseController @@ -58,16 +59,35 @@ abstract class BaseController extends Controller public function render_page($viewpage, $data) { + $session = \Config\Services::session(); + $session_uid = $session->get('user_id'); + $session_uname = $session->get('user_name'); + $session_role = $session->get('user_role'); + + $auth_model = new AuthenticationModel(); + $details = $auth_model->getheringDetailsForHeader($session_uid); + $data['company_name'] = $details[0]['site_name']; + $data['company_short_name'] = $details[0]['site_title']; + $data['loggedin_person'] = $session_uname; + $data['loggedin_person_role'] = $details[0]['role']; + $data['favicon'] = $details[0]['favicon']; + $data['profile_picture'] = $details[0]['profile_picture']; + $data['browser_title'] = $data['company_name'].' | '.$data['company_short_name'] .' '. $data['page_name']; + $data['heading'] = $data['page_name'] == "Dashboard" ? 'Welcome to '.$data['company_name'] : ""; + - $data['company_name'] = 'publishing'; - $data['company_short_name'] = 'VBP'; - $data['loggedin_person'] = 'Charles Deakin'; - $data['loggedin_person_role'] = 'VBP CEO'; - $data['browser_title'] = $data['company_name'].' | '.$data['company_short_name'] .' '. $data['page_name']; - $data['heading'] = $data['page_name'] == "Dashboard" ? 'Welcome to VijayabharathamPublishing.com' : ""; echo view('template/header.php', $data); echo view('template/topbar.php', $data); echo view($viewpage, $data); echo view('template/footer.php', $data); + + // $header = view('template/header.php', $data); + // $topbar = view('template/topbar.php', $data); + // $content = view($viewpage, $data); + // $footer = view('template/footer.php', $data); + + // return $header . $topbar. $content . $footer; + + } } diff --git a/app/Controllers/Books.php b/app/Controllers/Books.php new file mode 100755 index 00000000..ae3648c0 --- /dev/null +++ b/app/Controllers/Books.php @@ -0,0 +1,25 @@ +get('user_role'); + $session_bid = $session->get('business_id'); + $where = ['books.isactive' => 1]; + if (!empty($session_role) && $session_role !== "sadmin" ) { + $where = ['books.business_id' => $session_bid,'books.isactive' => 1]; + } + + $model = new BooksModel(); + $model->setTable('books'); + $book_details = $model->where($where)->orderBy('book_id', 'DESC')->findAll(); + $data['page_name'] = 'Book Details'; + $data['details'] = $book_details; + $this->render_page('book_list', $data); + } + +} \ No newline at end of file diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 53f2264f..dc6e35c5 100755 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -15,57 +15,6 @@ class Home extends BaseController // return view('template'); // } - public function render_page($viewpage, $data) - { - - $data['company_name'] = 'publishing'; - $data['company_short_name'] = 'VBP'; - $data['loggedin_person'] = 'Charles Deakin'; - $data['loggedin_person_role'] = 'VBP CEO'; - $data['browser_title'] = $data['company_name'].' | '.$data['company_short_name'] .' '. $data['page_name']; - $data['heading'] = $data['page_name'] == "Dashboard" ? 'Welcome to VijayabharathamPublishing.com' : ""; - echo view('template/header.php', $data); - echo view('template/topbar.php', $data); - echo view($viewpage, $data); - echo view('template/footer.php', $data); - } - - public function user_list() - { - $data['page_name'] = 'User Details'; - $this->render_page('user_list', $data); - } - - public function add_user() - { - $data['page_name'] = 'Add User'; - $this->render_page('user', $data); - } - - public function edit_user() - { - $data['page_name'] = 'Edit User'; - $this->render_page('user', $data); - } - - public function book_list() - { - $data['page_name'] = 'Book Details'; - $this->render_page('book_list', $data); - } - - public function add_book() - { - $data['page_name'] = 'Add Book'; - $this->render_page('book', $data); - } - - public function edit_book() - { - $data['page_name'] = 'Edit Book'; - $this->render_page('book', $data); - } - public function subscribers_list() { $data['page_name'] = 'Subscribers Details'; diff --git a/app/Controllers/Users.php b/app/Controllers/Users.php new file mode 100755 index 00000000..02aae4d0 --- /dev/null +++ b/app/Controllers/Users.php @@ -0,0 +1,74 @@ +get('user_role'); + $session_bid = $session->get('business_id'); + + $where = ['users.isactive' => 1]; + if (!empty($session_role) && $session_role !== "sadmin" ) { + $where = ['users.business_id' => (int)$session_bid,'users.isactive' => 1]; + } + $model = new UsersModel(); + $model->setTable('users'); + $user_details = $model->where($where)->orderBy('user_id', 'DESC')->findAll(); + $data['page_name'] = 'User Details'; + $data['details'] = $user_details; + $this->render_page('user_list', $data); + } + + ## To Load User Add/Update page + public function user_page($id) + { + if($id === '0') { + $data['page_name'] = 'Add User'; + $data['details'] = []; + } + else if($id !== '0') { + $data['page_name'] = 'Edit User'; + $model = new UsersModel(); + $model->setTable('users'); + $edit_user_details = $model->where(['user_id'=>$id,'isactive' => 1])->first(); + $data['details'] = $edit_user_details; + } + $this->render_page('user', $data); + } + + + ## To Save/Update User Data on DB. + public function user_synchronization() + { + $session = \Config\Services::session(); + $model = new UsersModel(); + $model->setTable('users'); + if($this->request->is('post')){ + $requestData = $this->request->getVar(); + } + $requestData['business_id'] = $session->get('business_id'); + if($requestData['user_id']){ + #edit + $requestData['updated_by'] = $session->get('user_id'); + $requestData['isactive'] = isset($requestData['isactive']) && $requestData['isactive'] == 'on' ? 1 : 0; + unset($requestData['password']); + $model->saveData($requestData, $requestData['user_id']); + + }else{ + #add + $hash_password = password_hash($requestData['password'], PASSWORD_DEFAULT); + $requestData['password'] = $hash_password; + $requestData['created_by'] = $session->get('user_id'); + $requestData['isactive'] = 1 ; + $model->saveData($requestData, null); + + } + return redirect()->route('user_list'); + } + +} \ No newline at end of file diff --git a/app/Models/AuthenticationModel.php b/app/Models/AuthenticationModel.php new file mode 100644 index 00000000..a810e91f --- /dev/null +++ b/app/Models/AuthenticationModel.php @@ -0,0 +1,22 @@ +db->table('users'); + $builder->select('user_id,user_name,email,first_name,last_name,password,mobile_no,date_of_birth,address,gender,profile_picture,city,state,postal_code,users.country,role,setting_id,site_name,site_title,favicon,logo,terms_service,footer_about,admin_email,mobile,copyright,pagination_limit,site_info,about_info,mail_protocol,mail_title,mail_host,mail_port,mail_encryption,mail_username,mail_password,currency,settings.country'); + $builder->join('settings', 'settings.admin_email = users.email', 'left'); + $builder->where('user_id', $user_id); + //$template_mapping_details['fk_entity_id']; + $query = $builder->get(); + + return $query->getResultArray(); + } +} + diff --git a/app/Models/BooksModel.php b/app/Models/BooksModel.php new file mode 100644 index 00000000..4f35b116 --- /dev/null +++ b/app/Models/BooksModel.php @@ -0,0 +1,10 @@ +insert($data); + } else { + // Update existing record + return $this->update($id, $data); + } + } + +} + diff --git a/app/Views/auth_login.php b/app/Views/auth_login.php index 04d28024..db97aa92 100755 --- a/app/Views/auth_login.php +++ b/app/Views/auth_login.php @@ -2,13 +2,13 @@ - <?= $browser_title; ?> + BigBambooBookPublish | BBBP - "> + "> " rel="stylesheet" type="text/css" id="bs-default-stylesheet" /> @@ -36,21 +36,21 @@ -

Enter your email address and password to access admin panel.

+

BigBambooBookPublish

Enter your email address and password to access admin panel.

-
" method="post"> + " method="post"> @@ -105,7 +105,7 @@ diff --git a/app/Views/book_list.php b/app/Views/book_list.php index 63367fa9..c7f73f48 100755 --- a/app/Views/book_list.php +++ b/app/Views/book_list.php @@ -17,45 +17,38 @@ Name Author - Edition/Language + Category + Language Year Of Release - State/Country Price of the Book - Book Avaialble Count + Description Status + - Cyber Crime - Tiger Nixon - 7th / English - 2023 - TamilNadu/India - ₹ 450 - 200 Copies - In-Active - - - Reinforced Concrete Design - Rory Dalyell - 1st / English - 1998 - Kerala/India - ₹ 730 - 20 Copies - Active - - - The big bull - Garrett - 2nd / Tamil - 2002 - TamilNadu/India - ₹ 1000 - 150 Copies - Active + + + + + + ₹ + + + + + + diff --git a/app/Views/template/header.php b/app/Views/template/header.php index a2b9aa5d..f0001f0f 100755 --- a/app/Views/template/header.php +++ b/app/Views/template/header.php @@ -8,7 +8,7 @@ - " > + " > " rel="stylesheet" type="text/css" /> @@ -71,7 +71,7 @@
- " alt="user-img" title="Mat Helme" + " alt="user-img" title="Mat Helme" class="rounded-circle avatar-md"> diff --git a/app/Views/user_list.php b/app/Views/user_list.php index d3712e8c..c0a681e3 100755 --- a/app/Views/user_list.php +++ b/app/Views/user_list.php @@ -2,9 +2,8 @@
-

@@ -17,44 +16,41 @@ Name + Email + Role + Mobile Number Address - State - City - Pincode Status Action - + + - Tiger Nixon - New-50,Old-09 Sri K.B. Hardwares and paints 1st floor nanganallur, - TamilNadu - Chennai - 600061 + + + + + - In-Active + - + - - Garrett Winters - Door No 1/69 B3 JaiFlats Meenampakkam, - TamilNadu - Chennai - 600041 - - Active - - - - - - +
diff --git a/public/assets/images/company/JerryCharlesMiculekPublishing.ico b/public/assets/images/company/JerryCharlesMiculekPublishing.ico new file mode 100644 index 00000000..cdd99e1a Binary files /dev/null and b/public/assets/images/company/JerryCharlesMiculekPublishing.ico differ diff --git a/public/assets/images/company/JerryCharlesMiculekPublishing.png b/public/assets/images/company/JerryCharlesMiculekPublishing.png new file mode 100644 index 00000000..59947092 Binary files /dev/null and b/public/assets/images/company/JerryCharlesMiculekPublishing.png differ diff --git a/public/assets/images/company/LuminaDatamatics.ico b/public/assets/images/company/LuminaDatamatics.ico new file mode 100644 index 00000000..cfdcc293 Binary files /dev/null and b/public/assets/images/company/LuminaDatamatics.ico differ diff --git a/public/assets/images/company/LuminaDatamatics.png b/public/assets/images/company/LuminaDatamatics.png new file mode 100644 index 00000000..7b8f17bc Binary files /dev/null and b/public/assets/images/company/LuminaDatamatics.png differ diff --git a/public/assets/images/company/RenaMadhuBalan.ico b/public/assets/images/company/RenaMadhuBalan.ico new file mode 100755 index 00000000..9eb9818b Binary files /dev/null and b/public/assets/images/company/RenaMadhuBalan.ico differ diff --git a/public/assets/images/logo.png b/public/assets/images/company/RenaMadhuBalan.png similarity index 100% rename from public/assets/images/logo.png rename to public/assets/images/company/RenaMadhuBalan.png diff --git a/public/assets/images/company/VijayabharathamPublishing.ico b/public/assets/images/company/VijayabharathamPublishing.ico new file mode 100644 index 00000000..894eafff Binary files /dev/null and b/public/assets/images/company/VijayabharathamPublishing.ico differ diff --git a/public/assets/images/company/VijayabharathamPublishing.png b/public/assets/images/company/VijayabharathamPublishing.png new file mode 100644 index 00000000..dd0dd3b3 Binary files /dev/null and b/public/assets/images/company/VijayabharathamPublishing.png differ diff --git a/public/assets/images/company/default.ico b/public/assets/images/company/default.ico new file mode 100644 index 00000000..932f2118 Binary files /dev/null and b/public/assets/images/company/default.ico differ diff --git a/public/assets/images/company/default.png b/public/assets/images/company/default.png new file mode 100644 index 00000000..4b659d03 Binary files /dev/null and b/public/assets/images/company/default.png differ diff --git a/public/assets/images/favicon.ico b/public/assets/images/favicon.ico old mode 100755 new mode 100644 index 9eb9818b..062b800a Binary files a/public/assets/images/favicon.ico and b/public/assets/images/favicon.ico differ