Skip to content

Commit

Permalink
little progress....
Browse files Browse the repository at this point in the history
  • Loading branch information
neeraj-395 committed Mar 23, 2024
1 parent f543676 commit d06460b
Show file tree
Hide file tree
Showing 31 changed files with 588 additions and 505 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
bootstrap-simple-admin-template-main
database/connect.php
bootstrap-simple-admin-template-main
138 changes: 32 additions & 106 deletions assets/js/auth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
// BASE URL FOR FETCHING CONTENT
var baseURL = getBaseURL('/nsp-dbms-project'); // Define root folder name with forward slash (/) !importatant
import { baseURL, formSubmitHandler } from './inc-js/utils.inc.js';

'use strict';
$(function () {
$('<div id="cover-spin"></div>').appendTo('body'); // spinner
$("input[type='password'][data-eye]").each(function (i) {
Expand All @@ -17,14 +16,24 @@ $(function () {
$this.css({
paddingRight: 60
});
$this.after($("<div/>", {
html: $("<img>",{
src: baseURL + '/assets/img/eye-show.svg',
height: '24px',
width: '24px'
}),
id: 'passeye-toggle-' + i,
}).css({
$this.after(
$("<div/>", {
html: [
$("<img>", {
id: 'show',
src: baseURL + '/assets/img/eye-show.svg',
height: '24px',
width: '24px',
hidden: 'true'
}),
$("<img>", {
id: 'hide',
src: baseURL + '/assets/img/eye-hide.svg',
height: '24px',
width: '24px'
})],
id: 'passeye-toggle-' + i
}).css({
position: 'absolute',
right: 10,
top: ($this.outerHeight() / 2) - 12,
Expand All @@ -42,27 +51,17 @@ $(function () {
$this.after(invalid_feedback.clone());
}

$this.on("keyup paste", function () {
$("#passeye-" + i).val($(this).val());
});
$("#passeye-toggle-" + i).on("click", function () {
if ($this.hasClass("show")) {
$this.attr('type', 'password');
$this.removeClass("show");
$(this).html($("<img>",{
src: baseURL + '/assets/img/eye-show.svg',
height: '24px',
width: '24px'
}));
$(this).find('#show').attr('hidden','true');
$(this).find('#hide').removeAttr('hidden');
} else {
$this.attr('type', 'text');
$this.val($("#passeye-" + i).val());
$this.addClass("show");
$(this).html($("<img>",{
src: baseURL + '/assets/img/eye-hide.svg',
height: '24px',
width: '24px'
}));
$(this).find('#show').removeAttr('hidden');
$(this).find('#hide').attr('hidden','true');
}
});
});
Expand All @@ -74,17 +73,6 @@ document.addEventListener('DOMContentLoaded', () => {
const username = form.querySelector('#username');
const password = form.querySelector('#password');

const errMsg = {
name: "Names must start with a capital letter and have capital letters after spaces. " +
"Only alphabetical characters are allowed.",

username: "The username must start with a letter and can contain only " +
"letters, digits, or underscores, with a length between 8 and 30 characters.",

password: "Please use at least 8 characters with a combination of uppercase and " +
"lowercase letters, digits, and symbols."
};

const pattern = {
name: "^[A-Z][a-z]*( [A-Z][a-z]*)*$",
username: "^[A-Za-z][A-Za-z0-9_]{7,29}$",
Expand All @@ -95,79 +83,17 @@ document.addEventListener('DOMContentLoaded', () => {
// Prevent Deafault form submission.
event.preventDefault();

validityCheck(name, pattern.name, errMsg.name);
validityCheck(username, pattern.username, errMsg.username);
validityCheck(password, pattern.password, errMsg.password);
if(name) name.setAttribute('pattern', pattern.name);
if(username) username.setAttribute('pattern', pattern.username);
if(password) password.setAttribute('pattern', pattern.password);

if (!form.reportValidity()) {
if (!form.checkValidity()) {
event.stopPropagation();
form.classList.add("was-validated"); //dont remove
} else {
document.getElementById('cover-spin').style.display = 'block';
form.classList.add("was-validated"); //dont remove
authenticate(form, form.getAttribute('execute'));
const phpPath = baseURL + form.getAttribute('php-execute');
formSubmitHandler(new FormData(form), phpPath);
}
form.classList.add('was-validated');
});
});

function validityCheck(element, pattern, errorMessage) {
if (element === undefined || element === null) return;
element.setAttribute('pattern', pattern);
// Set custom validation message.
if (element.validity.patternMismatch) {
element.setCustomValidity(errorMessage);
} else {
element.setCustomValidity('');
}
// Check validity then set valid/invalid class appropriately.
if (element.checkValidity()) {
element.classList.remove('is-invalid');
element.classList.add('is-valid');
} else {
element.classList.remove('is-valid');
element.classList.add('is-invalid');
}
}

function authenticate(form, filepath) {
if(!filepath) return;
var file_url = baseURL + filepath;
fetch(file_url, { method:'POST', body: new FormData(form) })
.then(response => {
if (!response.ok)
throw new Error('Network response was not ok');
return response.json();
})
.then(result => {
switch(result.status){
case 200: if(result.message) alert(result.message);
if(result.redirect) window.location.href = baseURL + result.redirect;
break;
case 500: alert(result.message); // Bad response
window.location.reload();
break;
default: alert("Unexpected error occurred. Please try again later :-(");
window.location.reload();
break;
}
})
.catch(error => {
var err_msg = [
`An error has occurred, most likely due to an attempt to execute`,
`server-side scripts on a GitHub page, which is not permitted.`,
`Please run this project on a PHP-supported server for seamless functionality.`,
`\nThank you for your understanding and cooperation.`,
`\nError: ${error}`
];
alert(err_msg.join(" "));
window.location.reload();
});
}

function getBaseURL(rootFolderName) {
if(window.location.pathname.includes(rootFolderName)){
return window.location.origin + rootFolderName;
} else {
return window.location.origin;
}
}
});
100 changes: 0 additions & 100 deletions assets/js/common.js

This file was deleted.

48 changes: 48 additions & 0 deletions assets/js/content-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {baseURL} from './inc-js/utils.inc.js';

//---------------------Load Notes Content into HTML Document---------------------//
$(function(){
if ($('#content')) {
const meta = {
title: "MATT RIDLEY",
desc: "This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.",
time: "3 mins ago",
path: baseURL + "/assets/img/note-img.jpg",
vlink : "#",
dlink : "#"
}

// Add note cards along with there meta data
for (let i = 0; i < 6; i++)
$('#content').append(note_cards(meta));
}
})

function note_cards(meta) {
return `
<div class="container-sm col">
<div class="card mb-3" style="max-width: 540px;">
<div class="row g-0">
<div class="col-md-4">
<img src="${meta.path}" class="img-fluid rounded-start" alt="...">
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">${meta.title}</h5>
<p class="card-text">${meta.desc}</p>
<div class="d-flex justify-content-between align-items-center">
<div class="btn-group">
<a role="button" class="btn btn-sm btn-outline-secondary"
href="${meta.vlink}">View</a>
<a role="button" class="btn btn-sm btn-outline-secondary"
href="${meta.dlink}">Download</a>
</div>
<small class="text-body-secondary">${meta.time}</small>
</div>
</div>
</div>
</div>
</div>
</div>
`;
}
Loading

0 comments on commit d06460b

Please sign in to comment.