diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 08ab34b..bbd0300 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -35,7 +35,7 @@ $routes->get('/', 'Authentication::index'); $routes->get('login/', 'Authentication::index'); $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->post('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. $routes->get('lockscreen/', 'Authentication::lockscreen'); diff --git a/app/Controllers/Authentication.php b/app/Controllers/Authentication.php index c3cdeb2..49a32b4 100644 --- a/app/Controllers/Authentication.php +++ b/app/Controllers/Authentication.php @@ -83,20 +83,22 @@ class Authentication extends BaseController ## Load Forgot password Confirmation Alert public function auth_confirm_mail() { - $this->logger->info("auth confirm mail: auth confirm mail"); - - // Get the email address from the request - $mail_id = $this->request->getGet('email'); + $mail_id = $this->request->getPost('email'); $url_domain = base_url(); + $this->logger->info("auth confirm mail : Mail = ".$mail_id); + $this->logger->info("auth confirm mail : Domain = ".$url_domain); + // 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'); + $response['status'] = false; + $response['message'] = 'Enter correct E-mail to reset your password'; + $this->logger->error($response['message']); + return $this->response->setJSON(['data' => $response]); } // Check if the email exists in the database @@ -104,15 +106,19 @@ class Authentication extends BaseController // $user = $auth_model->where('email', $mail_id)->first(); $where = ['email' => $mail_id, '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'); + $response['status'] = false; + $response['message'] = 'There is no user enteries against given mail'; + $this->logger->error($response['message']); + return $this->response->setJSON(['data' => $response]); } else { + $this->logger->info("auth confirm mail : count = ".count($user)); $data['mail_id'] = $mail_id; // Generate a unique token for password reset $token = bin2hex(random_bytes(32)); $content = "Click the link below to reset your password : " . $url_domain . "auth_reset_password?email=" . $mail_id . "&token=" . $token; + $this->logger->info("auth confirm mail : content = ".$content); $email = \Config\Services::email(); // $recipient = 'venbalap08@gmail.com'; $recipient = $mail_id; @@ -127,22 +133,20 @@ class Authentication extends BaseController $update_token['reset_link'] = $token; $auth_model->update($user['user_id'], $update_token); $data['link'] = $url_domain . "auth_reset_password?email=" . $mail_id . "&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); + if ($email->send()) { - // Email sent successfully - return view('auth_confirm_mail', $data); + $this->logger->info("auth confirm mail = Email sent successfully"); + $response['status'] = true; + $response['message'] = "Password Reset Link Shared on Your Email"; + $this->logger->error($response['message']); + return $this->response->setJSON(['data' => $response]); } else { - $this->logger->error('Email Not Sended,Try Again'); - return redirect()->back()->withInput()->with('error', 'Email Not Sended,Try Again'); + $response['status'] = false; + $response['message'] = 'There is no user enteries against given mail'; + $this->logger->error($response['message']); + // return redirect()->back()->withInput()->with('error', 'Email Not Sended,Try Again'); } + return $this->response->setJSON(['data' => $response]); } } @@ -334,4 +338,4 @@ class Authentication extends BaseController $pwd_verify = password_verify((string)$password, $user['password']); return $pwd_verify ; } -} +} \ No newline at end of file diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 366fbd5..924d1cb 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -65,10 +65,10 @@ abstract class BaseController extends Controller echo "This is a command-line request."; // echo $requestedRoute; } else { - if ($requestedRoute !== 'login' && $requestedRoute !== 'authenticate') { - - $this->authData = $this->session_log(); - } + $routesArr = ['login', 'authenticate', 'auth_confirm_mail', 'auth_reset_password', 'auth_reset_password_save']; + if (!in_array($requestedRoute, $routesArr)) { + $this->authData = $this->session_log(); + } } } diff --git a/app/Views/auth_confirm_mail.php b/app/Views/auth_confirm_mail.php index e36eade..69be357 100644 --- a/app/Views/auth_confirm_mail.php +++ b/app/Views/auth_confirm_mail.php @@ -121,7 +121,7 @@ diff --git a/app/Views/auth_lock_screen.php b/app/Views/auth_lock_screen.php index 953ed9a..08ecefa 100644 --- a/app/Views/auth_lock_screen.php +++ b/app/Views/auth_lock_screen.php @@ -92,7 +92,7 @@ diff --git a/app/Views/auth_logout.php b/app/Views/auth_logout.php index 2b709b8..ff52303 100644 --- a/app/Views/auth_logout.php +++ b/app/Views/auth_logout.php @@ -92,7 +92,7 @@ diff --git a/app/Views/auth_reset_password.php b/app/Views/auth_reset_password.php index 6a518ed..2df2d15 100644 --- a/app/Views/auth_reset_password.php +++ b/app/Views/auth_reset_password.php @@ -102,7 +102,7 @@