diff --git a/.env b/.env index ee3e3ec5..4b786128 100644 --- a/.env +++ b/.env @@ -141,3 +141,4 @@ CI_ENVIRONMENT = development #-------------------------------------------------------------------- # curlrequest.shareOptions = true +APP_TIMEZONE = 'Asia/Kolkata' diff --git a/app/Config/App.php b/app/Config/App.php index 52b2a310..2bde670b 100644 --- a/app/Config/App.php +++ b/app/Config/App.php @@ -7,6 +7,7 @@ use CodeIgniter\Session\Handlers\FileHandler; class App extends BaseConfig { + /** * -------------------------------------------------------------------------- * Base Site URL @@ -115,7 +116,18 @@ class App extends BaseConfig * * @see https://www.php.net/manual/en/timezones.php for list of timezones supported by PHP. */ - public string $appTimezone = 'UTC'; + // public string $appTimezone = 'UTC'; + public $appTimezone = 'UTC'; // Set default timezone + public function __construct() + { + parent::__construct(); + + // Read APP_TIMEZONE from environment and update appTimezone if available + $envTimezone = $_ENV['APP_TIMEZONE'] ?? null; + if ($envTimezone) { + $this->appTimezone = $envTimezone; + } + } /** * -------------------------------------------------------------------------- diff --git a/app/Config/Constants.php b/app/Config/Constants.php index bae5eb9e..b9cb843e 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -94,11 +94,6 @@ define('EVENT_PRIORITY_NORMAL', 100); define('EVENT_PRIORITY_HIGH', 10); /** - * Dummy Constants For Api Integration. + * Constants For Api Integration. */ -define('WPBOOK_DETAILS', 'https://reqres.in/api/users?page=2'); -define('WPBOOK_DETAILS_GET_PARAMETER', 'https://reqres.in/api/users?page=2'); -define('WPBOOK_DETAILS_GET_STRAIGHTFORWARD', 'https://reqres.in/api/users'); -define('WPBOOK_DETAILS_GET_SEGMENT', 'https://reqres.in/api/users/2'); -define('WPBOOK_DETAILS_POST', 'https://reqres.in/api/users'); -define('WPBOOK_DETAILS_PUT', 'https://reqres.in/api/users/707'); +define('VPB_BOOK', 'https://vbp.venbait.in/wp-json/wc/v3/products'); diff --git a/app/Config/Email.php b/app/Config/Email.php index 01350186..3875d5f1 100644 --- a/app/Config/Email.php +++ b/app/Config/Email.php @@ -18,7 +18,7 @@ class Email extends BaseConfig /** * The mail sending protocol: mail, sendmail, smtp */ - public string $protocol = 'mail'; + public string $protocol = 'smtp'; /** * The server path to Sendmail. @@ -28,27 +28,29 @@ class Email extends BaseConfig /** * SMTP Server Address */ - public string $SMTPHost = ''; + public string $SMTPHost = 'bh-in-11.webhostbox.net'; /** * SMTP Username */ - public string $SMTPUser = ''; + public string $SMTPUser = 'devbook@mprkv.co.in'; + //public string $SMTPUser = 'venbalap08@gmail.com'; /** * SMTP Password */ - public string $SMTPPass = ''; + public string $SMTPPass = 'DevBook@2023'; + //public string $SMTPPass = 'sganobynfyouaxgs'; /** * SMTP Port */ - public int $SMTPPort = 25; + public int $SMTPPort = 465; /** * SMTP Timeout (in seconds) */ - public int $SMTPTimeout = 5; + public int $SMTPTimeout = 20; /** * Enable persistent SMTP connections @@ -58,7 +60,7 @@ class Email extends BaseConfig /** * SMTP Encryption. Either tls or ssl */ - public string $SMTPCrypto = 'tls'; + public string $SMTPCrypto = 'ssl'; /** * Enable word-wrap @@ -73,7 +75,7 @@ class Email extends BaseConfig /** * Type of mail, either 'text' or 'html' */ - public string $mailType = 'text'; + public string $mailType = 'html'; /** * Character set (utf-8, iso-8859-1, etc.) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index dc98c576..29aed9aa 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -33,8 +33,11 @@ $routes->set404Override(); # Authentication Routes $routes->get('/', 'Authentication::index'); $routes->get('login/', 'Authentication::index'); -$routes->post('authenticate/', 'Authentication::authenticate'); +$routes->post('authenticate/', 'Authentication::authenticate');//Routes For Authentication. $routes->get('logout/', 'Authentication::logout'); +$routes->get('auth_confirm_mail/', 'Authentication::auth_confirm_mail');//Routes For Confirmation Mail alert page. +$routes->get('auth_reset_password/', 'Authentication::auth_reset_password');//Routes For Load Reset password Page. +$routes->post('auth_reset_password_save/', 'Authentication::auth_reset_password_save');//Routes For update the Resetted password. # Dashboard Routes $routes->get('dashboard/', 'Home::index'); diff --git a/app/Controllers/Authentication.php b/app/Controllers/Authentication.php index b284188f..0b4bf994 100755 --- a/app/Controllers/Authentication.php +++ b/app/Controllers/Authentication.php @@ -4,23 +4,28 @@ namespace App\Controllers; use App\Models\AuthenticationModel; -## Authentication Controllers only for Login,Logout,Signup,forgotpassword,confirmationpassword,resetpassword,session,cookie Modules +## Authentication Controllers only for Login,Logout,forgotpassword,confirmationpassword,resetpassword,session,cookie,lock-screen Modules class Authentication extends BaseController { + ## Load Login Page public function index() { - // Load the view - $data['company_name'] = 'Publishing'; - $data['company_short_name'] = 'P'; - $data['page_name'] = 'Login'; - // $data['browser_title'] = $data['company_name'].' | '.$data['company_short_name'] .' '. $data['page_name']; - echo view('auth_login'); + // Retrieve flashed session data + $successMessage = session()->getFlashdata('success'); + $validationErrors = session()->getFlashdata('error'); + + // Load and display the form view with the above data + // Here, we'll use the default View class for demonstration purposes + $alerts = [ + 'successMessage' => $successMessage, + 'validationErrors' => $validationErrors, + ]; + return view('auth_login', $alerts); } + ## Authenticate the users and Redirect to Dashboard public function authenticate() { - - $validation = \Config\Services::validation(); $auth_model = new AuthenticationModel(); $rules = [ 'username' => 'required', @@ -32,17 +37,18 @@ class Authentication extends BaseController $password = $this->request->getPost('password'); $user = $auth_model->where('email', $username)->first(); - // print_r($user);die; + // $this->logger->info("Authenticate: Function Called."); + if (is_null($user)) { - return redirect()->back()->with('error', 'Invalid username or password.'); - // return redirect()->back()->withInput()->with('error', 'Invalid username or password.'); + $this->logger->error('User does not exist'); + return redirect()->back()->withInput()->with('error', 'User does not exist'); } $pwd_verify = password_verify((string)$password, $user['password']); if (!$pwd_verify) { - // return redirect()->back()->with('error', 'Invalid username or password.'); - return redirect()->back()->withInput()->with('error', 'Invalid username or password.'); + $this->logger->error('Invalid Password'); + return redirect()->back()->withInput()->with('error', 'Invalid Password.'); } // You can implement your authentication logic here @@ -59,28 +65,178 @@ class Authentication extends BaseController // $cookie = \Config\Services::cookie(); // $cookie->setCookie('remember_username', 'Sri Harsha', 3600); // Cookie expires in 1 hour - + } else { // Invalid credentials, display error message // return redirect()->back()->with('error', 'Invalid username or password.'); + $this->logger->error('Invalid username or password.'); return redirect()->back()->withInput()->with('error', 'Invalid username or password.'); } } else { // Validation failed, display errors // return redirect()->back()->withInput()->with('validation', $validation); - return redirect()->back()->withInput()->with('error', 'Invalid username or password.'); + $this->logger->error('Username or password Required.'); + return redirect()->back()->withInput()->with('error', 'Username or password Required.'); } } + ## Load Forgot password Confirmation Alert + public function auth_confirm_mail() + { + // Get the email address from the request + $email = $this->request->getGet('email'); + $url_domain = base_url(); + + // Validate the email address + $validation_rules = [ + 'email' => 'required|valid_email', + ]; + + if (!$this->validate($validation_rules)) { + $this->logger->error('enter correct mail to reset your Password'); + return redirect()->back()->withInput()->with('error', 'Enter correct E-mail to reset your password'); + } + + // Check if the email exists in the database + $auth_model = new AuthenticationModel(); + // $user = $auth_model->where('email', $email)->first(); + $where = ['email' => $email, 'isactive' => 1]; + $user = $auth_model->where($where)->first(); + + if (!$user) { + $this->logger->error('There is no user enteries against given mail'); + return redirect()->back()->withInput()->with('error', 'There is no user enteries against given mail'); + } else { + $data['email'] = $email; + // Generate a unique token for password reset + $token = bin2hex(random_bytes(32)); + $content = "Click the link below to reset your password : " . $url_domain . "reset_password?email=" . $email . "&token=" . $token; + // $email = \Config\Services::email(); + // $email->setTo('sanjeev.p@venbainfotech.com'); + // $email->setFrom('venbalap08@gmail.com', 'BB-VBP'); + // $email->setSubject('BB-VBP Password Reset'); + // $email->setMessage($content); + + + + // $email->setTo('venbalap08@gmail.com'); + // $email->setFrom('venbalap08@gmail.com'); + // $email->setSubject('Password Reset Testing'); + // $email->setMessage('ZXER'); + + + // if ($email->send()) { + // // Email sent successfully + // return view('auth_confirm_mail', $data); + // } else { + // $this->logger->error('Email Not Sended,Try Again'); + // return redirect()->back()->withInput()->with('error', 'Email Not Sended,Try Again'); + // } + + $update_token['reset_link'] = $token; + $auth_model->update($user['user_id'], $update_token); + $data['link'] = $url_domain . "auth_reset_password?email=" . $email . "&token=" . $token; + // Retrieve flashed session data + $successMessage = session()->getFlashdata('success'); + $validationErrors = session()->getFlashdata('error'); + + // Load and display the form view with the above data + // Here, we'll use the default View class for demonstration purposes + $data['successMessage'] = $successMessage; + $data['validationErrors'] = $validationErrors; + return view('auth_confirm_mail', $data); + } + } + + ## Load Reset password Page + public function auth_reset_password() + { + + $email = $this->request->getGet('email'); + $token = $this->request->getGet('token'); + + $auth_model = new AuthenticationModel(); + $where = ['email' => $email, 'reset_link' => $token, 'isactive' => 1]; + $user = $auth_model->where($where)->first(); + if (!$user) { + $this->logger->error('Invaild link for this Email'); + return redirect()->back()->withInput()->with('error', 'Invaild link for this Email'); + //return back page is auth_login + } else { + $update_token['reset_link'] = NULL; + $auth_model->update($user['user_id'], $update_token); + $data['email'] = $email; + // Retrieve flashed session data + $successMessage = session()->getFlashdata('success'); + $validationErrors = session()->getFlashdata('error'); + + // Load and display the form view with the above data + // Here, we'll use the default View class for demonstration purposes + $data['successMessage'] = $successMessage; + $data['validationErrors'] = $validationErrors; + return view('auth_reset_password', $data); + } + } + + ## Save Resetted password. and Redirect to login + public function auth_reset_password_save() + { + $auth_model = new AuthenticationModel(); + $rules = [ + 'password1' => 'required', + 'password2' => 'required', + ]; + if ($this->validate($rules)) { + $email = $this->request->getVar('email'); + $password = $this->request->getVar('password1'); + $confirmation = $this->request->getVar('password2'); + $hash_password = password_hash($password, PASSWORD_DEFAULT); + try { + // code for password confirmation + if ($password === $confirmation) { + $auth_model = new AuthenticationModel(); + $user_details = $auth_model->where(['email' => $email, 'isactive' => 1])->first(); + if ($user_details) { + $update_user_details = ['email' => $email, 'password' => $hash_password]; + $auth_model->update($update_user_details['user_id'], $update_user_details); + } + // Retrieve flashed session data + $successMessage = session()->getFlashdata('success'); + $validationErrors = session()->getFlashdata('error'); + + // Load and display the form view with the above data + // Here, we'll use the default View class for demonstration purposes + $data['successMessage'] = $successMessage; + $data['validationErrors'] = $validationErrors; + return view('auth_login', $data); + } else { + // Password confirmation failed + $this->logger->error('Password confirmation failed'); + return redirect()->back()->withInput()->with('error', 'Password confirmation failed'); + } + } catch (\Exception $e) { + $error = "Exception Errno returned" . $e->getCode() . "
"; + $error_msg = $e->getMessage(); + $this->logger->error($error . '(' . $error_msg . ')'); + return redirect()->back()->withInput()->with('error', $error . '(' . $error_msg . ')'); + } + } else { + // Validation failed, display errors + $this->logger->error('Password And Confirmation Password are Required.'); + return redirect()->back()->withInput()->with('error', 'Password And Confirmation Password are Required.'); + } + } + + ## Logout With destory Session Details public function logout() { // Clear session and cookies $session = session(); - + // Regenerate the session ID $session->regenerate(); - + // Clear session data and perform logout logic $session->destroy(); // $cookie = \Config\Services::cookie(); @@ -96,6 +252,7 @@ class Authentication extends BaseController return redirect()->to('/login'); // } + ## Lock Screen - holded public function lockscreen() { // Load the session library @@ -111,6 +268,7 @@ class Authentication extends BaseController } } + ## Lock Screen - holded public function lock() { // Load the session library @@ -123,6 +281,7 @@ class Authentication extends BaseController return redirect()->to('lockscreen'); // Replace with your lock screen URL } + ## Unlock Screen - holded public function unlock() { // Load the session library @@ -141,7 +300,7 @@ class Authentication extends BaseController } } - // Replace with your password checking logic + ## Unlock Screen - Replace with your password checking logic - holded private function checkPassword($password) { // Implement your password validation logic here diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 653315f3..69c4838b 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -1,6 +1,8 @@ "Soumitra", "job" => "Blog Author", "avatar" => "https://roytuts.com/about/")); - $response_4 = perform_http_request('POST', WPBOOK_DETAILS_POST, $request_data); - $data['new_book'] = $response_4; - //PUT - update book - $request_data = json_encode(array("name" => "Soumitra", "job" => "Roy Tutorials Author", "avatar" => "https://roytuts.com/about/")); - $response_5 = perform_http_request('PUT', WPBOOK_DETAILS_PUT, $request_data); - $data['update_book'] = $response_5; - //View - // print_r($data); - return view('api_list', $data); + helper('session'); + $session_role = get_user_role(); + $session_uid = get_logged_user_id(); + $response = perform_http_request('GET', VPB_BOOK); + $message = ""; + if(count($response['response'])>0){ + //$message = "Reponse Count : ".count($response['response'])."
"; + echo "Reponse Count : ".count($response['response'])."
"; + $BooksModel = new BooksModel(); + foreach($response['response'] as $row){ + if($row->status == "publish"){ + $publisher = ''; + $language = ''; + $attributes = $row->attributes; + if(count($attributes)>0){ + foreach ($attributes as $att){ + if($att->name == "Publisher"){ $publisher = implode(", ",$att->options); } + if($att->name == "Book Author"){ $publisher .= implode(", ",$att->options)."(Book Author)"; } + if($att->name == "Book Language"){ $language = implode(", ",$att->options); } + } + } + // echo $row->permalink ; + $insertion_data['title'] = $row->name ; + $insertion_data['publication_date'] = $row->date_created; + $insertion_data['publisher'] = $publisher; + $insertion_data['genre'] = $row->description; + $insertion_data['language'] = $language; + $insertion_data['description'] = $row->short_description; + $insertion_data['page_count']=''; + $insertion_data['price'] = $row->sale_price != '' ? $row->sale_price : $row->regular_price; + $insertion_data['created_by'] = $session_uid; + $insertion_data['isactive'] = 1; + $insertion_data['business_id'] = 1; + $images = $row->images; + $i = 0; + $BooksModel->insert($insertion_data); + $lastInsertId = $BooksModel->insertID(); + $insertion_img_data = []; + // $message .= "book ID : ".$lastInsertId." have Imgs".count($images)."
"; + echo "book ID : ".$lastInsertId." have Imgs".count($images)."
"; + if(count($images)>0){ + foreach ($images as $img){ + $insertion_img_data[$i]['img_name'] = $img->src; + $insertion_img_data[$i]['is_cover'] = 0; + $insertion_img_data[$i]['type'] = 2; + $insertion_img_data[$i]['book_id'] = $lastInsertId; + $insertion_img_data[$i]['created_by'] = $session_uid; + $insertion_img_data[$i]['isactive'] = 1; + $i++; + } // image loop closed + $BooksModel->insertImagesBatch($insertion_img_data); + //$message .= "book ID : ".$lastInsertId." Img. Batch Inserted Done
"; + echo "book ID : ".$lastInsertId." Img. Batch Inserted Done
"; + }//image count closed + }//if cond. closed + }//reponse foreach closed + }//reponse count if closed + if(!empty($response['error'])){ + echo $response['error']; + echo $response['error_msg']; + $message .= $response['error'].$response['error_msg']; + echo $response['error'].$response['error_msg']; + } + //return $message; + echo "Done"; } } diff --git a/app/Controllers/Users.php b/app/Controllers/Users.php index 525df3d8..55d5b105 100755 --- a/app/Controllers/Users.php +++ b/app/Controllers/Users.php @@ -125,7 +125,6 @@ class Users extends BaseController 'role' => $this->request->getPost('role'), 'first_name' => $this->request->getPost('first_name'), 'last_name' => $this->request->getPost('last_name'), - 'password' => $this->request->getPost('password'), 'mobile_no' => $this->request->getPost('mobile_no'), 'date_of_birth' => $this->request->getPost('date_of_birth'), 'address' => $this->request->getPost('address'), @@ -136,7 +135,10 @@ class Users extends BaseController if (empty($user_id)) { // It's an insert operation + $password = $this->request->getVar('password'); + $hash_password = password_hash($password, PASSWORD_DEFAULT); $data['isactive'] = 1; + $data['password'] = $hash_password; $data['created_by'] = $session_uid; //print_r($data);die; $UsersModel->insert($data); diff --git a/app/Helpers/apiIntegration_helper.php b/app/Helpers/apiIntegration_helper.php index 3c3e2a09..c6bf5112 100644 --- a/app/Helpers/apiIntegration_helper.php +++ b/app/Helpers/apiIntegration_helper.php @@ -1,36 +1,60 @@ Curl Errno returned $curl_errno
"; + } + else{ $error = "Curl Errno returned $curl_errno
"; } + $error_msg = curl_error($curl); + }else{ + $error = ""; + $error_msg = ""; + } + curl_close($curl); + $response = (array) json_decode($result); + }catch (Exception $e) { + $error = "Exception Errno returned".$e->getCode()."
"; + $error_msg = $e->getMessage(); + $response = array(); + } - - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //If SSL Certificate Not Available, for example, I am calling from http://localhost URL - // curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true ); - $result = curl_exec($curl); - curl_close($curl); - // print_r(json_decode($result)); - return $result; + $final = array( "response"=>$response,"error"=>$error,"error_msg"=>$error_msg); + return $final; } - ?> \ No newline at end of file diff --git a/app/Models/AuthenticationModel.php b/app/Models/AuthenticationModel.php index 2e481bda..e6a3a95d 100644 --- a/app/Models/AuthenticationModel.php +++ b/app/Models/AuthenticationModel.php @@ -5,7 +5,7 @@ class AuthenticationModel extends Model { protected $table = 'users'; protected $primaryKey = 'user_id'; - protected $allowedFields = ['user_id','user_name','email','first_name','last_name','password','mobile_no','date_of_birth','address','gender','profile_picture','city','state','postal_code','country','role','isactive','business_id']; + protected $allowedFields = ['user_id','user_name','email','first_name','last_name','password','mobile_no','date_of_birth','address','gender','profile_picture','city','state','postal_code','country','role','isactive','business_id','reset_link']; public function getheringDetailsForHeader($user_id) { diff --git a/app/Models/BooksModel.php b/app/Models/BooksModel.php index e0dada6b..7fe15298 100644 --- a/app/Models/BooksModel.php +++ b/app/Models/BooksModel.php @@ -17,5 +17,14 @@ class BooksModel extends Model return $this->update($id, $data); } } - + + public function insertImages($imgData) { + $this->db->table('book_images')->insert($imgData); + return $this->db->insertID(); // Return the last inserted ID + } + + public function insertImagesBatch($imgDataArray) { + $this->db->table('book_images')->insertBatch($imgDataArray); + return $this->db->insertID(); // Note: insertID() might not be applicable for batch inserts + } } diff --git a/app/Views/auth_confirm_mail.php b/app/Views/auth_confirm_mail.php new file mode 100644 index 00000000..0f5491f3 --- /dev/null +++ b/app/Views/auth_confirm_mail.php @@ -0,0 +1,135 @@ + + + + + + Confirm Email Alert + + + + + + "> + + + " rel="stylesheet" type="text/css" id="bs-default-stylesheet" /> + " rel="stylesheet" type="text/css" id="app-default-stylesheet" /> + + " rel="stylesheet" type="text/css" id="bs-dark-stylesheet" /> + " rel="stylesheet" type="text/css" id="app-dark-stylesheet" /> + + + " rel="stylesheet" type="text/css" /> + + + + + +
+
+
+
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + + + +

Success !

+ + Alternative So Click here +
+
+
+ + +
+
+ +
+ +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/Views/auth_login.php b/app/Views/auth_login.php index 25de0fbc..2bffa6f6 100755 --- a/app/Views/auth_login.php +++ b/app/Views/auth_login.php @@ -1,118 +1,134 @@ - - - BigBambooBookPublish | BBBP - - - - - - "> - - " rel="stylesheet" type="text/css" id="bs-default-stylesheet" /> - " rel="stylesheet" type="text/css" id="app-default-stylesheet" /> + + + BigBambooBookPublish | BBBP + + + + + + "> - " rel="stylesheet" type="text/css" id="bs-dark-stylesheet" /> - " rel="stylesheet" type="text/css" id="app-dark-stylesheet" /> + + " rel="stylesheet" type="text/css" id="bs-default-stylesheet" /> + " rel="stylesheet" type="text/css" id="app-default-stylesheet" /> + " rel="stylesheet" type="text/css" id="bs-dark-stylesheet" /> + " rel="stylesheet" type="text/css" id="app-dark-stylesheet" /> - - " rel="stylesheet" type="text/css" /> + + " rel="stylesheet" type="text/css" /> - + - + -
-
-
-
-
+