New design
This commit is contained in:
0
rss/js/create-account.js
Normal file
0
rss/js/create-account.js
Normal file
128
rss/js/home.js
128
rss/js/home.js
@@ -1,128 +0,0 @@
|
||||
document.addEventListener('DOMContentLoaded', async (v) => {
|
||||
let countries = await fetchCountries();
|
||||
|
||||
// Handlers
|
||||
let countrySelector = document.getElementById('userCountry');
|
||||
for(country of countries){
|
||||
countrySelector.innerHTML += `<option value="${country.text}">${country.text}</option>`;
|
||||
}
|
||||
|
||||
let signupForm = document.getElementById('signup');
|
||||
signupForm.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
document.getElementById('spinner').classList.add('show');
|
||||
|
||||
// Extract form data
|
||||
let username = signupForm.querySelector('#username').value;
|
||||
let dob = signupForm.querySelector('#u_dob').value;
|
||||
let country = signupForm.querySelector('#userCountry').value;
|
||||
let gender = signupForm.querySelector('#gender').value;
|
||||
let email = signupForm.querySelector('#email').value;
|
||||
let password = signupForm.querySelector('#password').value;
|
||||
let password2 = signupForm.querySelector('#password2').value;
|
||||
let tosInput = signupForm.querySelector('#tos');
|
||||
let tos = tosInput.checked;
|
||||
|
||||
// Remove errors
|
||||
document.getElementById('usernameError').innerText = null;
|
||||
document.getElementById('countryError').innerText = null;
|
||||
document.getElementById('emailError').innerText = null;
|
||||
document.getElementById('dobError').innerText = null;
|
||||
document.getElementById('genderError').innerText = null;
|
||||
document.getElementById('passwordError').innerText = null;
|
||||
document.getElementById('password2Error').innerText = null;
|
||||
|
||||
|
||||
let userData = {
|
||||
username: username,
|
||||
country: country,
|
||||
gender: gender,
|
||||
email: email,
|
||||
dob: dob,
|
||||
password: password,
|
||||
password2: password2,
|
||||
acceptTerms: tos
|
||||
};
|
||||
|
||||
let action = 'signup';
|
||||
|
||||
let formData = JSON.stringify({
|
||||
action: action,
|
||||
userData: userData
|
||||
});
|
||||
|
||||
// Send request
|
||||
fetch('https://api.stellaamor.com/users.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: formData
|
||||
})
|
||||
.then(response => {
|
||||
if(response && response.length){
|
||||
return response.json();
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.then(msg => {
|
||||
console.log(msg);
|
||||
// If we have a JSON response, process it; otherwise, assume success
|
||||
document.getElementById('spinner').classList.remove('show');
|
||||
if (msg && msg.status === 'fail') {
|
||||
let errorArea = msg.fail_status;
|
||||
|
||||
if (errorArea === 'username') {
|
||||
document.getElementById('usernameError').innerText = msg.message;
|
||||
}
|
||||
if (errorArea === 'country') {
|
||||
document.getElementById('countryError').innerText = msg.message;
|
||||
}
|
||||
if (errorArea === 'email') {
|
||||
document.getElementById('emailError').innerText = msg.message;
|
||||
}
|
||||
if (errorArea === 'dob') {
|
||||
document.getElementById('dobError').innerText = msg.message;
|
||||
}
|
||||
if (errorArea === 'gender') {
|
||||
document.getElementById('genderError').innerText = msg.message;
|
||||
}
|
||||
if (errorArea === 'password') {
|
||||
document.getElementById('passwordError').innerText = msg.message;
|
||||
}
|
||||
if (errorArea === 'password2' || errorArea === 'passwords') {
|
||||
document.getElementById('password2Error').innerText = msg.message;
|
||||
}
|
||||
} else {
|
||||
// Success: Redirect to signin page
|
||||
setTimeout(() => {
|
||||
window.location.href = '/signin';
|
||||
}, 2000);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during signup:', error);
|
||||
document.getElementById('errors').innerText = 'An error occurred. Please try again later.';
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Call init functions
|
||||
});
|
||||
|
||||
async function fetchCountries() {
|
||||
try {
|
||||
const response = await fetch('https://restcountries.com/v3.1/all?fields=name');
|
||||
const data = await response.json();
|
||||
|
||||
const countries = data.map(country => ({
|
||||
text: country.name.common,
|
||||
val: country.cca2,
|
||||
})).sort((a, b) => a.text.localeCompare(b.text));
|
||||
|
||||
return countries;
|
||||
} catch (error) {
|
||||
console.error('Error fetching countries:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
0
rss/js/index.js
Normal file
0
rss/js/index.js
Normal file
@@ -1,82 +0,0 @@
|
||||
document.addEventListener('DOMContentLoaded', async (v) =>{
|
||||
await isAuth();
|
||||
let loginForm = document.getElementById('loginForm');
|
||||
|
||||
loginForm.addEventListener('submit', async (e) =>{
|
||||
e.preventDefault();
|
||||
await login();
|
||||
})
|
||||
})
|
||||
|
||||
// Async login function in vanilla JS
|
||||
async function login() {
|
||||
// Set login running state
|
||||
let loginRunning = true;
|
||||
let loginError = false;
|
||||
|
||||
// Get form data
|
||||
let username = document.getElementById('username').value;
|
||||
let password = document.getElementById('password').value;
|
||||
|
||||
let postFields = {
|
||||
userData: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
action: 'login'
|
||||
};
|
||||
|
||||
try {
|
||||
// Send request
|
||||
const response = await fetch('https://api.stellaamor.com/users.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include', // To handle cookies
|
||||
body: JSON.stringify(postFields)
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.status === 'fail') {
|
||||
// Display error if login fails
|
||||
loginError = true;
|
||||
document.getElementById('loginError').innerText = data.message;
|
||||
loginRunning = false;
|
||||
} else {
|
||||
// Successful login, redirect to /home
|
||||
loginRunning = false;
|
||||
setTimeout(() => {
|
||||
window.location.href = '/home';
|
||||
|
||||
// Reset form fields and errors after login
|
||||
document.getElementById('username').value = '';
|
||||
document.getElementById('password').value = '';
|
||||
document.getElementById('loginError').innerText = '';
|
||||
loginRunning = false;
|
||||
}, 1500);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Login error:', error);
|
||||
loginError = true;
|
||||
loginRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Async authentication check function in vanilla JS
|
||||
async function isAuth() {
|
||||
try {
|
||||
const response = await fetch('https://api.stellaamor.com/users.php?isAuth=true', {
|
||||
method: 'GET',
|
||||
credentials: 'include'
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
if (data.status === true) {
|
||||
window.location.href = '/home';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,76 @@
|
||||
// Global functions
|
||||
async function mainFetch(fdata){
|
||||
|
||||
async function _post(formObj, target, func){
|
||||
try{
|
||||
const form = await createFormData(formObj, target, func)
|
||||
const respJson = await fetch('/rss/php/handler.php', {
|
||||
method: 'POST',
|
||||
body: form
|
||||
});
|
||||
|
||||
if(respJson){
|
||||
return await(respJson.json());
|
||||
}else{
|
||||
return 'Error';
|
||||
}
|
||||
}catch(errno){
|
||||
console.log('Post failed');
|
||||
console.log(errno)
|
||||
}
|
||||
}
|
||||
|
||||
async function createFormData(data, target, func){
|
||||
const formData = new FormData();
|
||||
try{
|
||||
for(const key in data){
|
||||
if(data.hasOwnProperty(key)){
|
||||
formData.append(key, data[key]);
|
||||
}
|
||||
}
|
||||
formData.append('target', target);
|
||||
formData.append('function', func)
|
||||
}catch(errno){
|
||||
console.log('Incorrect use of object');
|
||||
return false;
|
||||
}
|
||||
return formData;
|
||||
}
|
||||
|
||||
function createEl(el, classArr = null, elText = null, dtSet = null){
|
||||
const element = document.createElement(el);
|
||||
if(elText){
|
||||
element.appendChild(document.createTextNode(elText));
|
||||
}
|
||||
|
||||
if(classArr && classArr.length){
|
||||
element.classList.add(...classArr);
|
||||
}
|
||||
|
||||
if(dtSet && Object.keys(dtSet).length){
|
||||
for(const [data, value] of Object.entries(dtSet)){
|
||||
element.dataset[data] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
|
||||
function getRandomID(){
|
||||
return Math.random().toString(36).replace('0.', '');
|
||||
}
|
||||
|
||||
async function generateAlert(type, text){
|
||||
const alert = document.createElement('div');
|
||||
alert.classList.add('alert');
|
||||
alert.classList.add(type);
|
||||
alert.appendChild(document.createTextNode(text));
|
||||
return alert;
|
||||
}
|
||||
|
||||
async function removeAlert(){
|
||||
const alerts = document.querySelectorAll('.alert');
|
||||
if(alerts && alerts.length){
|
||||
for(const alert of alerts){
|
||||
alert.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
const burger = document.querySelector('.burger');
|
||||
const navLinks = document.querySelector('.nav-links');
|
||||
|
||||
burger.addEventListener('click', () => {
|
||||
navLinks.classList.toggle('nav-active');
|
||||
burger.classList.toggle('toggle');
|
||||
});
|
||||
21
rss/js/properties.js
Normal file
21
rss/js/properties.js
Normal file
@@ -0,0 +1,21 @@
|
||||
document.addEventListener('DOMContentLoaded', async () =>{
|
||||
await getParams();
|
||||
})
|
||||
|
||||
async function getParams() {
|
||||
const queryString = window.location.search;
|
||||
const params = new URLSearchParams(queryString);
|
||||
const paramsObject = {};
|
||||
for (const key of params.keys()) {
|
||||
if (key.endsWith('[]')) {
|
||||
|
||||
const cleanKey = key.replace('[]', '');
|
||||
paramsObject[cleanKey] = params.getAll(key);
|
||||
} else {
|
||||
|
||||
paramsObject[key] = params.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
return paramsObject;
|
||||
}
|
||||
Reference in New Issue
Block a user