From 6d926b495e418d38c352ef003a58017a29731b1f Mon Sep 17 00:00:00 2001 From: sayliraut Date: Mon, 12 Aug 2024 13:48:43 +0530 Subject: [PATCH] changes --- public/assets/js/admin/auth/login.js | 182 ++++++++++-------- .../pages/auth/forgot_password.blade.php | 108 +++-------- .../views/Admin/pages/auth/login.blade.php | 80 +------- .../views/Admin/pages/auth/otp.blade.php | 83 ++------ .../Admin/pages/auth/password_reset.blade.php | 115 ----------- 5 files changed, 153 insertions(+), 415 deletions(-) diff --git a/public/assets/js/admin/auth/login.js b/public/assets/js/admin/auth/login.js index 6602b7c..32d1dc0 100644 --- a/public/assets/js/admin/auth/login.js +++ b/public/assets/js/admin/auth/login.js @@ -1,13 +1,13 @@ // Login js -$(document).on("click", "#admin_login_btn", function (e) { - $("#admin_login_form").validate({ +$(document).on("click", "#admin_login_btn", function(e) { + $('#admin_login_form').validate({ rules: { email: { required: true, }, password: { required: true, - }, + } }, messages: { email: { @@ -15,150 +15,153 @@ $(document).on("click", "#admin_login_btn", function (e) { }, password: { required: "Please enter the password.", - }, + } }, - submitHandler: function (form) { + submitHandler: function(form) { e.preventDefault(); let base_url = url_path; var formData = new FormData(form); $.ajaxSetup({ headers: { - "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr( - "content" - ), + "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), }, }); $.ajax({ - url: base_url + "/check_login", - type: "POST", + url: base_url + '/check_login', + type: 'POST', data: formData, - beforeSend: function () { - $("#admin_login_btn").text("Please wait..."); - $("#admin_login_btn").attr("disabled", true); + beforeSend: function() { + $('#admin_login_btn').text('Please wait...'); + $('#admin_login_btn').attr('disabled', true); }, processData: false, contentType: false, - success: function (response) { - if (response.status == 200) { - $("#admin_login_btn").prop("disabled", false); - $("#admin_login_btn").text("Login"); - window.location.href = base_url + "/dashboard"; - } - if (response.status == 401) { + success: function(response) { + console.log(response); + $('#admin_login_btn').prop('disabled', false); + $('#admin_login_btn').text('Login'); + + if (response.status_code == 200) { + toastr.success(response.message); + setTimeout(function() { + window.location.href = base_url + "/dashboard"; + }, 2000); + } else if (response.status_code == 401) { toastr.error(response.message); form.reset(); - $("#admin_login_btn").prop("disabled", false); - $("#admin_login_btn").text("Sign In"); + } else { + toastr.error(response.message); } }, + error: function(xhr, status, error) { + toastr.error('An unexpected error occurred.'); + $('#admin_login_btn').prop('disabled', false); + $('#admin_login_btn').text('Sign In'); + } }); - }, + } }); }); // forgot password js $(document).on("click", "#forgot_password_btn", function (e) { let base_url = url_path; - $("#forgot_pass_form").validate({ + $('#forgot_pass_form').validate({ ignore: [], debug: false, rules: { email: { - required: true, - }, + required: true + } }, messages: { email: { - required: "Please Enter email", - }, + required: "Please Enter email" + } }, submitHandler: function (form) { var formData = new FormData(form); e.preventDefault(), - $.ajaxSetup({ - headers: { - "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr( - "content" - ), - }, - }); + $.ajaxSetup({ + headers: { + "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), + }, + }); $.ajax({ - url: base_url + "/send_otp", - type: "POST", + url: base_url + '/send_otp', + type: 'POST', data: formData, processData: false, contentType: false, success: function (response) { console.log(response); - if (response.status == 200) { + if (response.status_code == 200) { form.reset(); - toastr.success("Otp send it your mail id please check"); - setTimeout(function () { - // toastr.info('Please check your email to reset your password. The link is valid for 5 minutes.'); + toastr.success('An OTP has been sent to your email address'); + setTimeout(function() { window.location.href = base_url + "/otp"; - }, 1000); - } else if (response.status == 404) { - toastr.error("This email id is not exits"); - } else { - toastr.error("Something went wrong"); + }, 2000); + }else if (response.status == 404) { + toastr.error('This email id is not exits'); + } + else { + toastr.error(response.message); } }, }); - }, + } }); }); - // otp varification -$(document).on("click", "#otp_verify_button", function (e) { +$(document).on('click', '#otp_verify_button', function(e) { e.preventDefault(); // Get base URL let base_url = url_path; // Get admin ID - var id = $("#admin_otp_id").val(); + var id = $('#admin_otp_id').val(); // Get OTP by concatenating values of all OTP input fields - var otp = $(".otp") - .map(function () { - return this.value; - }) - .get() - .join(""); + var otp = $('.otp').map(function() { + return this.value; + }).get().join(''); + if (otp === '') { + toastr.error('Please enter OTP'); + return; + } // Send AJAX request for OTP verification $.ajax({ - url: base_url + "/otp_verify", - type: "POST", + url: base_url + '/otp_verify', + type: 'POST', data: { id: id, otp: otp, - _token: $('meta[name="csrf-token"]').attr("content"), + '_token': $('meta[name="csrf-token"]').attr('content') }, success: function (response) { - if (response.status == 200) { + if (response.status_code == 200) { // Display success message - toastr.success("Otp Verify Successfully"); + toastr.success('Otp Verify Successfully'); // Redirect to the dashboard after a delay setTimeout(function () { window.location.href = base_url + "/password_reset"; }, 1000); } else if (response.status == 401) { - // Display error message for invalid OTP or expired toastr.error(response.message); } else { - // Display error message for other issues - toastr.error("Something went wrong"); + toastr.error(response.message); } }, }); }); -$(document).on("input", ".otp", function () { - this.value = this.value.replace(/[^0-9]/g, ""); +$(document).on('input', '.otp', function() { + this.value = this.value.replace(/[^0-9]/g, ''); if (this.value.length >= this.maxLength) { - $(this).next(".otp").focus(); + $(this).next('.otp').focus(); } }); @@ -224,15 +227,44 @@ $(document).on("click", "#password_reset", function (e) { }); }); -$("#passwordToggle").click(function () { - var passwordInput = $("#password"); - var eyeIcon = $("#passwordToggle"); +$('#passwordToggle').click(function() { + var passwordInput = $('#password'); + var eyeIcon = $('#passwordToggle'); - if (passwordInput.attr("type") === "password") { - passwordInput.attr("type", "text"); - eyeIcon.removeClass("fa-eye-slash").addClass("fa-eye"); + if (passwordInput.attr('type') === 'password') { + passwordInput.attr('type', 'text'); + eyeIcon.removeClass('fa-eye-slash').addClass('fa-eye'); } else { - passwordInput.attr("type", "password"); - eyeIcon.removeClass("fa-eye").addClass("fa-eye-slash"); + passwordInput.attr('type', 'password'); + eyeIcon.removeClass('fa-eye').addClass('fa-eye-slash'); + } +}); + + +document.getElementById('togglePassword').addEventListener('click', function() { + var passwordField = document.getElementById('password'); + var icon = document.getElementById('togglePassword'); + if (passwordField.type === 'password') { + passwordField.type = 'text'; + icon.classList.remove('fa-eye-slash'); + icon.classList.add('fa-eye'); + } else { + passwordField.type = 'password'; + icon.classList.remove('fa-eye'); + icon.classList.add('fa-eye-slash'); + } +}); + +document.getElementById('toggleConfirmPassword').addEventListener('click', function() { + var confirmPasswordField = document.getElementById('confirm_password'); + var icon = document.getElementById('toggleConfirmPassword'); + if (confirmPasswordField.type === 'password') { + confirmPasswordField.type = 'text'; + icon.classList.remove('fa-eye-slash'); + icon.classList.add('fa-eye'); + } else { + confirmPasswordField.type = 'password'; + icon.classList.remove('fa-eye'); + icon.classList.add('fa-eye-slash'); } }); diff --git a/resources/views/Admin/pages/auth/forgot_password.blade.php b/resources/views/Admin/pages/auth/forgot_password.blade.php index cef0b3f..20ee4af 100644 --- a/resources/views/Admin/pages/auth/forgot_password.blade.php +++ b/resources/views/Admin/pages/auth/forgot_password.blade.php @@ -1,89 +1,39 @@ @extends('Admin.layouts.app_login') @section('title', 'Forgot Password') @section('content') -
-
-
- +
+
+
+ +
+
+
- -
@endsection @section('scripts') - - - - + + + @endsection diff --git a/resources/views/Admin/pages/auth/login.blade.php b/resources/views/Admin/pages/auth/login.blade.php index b73bab5..5b1a27e 100644 --- a/resources/views/Admin/pages/auth/login.blade.php +++ b/resources/views/Admin/pages/auth/login.blade.php @@ -52,84 +52,6 @@ @section('scripts') - - + @endsection diff --git a/resources/views/Admin/pages/auth/otp.blade.php b/resources/views/Admin/pages/auth/otp.blade.php index 925fa6f..0d0e31f 100644 --- a/resources/views/Admin/pages/auth/otp.blade.php +++ b/resources/views/Admin/pages/auth/otp.blade.php @@ -1,11 +1,11 @@ @extends('Admin.layouts.app_login') @section('title', 'Cheers to the Season - Otp') @section('content') -
-
+
- +
-
+
@endsection @section('scripts') - - - + + - // Get base URL - let base_url = url_path; - - // Get admin ID - var id = $('#admin_otp_id').val(); - - // Get OTP by concatenating values of all OTP input fields - var otp = $('.otp').map(function() { - return this.value; - }).get().join(''); - - if (otp === '') { - toastr.error('Please enter OTP'); - return; - } - // Send AJAX request for OTP verification - $.ajax({ - url: base_url + '/otp_verify', - type: 'POST', - data: { - id: id, - otp: otp, - '_token': $('meta[name="csrf-token"]').attr('content') - }, - success: function (response) { - if (response.status_code == 200) { - // Display success message - toastr.success('Otp Verify Successfully'); - // Redirect to the dashboard after a delay - setTimeout(function () { - window.location.href = base_url + "/password_reset"; - }, 1000); - } else if (response.status == 401) { - toastr.error(response.message); - } else { - toastr.error(response.message); - } - }, - }); -}); - - -$(document).on('input', '.otp', function() { - this.value = this.value.replace(/[^0-9]/g, ''); - - if (this.value.length >= this.maxLength) { - $(this).next('.otp').focus(); - } -}); - @endsection diff --git a/resources/views/Admin/pages/auth/password_reset.blade.php b/resources/views/Admin/pages/auth/password_reset.blade.php index 9d44ae1..e8e5010 100644 --- a/resources/views/Admin/pages/auth/password_reset.blade.php +++ b/resources/views/Admin/pages/auth/password_reset.blade.php @@ -124,119 +124,4 @@ - - - - - - - - - - @endsection