Merge pull request #40 from Newtbot/Dev-branch

login WIP
This commit is contained in:
noot
2024-01-20 04:13:41 +08:00
committed by GitHub
7 changed files with 141 additions and 54 deletions

View File

@ -65,7 +65,7 @@ body {
header {
font-size: 30px;
text-align: center;
color: #fff;
color: #000000;
font-weight: 600;
cursor: pointer;
}
@ -92,6 +92,7 @@ body {
margin-top: 50px;
}
form
input {
height: 60px;
@ -105,6 +106,7 @@ form
border-radius: 8px;
background: #fff;
}
.form.login
input {
border: 1px

View File

@ -12,7 +12,7 @@ app.util = (function (app) {
function actionMessage(message, $target, type, callback) {
message = message || "";
$target = $target.closest("div.card").find(".actionMessage");
$target = $target.closest("div.iot-card").find(".actionMessage");
type = type || "info";
callback = callback || function () {};
@ -29,9 +29,6 @@ app.util = (function (app) {
});
} else {
if (type) $target.addClass("bg-" + type);
message =
'<button class="action-close btn btn-sm btn-outline-dark float-right"><i class="fa-solid fa-xmark"></i></button>' +
message;
$target.html(message).slideDown("fast");
}
setTimeout(callback, 10);
@ -137,6 +134,7 @@ app.api = (function (app) {
complete: function (res, text) {
callback(
text !== "success" ? res.statusText : null,
//console.log(res.responseText),
JSON.parse(res.responseText),
res.status
);
@ -213,14 +211,15 @@ app.auth = (function (app) {
location.href.replace(location.replace(`/login`)) || "/";
}
function homeRedirect(){
window.location.href =
location.href.replace(location.replace(`/`)) || "/";
function homeRedirect() {
window.location.href = location.href.replace(location.replace(`/`)) || "/";
}
return {
getToken: getToken,
setToken: setToken,
setUserId: setUserId,
setUsername: setUsername,
isLoggedIn: isLoggedIn,
//logIn: logIn,
logOut: logOut,
@ -231,31 +230,27 @@ app.auth = (function (app) {
})(app);
//ajax form submit
function formAJAX( btn, del ) {
event.preventDefault(); // avoid to execute the actual submit of the form.
var $form = $(btn).closest( '[action]' ); // gets the 'form' parent
var formData = $form.find( '[name]' ).serializeObject(); // builds query formDataing
var method = $form.attr('method') || 'post';
function formAJAX(btn, del) {
event.preventDefault(); // avoid to execute the actual submit of the form.
var $form = $(btn).closest("[action]"); // gets the 'form' parent
var formData = $form.find("[name]").serializeObject(); // builds query formDataing
var method = $form.attr("method") || "post";
// if( !$form.validate()) {
// app.util.actionMessage('Please fix the form errors.', $form, 'danger')
// return false;
// }
app.util.actionMessage(
'<div class="spinner-border" role="status"><span class="sr-only">Loading...</span></div>',
$form,
'info'
);
// if( !$form.validate()) {
// app.util.actionMessage('Please fix the form errors.', $form, 'danger')
// return false;
// }
//console.log('Data being sent to', $form.attr('action'), formData)
app.util.actionMessage("Loading...", $form, "info");
app.api[method]($form.attr('action'), formData, function(error, data){
//console.log('Data back from the server', error, data)
app.util.actionMessage(data.message, $form, error ? 'danger' : 'success'); //re-populate table
if(!error){
$form.trigger("reset");
eval($form.attr('evalAJAX')); //gets JS to run after completion
}
});
}
//console.log('Data being sent to', $form.attr('action'), formData)
app.api[method]($form.attr("action"), formData, function (error, data) {
//console.log('Data back from the server', error, data)
app.util.actionMessage(data.message, $form, error ? "danger" : "success"); //re-populate table
if (!error) {
$form.trigger("reset");
eval($form.attr("evalAJAX")); //gets JS to run after completion
}
});
}