i fucking did it
This commit is contained in:
@@ -0,0 +1 @@
|
||||
# userlogins-for-fun-miles
|
||||
@@ -0,0 +1,233 @@
|
||||
// Initialize Userbase
|
||||
userbase.init({ appId: '7cd8e25b-723d-4af7-8bdf-ef558bd0dfcc' }); // Replace with your Userbase app ID
|
||||
|
||||
let currentUser; // Variable to hold the current user object
|
||||
let isDatabaseOpen = false; // Flag to check if the database is open
|
||||
|
||||
document.getElementById('signup-form').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const username = document.getElementById('signup-username').value; // Email as username
|
||||
const password = document.getElementById('signup-password').value;
|
||||
|
||||
try {
|
||||
const user = await userbase.signUp({ username: username, password });
|
||||
alert('Signup successful!');
|
||||
} catch (error) {
|
||||
console.error('Signup error:', error);
|
||||
alert('Signup failed: ' + error.message);
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('login-form').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const username = document.getElementById('login-username').value; // Email as username
|
||||
const password = document.getElementById('login-password').value;
|
||||
|
||||
try {
|
||||
currentUser = await userbase.signIn({
|
||||
username: username,
|
||||
password: password,
|
||||
rememberMe: 'none' // Do not remember the session
|
||||
});
|
||||
alert('Login successful!');
|
||||
document.getElementById('form-container').style.display = 'none';
|
||||
document.getElementById('note-management').style.display = 'block';
|
||||
|
||||
// Open the Userbase database
|
||||
await openUserbaseDatabase();
|
||||
} catch (error) {
|
||||
console.error('Login error:', error);
|
||||
alert('Login failed: ' + error.message);
|
||||
}
|
||||
});
|
||||
|
||||
// Function to check if user is logged in
|
||||
async function checkUserLoggedIn() {
|
||||
try {
|
||||
currentUser = await userbase.getUser();
|
||||
if (currentUser) {
|
||||
document.getElementById('form-container').style.display = 'none';
|
||||
document.getElementById('note-management').style.display = 'block';
|
||||
|
||||
// Open the Userbase database
|
||||
await openUserbaseDatabase();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking user login status:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to open Userbase database
|
||||
async function openUserbaseDatabase() {
|
||||
try {
|
||||
await userbase.openDatabase({
|
||||
databaseName: 'notes-database',
|
||||
changeHandler: function (items) {
|
||||
const notesList = document.getElementById('notes-list');
|
||||
notesList.innerHTML = ''; // Clear existing notes
|
||||
items.forEach(item => {
|
||||
const noteItem = document.createElement('li');
|
||||
noteItem.className = 'note-item';
|
||||
noteItem.textContent = item.item.text;
|
||||
|
||||
// Create delete button
|
||||
const deleteButton = document.createElement('button');
|
||||
deleteButton.textContent = 'Delete';
|
||||
deleteButton.style.marginLeft = '10px';
|
||||
deleteButton.onclick = () => deleteNote(item.itemId); // Bind delete function
|
||||
|
||||
noteItem.appendChild(deleteButton);
|
||||
notesList.appendChild(noteItem);
|
||||
});
|
||||
}
|
||||
});
|
||||
isDatabaseOpen = true;
|
||||
console.log('Database opened successfully.');
|
||||
} catch (error) {
|
||||
isDatabaseOpen = false;
|
||||
console.error('Error opening database:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to save note to Userbase
|
||||
async function saveNote() {
|
||||
if (!isDatabaseOpen) {
|
||||
alert('Database is not open. Please try again later.');
|
||||
return;
|
||||
}
|
||||
|
||||
const noteText = document.getElementById('note-input').value;
|
||||
if (!noteText) {
|
||||
alert('Please enter a note to save.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await userbase.insertItem({
|
||||
databaseName: 'notes-database',
|
||||
item: { text: noteText }
|
||||
});
|
||||
alert('Note saved successfully!');
|
||||
document.getElementById('note-input').value = ''; // Clear input
|
||||
} catch (error) {
|
||||
console.error('Error saving note:', error);
|
||||
alert('Failed to save note: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to delete a note from Userbase
|
||||
async function deleteNote(itemId) {
|
||||
if (!isDatabaseOpen) {
|
||||
alert('Database is not open. Please try again later.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await userbase.deleteItem({
|
||||
databaseName: 'notes-database',
|
||||
itemId: itemId
|
||||
});
|
||||
alert('Note deleted successfully!');
|
||||
} catch (error) {
|
||||
console.error('Error deleting note:', error);
|
||||
alert('Failed to delete note: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to log out the user
|
||||
async function logout() {
|
||||
try {
|
||||
await userbase.signOut(); // Sign out from Userbase
|
||||
currentUser = null; // Clear current user
|
||||
isDatabaseOpen = false; // Reset database open flag
|
||||
document.getElementById('form-container').style.display = 'block'; // Show login/signup forms
|
||||
document.getElementById('note-management').style.display = 'none'; // Hide note management
|
||||
alert('Logged out successfully!');
|
||||
} catch (error) {
|
||||
console.error('Logout error:', error);
|
||||
alert('Logout failed: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to save cookies to the cloud
|
||||
document.getElementById('save-cookies-cloud').addEventListener('click', async () => {
|
||||
if (!isDatabaseOpen) {
|
||||
alert('Database is not open. Please try again later.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Clear existing items in the database
|
||||
await userbase.openDatabase({
|
||||
databaseName: 'notes-database',
|
||||
changeHandler: async function (items) {
|
||||
for (const item of items) {
|
||||
await userbase.deleteItem({
|
||||
databaseName: 'notes-database',
|
||||
itemId: item.itemId
|
||||
});
|
||||
}
|
||||
|
||||
// Save cookies to the cloud
|
||||
const cookies = document.cookie.split('; ').map(cookie => decodeURIComponent(cookie)).join('\n');
|
||||
const chunkSize = 9000; // Set chunk size to be less than 10 KB
|
||||
for (let i = 0; i < cookies.length; i += chunkSize) {
|
||||
const chunk = cookies.substring(i, i + chunkSize);
|
||||
await userbase.insertItem({
|
||||
databaseName: 'notes-database',
|
||||
item: { text: chunk }
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error saving cookies to cloud:', error);
|
||||
alert('Failed to save cookies to cloud: ' + error.message);
|
||||
}
|
||||
});
|
||||
|
||||
// Function to load cookies from the cloud
|
||||
document.getElementById('load-cookies-cloud').addEventListener('click', async () => {
|
||||
if (!isDatabaseOpen) {
|
||||
alert('Database is not open. Please try again later.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await userbase.openDatabase({
|
||||
databaseName: 'notes-database',
|
||||
changeHandler: function (items) {
|
||||
const cookies = items.map(item => item.item.text).join('\n');
|
||||
document.cookie = cookies.split('\n').map(cookie => encodeURIComponent(cookie.trim())).join('; ');
|
||||
alert('Cookies loaded from cloud successfully!');
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error loading cookies from cloud:', error);
|
||||
alert('Failed to load cookies from cloud: ' + error.message);
|
||||
}
|
||||
});
|
||||
|
||||
// Function to display cookies
|
||||
function displayCookies() {
|
||||
const cookies = document.cookie.split('; ').map(cookie => decodeURIComponent(cookie)).join('\n');
|
||||
document.getElementById('cookies-display').textContent = cookies;
|
||||
document.getElementById('cookies-input').value = cookies;
|
||||
}
|
||||
|
||||
// Function to save cookies from the textarea
|
||||
document.getElementById('save-cookies').addEventListener('click', () => {
|
||||
const cookies = document.getElementById('cookies-input').value.split('\n');
|
||||
cookies.forEach(cookie => {
|
||||
document.cookie = encodeURIComponent(cookie.trim());
|
||||
});
|
||||
alert('Cookies updated!');
|
||||
displayCookies();
|
||||
});
|
||||
|
||||
// Event listeners for buttons
|
||||
document.getElementById('save-note').addEventListener('click', saveNote);
|
||||
document.getElementById('logout-button').addEventListener('click', logout);
|
||||
|
||||
// Check if user is logged in when the page loads
|
||||
window.onload = checkUserLoggedIn;
|
||||
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Notes Management</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
<script type="text/javascript" src="https://sdk.userbase.com/2/userbase.js"></script>
|
||||
</head>
|
||||
<body onload="checkUserLoggedIn()">
|
||||
<div class="container">
|
||||
<h1>Notes Management</h1>
|
||||
<div id="form-container">
|
||||
<form id="signup-form">
|
||||
<h2>Sign Up</h2>
|
||||
<input type="text" id="signup-username" placeholder="Username (Email)" required>
|
||||
<input type="password" id="signup-password" placeholder="Password" required>
|
||||
<button type="submit">Sign Up</button>
|
||||
</form>
|
||||
<form id="login-form">
|
||||
<h2>Login</h2>
|
||||
<input type="text" id="login-username" placeholder="Username (Email)" required>
|
||||
<input type="password" id="login-password" placeholder="Password" required>
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
<div id="note-management" style="display: none;">
|
||||
<h2>Note Management</h2>
|
||||
<input type="text" id="note-input" placeholder="Write your note here..." />
|
||||
<button id="logout-button">Logout</button>
|
||||
<ul id="notes-list" style="margin-top: 20px;"></ul>
|
||||
<div id="cookies-container">
|
||||
<h2>Cookies</h2>
|
||||
<p id="cookies-display"></p>
|
||||
<button id="save-cookies-cloud">Save Cookies to Cloud</button>
|
||||
<button id="load-cookies-cloud">Load Cookies from Cloud</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,72 @@
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f4f4f4;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: auto;
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
h1, h2 {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
form {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
input[type="password"] {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 10px 15px;
|
||||
background-color: #5cb85c;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #4cae4c;
|
||||
}
|
||||
|
||||
#notes-list {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.note-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: #e9ecef;
|
||||
padding: 10px;
|
||||
margin: 5px 0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.note-item button {
|
||||
background-color: #d9534f;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.note-item button:hover {
|
||||
background-color: #c9302c;
|
||||
}
|
||||
+1
-1
@@ -87,7 +87,7 @@ const mainContentData = [
|
||||
{
|
||||
name: "save to cloud",
|
||||
image: "/WebGames-master/WebGames-master/assets/save-to-cloud-2.png",
|
||||
link: "/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/userlogins-for-fun-miles-main/index.html",
|
||||
link: "/WebGames-master/WebGames-master/userlogins-for-fun-miles-main/index.html",
|
||||
},
|
||||
];
|
||||
mainContentData.forEach(item => {
|
||||
|
||||
Reference in New Issue
Block a user