I would like to authenticate the user login from the databases stored in mySql database on my server.
would like to know how I can get that done when using the Datatables in your example shown.
using the html version of Metronic
Hi,
You can customize src/js/custom/authentication/sign-in/general.js
script and remove the demo form submit function and use the below one which uses ajax submit using Axios Ajax library:
var handleSubmit = function(e) {
// Handle form submit
submitButton.addEventListener("click", function (e) {
// Prevent button default action
e.preventDefault();
// Validate form
validator.validate().then(function (status) {
if (status == "Valid") {
// Hide loading indication
submitButton.removeAttribute("data-kt-indicator");
// Enable button
submitButton.disabled = false;
axios.post("/your/ajax/login/url", {
email: form.querySelector("[name="email"]").value,
password: form.querySelector("[name="password"]").value
}).then(function (response) {
if (response) {
form.querySelector("[name="email"]").value= "";
form.querySelector("[name="password"]").value= "";
const redirectUrl = form.getAttribute("data-kt-redirect-url");
if (redirectUrl) {
location.href = redirectUrl;
}
} else {
// Show error popup. For more info check the plugin"s official documentation: https://sweetalert2.github.io/
Swal.fire({
text: "Sorry, the email or password is incorrect, please try again.",
icon: "error",
buttonsStyling: false,
confirmButtonText: "Ok, got it!",
customClass: {
confirmButton: "btn btn-primary"
}
});
}
}).catch(function (error) {
Swal.fire({
text: "Sorry, looks like there are some errors detected, please try again.",
icon: "error",
buttonsStyling: false,
confirmButtonText: "Ok, got it!",
customClass: {
confirmButton: "btn btn-primary"
}
});
});
} else {
// Show error popup. For more info check the plugin"s official documentation: https://sweetalert2.github.io/
Swal.fire({
text: "Sorry, looks like there are some errors detected, please try again.",
icon: "error",
buttonsStyling: false,
confirmButtonText: "Ok, got it!",
customClass: {
confirmButton: "btn btn-primary"
}
});
}
});
});
}
Thanks Sean,
so the /your/ajax/login/url is my php program that collects the email and pwd, checks for them in the mysqldb.
and what do I return from the php file to axios?