eduGHoSt / script.js
dropkickJesus999's picture
Now the first two windows in the app aren't even showing up. Please fix this issue and
9a6c1f1 verified
// Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyDqVv0wQ3X9X9X9X9X9X9X9X9X9X9X9X9X",
authDomain: "edughost-12345.firebaseapp.com",
projectId: "edughost-12345",
storageBucket: "edughost-12345.appspot.com",
messagingSenderId: "9876543210",
appId: "1:9876543210:web:abcdef1234567890"
};
// Check if Firebase app already exists
let app;
if (!firebase.apps.length) {
app = firebase.initializeApp(firebaseConfig);
} else {
app = firebase.app();
}
const auth = firebase.auth();
const db = firebase.firestore();
// Make auth and db available globally
window.auth = auth;
window.db = db;
window.firebaseApp = app;
// Authentication state listener
auth.onAuthStateChanged((user) => {
if (user) {
console.log("User logged in:", user.email);
document.querySelector('custom-email-list').setAttribute('user-id', user.uid);
document.querySelector('custom-email-composer').setAttribute('user-id', user.uid);
} else {
console.log("User logged out");
}
});
// Function to create user account
async function createUserAccount(email, password) {
try {
const userCredential = await auth.createUserWithEmailAndPassword(email, password);
await db.collection('users').doc(userCredential.user.uid).set({
email: email,
createdAt: firebase.firestore.FieldValue.serverTimestamp()
});
return userCredential.user;
} catch (error) {
throw error;
}
}
// Global email sending function
window.sendEmail = async function(userId, emailData) {
try {
const emailRef = await db.collection('emails').add({
...emailData,
userId: userId,
read: false,
createdAt: firebase.firestore.FieldValue.serverTimestamp()
});
// Return the email ID for reference
return emailRef.id;
} catch (error) {
console.error("Error sending email:", error);
throw error;
}
}
// Function to fetch emails
async function fetchEmails(userId) {
try {
const snapshot = await db.collection('emails')
.where('userId', '==', userId)
.orderBy('createdAt', 'desc')
.get();
return snapshot.docs.map(doc => ({
id: doc.id,
...doc.data()
}));
} catch (error) {
console.error("Error fetching emails:", error);
return demoEmails; // Fallback to demo emails
}
}
const demoEmails = [
{
id: '1',
from: 'registrar@harvard.edu',
subject: 'Fall Semester Registration',
preview: 'Registration for Fall 2023 is now open. Click here to register...',
date: '10 min ago',
read: false,
body: `Dear Student,
Registration for Fall 2023 courses is now open. Please log in to the student portal to select your courses.
Important dates:
- Add/Drop Period: August 28 - September 8
- Midterm Exams: October 16-20
- Final Exams: December 11-15
Regards,
Harvard Registrar's Office`
},
{
id: '2',
from: 'financialaid@yale.edu',
subject: 'Financial Aid Package Update',
preview: 'Your financial aid package for 2023-2024 has been updated...',
date: '1 hour ago',
read: true,
body: `Dear Student,
We're writing to inform you that your financial aid package for the 2023-2024 academic year has been updated.
Please log in to your Student Aid Portal to review the changes. If you have any questions, please contact our office at (203) 432-0441.
Sincerely,
Yale Financial Aid Office`
},
{
id: '3',
from: 'housing@mit.edu',
subject: 'Dormitory Assignment',
preview: 'Your dormitory assignment for Fall 2023 is now available...',
date: '3 hours ago',
read: true,
body: `Hello,
Your dormitory assignment for Fall 2023 is now available. You've been assigned to Baker House, Room 412.
Move-in dates:
- Freshmen: August 28
- Returning Students: August 30
Please complete the housing questionnaire by August 15.
MIT Housing Office`
},
{
id: '4',
from: 'library@stanford.edu',
subject: 'Book Due Reminder',
preview: 'The book "Computer Science Principles" is due in 3 days...',
date: '1 day ago',
read: false,
body: `Library Notice:
The following book checked out to your account is due soon:
- "Computer Science Principles" by John Smith
Due Date: July 15, 2023
You may renew this item online if no one has placed a hold on it.
Stanford University Libraries`
},
{
id: '5',
from: 'careercenter@princeton.edu',
subject: 'Career Fair Invitation',
preview: 'Princeton Fall Career Fair - Register Now...',
date: '2 days ago',
read: true,
body: `Princeton Students,
You're invited to attend our Fall Career Fair on September 12, 2023 from 10am-3pm in Dillon Gym.
Over 150 employers will be recruiting for full-time positions and internships. Register now through Handshake.
Princeton Career Services`
}
];
// In a real app, this would be replaced with actual API calls
function fetchEmails() {
return new Promise(resolve => {
setTimeout(() => resolve(demoEmails), 500);
});
}
// Enhanced email generation with realistic patterns
function generateRandomEmail(domain) {
const patterns = [
() => `s${Math.floor(Math.random() * 1000000)}@${domain}`,
() => `student${Math.floor(Math.random() * 1000)}@${domain}`,
() => {
const first = ['j', 'm', 'a', 's', 'k', 'd'][Math.floor(Math.random() * 6)];
const last = ['smith', 'johnson', 'williams', 'brown', 'jones', 'miller'][Math.floor(Math.random() * 6)];
return `${first}.${last}${Math.floor(Math.random() * 10)}@${domain}`;
},
() => {
const year = new Date().getFullYear();
return `classof${year - Math.floor(Math.random() * 4)}@${domain}`;
}
];
return patterns[Math.floor(Math.random() * patterns.length)]();
}
// Function to validate email format
function isValidEmail(email) {
const re = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return re.test(email);
}
// Function to check if domain exists (simulated)
function checkDomainAvailability(domain) {
const availableDomains = [
'ccsf.edu', 'mcc.edu', 'bmcc.cuny.edu', 'aacc.edu',
'ucla.edu', 'umich.edu', 'utexas.edu', 'fsu.edu',
'harvard.edu', 'yale.edu', 'princeton.edu', 'columbia.edu',
'mit.edu', 'caltech.edu', 'stanford.edu', 'gatech.edu',
'lsu.edu'
];
return availableDomains.includes(domain);
}