Forgot password Changes : ps
This commit is contained in:
parent
76242628f1
commit
43d27d1654
@ -35,7 +35,7 @@ $routes->get('/', 'Authentication::index');
|
|||||||
$routes->get('login/', 'Authentication::index');
|
$routes->get('login/', 'Authentication::index');
|
||||||
$routes->post('authenticate/', 'Authentication::authenticate');//Routes For Authentication.
|
$routes->post('authenticate/', 'Authentication::authenticate');//Routes For Authentication.
|
||||||
$routes->get('logout/', 'Authentication::logout');
|
$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->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->post('auth_reset_password_save/', 'Authentication::auth_reset_password_save');//Routes For update the Resetted password.
|
||||||
$routes->get('lockscreen/', 'Authentication::lockscreen');
|
$routes->get('lockscreen/', 'Authentication::lockscreen');
|
||||||
|
|||||||
@ -83,18 +83,22 @@ class Authentication extends BaseController
|
|||||||
## Load Forgot password Confirmation Alert
|
## Load Forgot password Confirmation Alert
|
||||||
public function auth_confirm_mail()
|
public function auth_confirm_mail()
|
||||||
{
|
{
|
||||||
// Get the email address from the request
|
$mail_id = $this->request->getPost('email');
|
||||||
$mail_id = $this->request->getGet('email');
|
|
||||||
$url_domain = base_url();
|
$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
|
// Validate the email address
|
||||||
$validation_rules = [
|
$validation_rules = [
|
||||||
'email' => 'required|valid_email',
|
'email' => 'required|valid_email',
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!$this->validate($validation_rules)) {
|
if (!$this->validate($validation_rules)) {
|
||||||
$this->logger->error('enter correct mail to reset your Password');
|
$response['status'] = false;
|
||||||
return redirect()->back()->withInput()->with('error', 'Enter correct E-mail to reset your password');
|
$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
|
// Check if the email exists in the database
|
||||||
@ -102,22 +106,26 @@ class Authentication extends BaseController
|
|||||||
// $user = $auth_model->where('email', $mail_id)->first();
|
// $user = $auth_model->where('email', $mail_id)->first();
|
||||||
$where = ['email' => $mail_id, 'isactive' => 1];
|
$where = ['email' => $mail_id, 'isactive' => 1];
|
||||||
$user = $auth_model->where($where)->first();
|
$user = $auth_model->where($where)->first();
|
||||||
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
$this->logger->error('There is no user enteries against given mail');
|
$response['status'] = false;
|
||||||
return redirect()->back()->withInput()->with('error', 'There is no user enteries against given mail');
|
$response['message'] = 'There is no user enteries against given mail';
|
||||||
|
$this->logger->error($response['message']);
|
||||||
|
return $this->response->setJSON(['data' => $response]);
|
||||||
} else {
|
} else {
|
||||||
|
$this->logger->info("auth confirm mail : count = ".count($user));
|
||||||
$data['mail_id'] = $mail_id;
|
$data['mail_id'] = $mail_id;
|
||||||
// Generate a unique token for password reset
|
// Generate a unique token for password reset
|
||||||
$token = bin2hex(random_bytes(32));
|
$token = bin2hex(random_bytes(32));
|
||||||
$content = "Click the link below to reset your password : " . $url_domain . "auth_reset_password?email=" . $mail_id . "&token=" . $token;
|
$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();
|
$email = \Config\Services::email();
|
||||||
// $recipient = 'venbalap08@gmail.com';
|
// $recipient = 'venbalap08@gmail.com';
|
||||||
$recipient = $mail_id;
|
$recipient = $mail_id;
|
||||||
|
|
||||||
// Compose the email
|
// Compose the email
|
||||||
$email->setTo($recipient);
|
$email->setTo($recipient);
|
||||||
$email->setFrom('no-reply@tripapprovaltool.com', 'BB-VBP');
|
$email->setFrom('no-reply@tripapprovaltool.com', 'BB-Donor');
|
||||||
$email->setSubject('Email Notification');
|
$email->setSubject('Email Notification');
|
||||||
// $email->setMessage('This is a notification email from CodeIgniter.');
|
// $email->setMessage('This is a notification email from CodeIgniter.');
|
||||||
$email->setMessage($content);
|
$email->setMessage($content);
|
||||||
@ -125,22 +133,20 @@ class Authentication extends BaseController
|
|||||||
$update_token['reset_link'] = $token;
|
$update_token['reset_link'] = $token;
|
||||||
$auth_model->update($user['user_id'], $update_token);
|
$auth_model->update($user['user_id'], $update_token);
|
||||||
$data['link'] = $url_domain . "auth_reset_password?email=" . $mail_id . "&token=" . $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()) {
|
if ($email->send()) {
|
||||||
// Email sent successfully
|
$this->logger->info("auth confirm mail = Email sent successfully");
|
||||||
return view('auth_confirm_mail', $data);
|
$response['status'] = true;
|
||||||
|
$response['message'] = "Password Reset Link Shared on Your Email";
|
||||||
|
$this->logger->error($response['message']);
|
||||||
|
return $this->response->setJSON(['data' => $response]);
|
||||||
} else {
|
} else {
|
||||||
$this->logger->error('Email Not Sended,Try Again');
|
$response['status'] = false;
|
||||||
return redirect()->back()->withInput()->with('error', 'Email Not Sended,Try Again');
|
$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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,8 +66,13 @@ abstract class BaseController extends Controller
|
|||||||
// echo $requestedRoute;
|
// echo $requestedRoute;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if ($requestedRoute !== '/login' && $requestedRoute !== '/authenticate' && $uri->getSegment(1) != 'getExpCustomerDetail'&& $uri->getSegment(1) != 'download_invoice_pdf') {
|
if ($uri->getSegment(1) != 'getExpCustomerDetail'&& $uri->getSegment(1) != 'download_invoice_pdf') {
|
||||||
$this->authData = $this->session_log();
|
$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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -120,11 +120,44 @@
|
|||||||
<script src="<?= base_url() . "public/assets/js/app.min.js" ?>"></script>
|
<script src="<?= base_url() . "public/assets/js/app.min.js" ?>"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
// $(document).ready(function() {
|
||||||
|
// // Fetch email value and set it as href for the reset link
|
||||||
|
// $('#emailaddress').on('input', function() {
|
||||||
|
// var emailValue = $(this).val();
|
||||||
|
// $('#resetLink').attr('href', 'auth_confirm_mail?email='+emailValue);
|
||||||
|
// });
|
||||||
|
// });
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Fetch email value and set it as href for the reset link
|
$('#resetLink').on('click', function(event) {
|
||||||
$('#emailaddress').on('input', function() {
|
var emailValue = $('#emailaddress').val();
|
||||||
var emailValue = $(this).val();
|
var baseUrl = "<?php echo base_url(); ?>";
|
||||||
$('#resetLink').attr('href', 'auth_confirm_mail?email='+emailValue);
|
if (!emailValue) {
|
||||||
|
event.preventDefault();
|
||||||
|
console.log('Please enter your email before clicking on "Forgot your password?"');
|
||||||
|
alert('Please enter your email before clicking on "Forgot your password?"');
|
||||||
|
} else {
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "<?= base_url() . 'auth_confirm_mail' ?>",
|
||||||
|
data: { email: emailValue },
|
||||||
|
success: function(response) {
|
||||||
|
console.log(response);
|
||||||
|
if (response['data']['status']) {
|
||||||
|
alert(response['data']['message']);
|
||||||
|
$('#emailaddress').val('');
|
||||||
|
console.log("Email confirmation successful");
|
||||||
|
} else {
|
||||||
|
alert(response['data']['message']);
|
||||||
|
console.log(response['data']['message']);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
console.log('AJAX Error:', error.responseText);
|
||||||
|
// Handle error here, if needed
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user