This commit is contained in:
Flatlogic Bot 2025-09-24 06:32:27 +00:00
parent 19ef21748b
commit fa86852137
3 changed files with 168 additions and 4 deletions

105
assets/js/auth.js Normal file
View File

@ -0,0 +1,105 @@
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.1/firebase-app.js";
import {
getAuth,
createUserWithEmailAndPassword,
signInWithEmailAndPassword,
GoogleAuthProvider,
signInWithPopup,
onAuthStateChanged
} from "https://www.gstatic.com/firebasejs/9.6.1/firebase-auth.js";
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyAuabZynwAn8r91_toMzdN2_vCVOwLsAf8",
authDomain: "ai-resume-builder-90135.firebaseapp.com",
projectId: "ai-resume-builder-90135",
storageBucket: "ai-resume-builder-90135.firebasestorage.app",
messagingSenderId: "465451014283",
appId: "1:465451014283:web:355ddebe12bc8a2dfedc8e",
measurementId: "G-4B91V0ZY58"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const provider = new GoogleAuthProvider();
// DOM Elements
const loginForm = document.getElementById('loginForm');
const signupForm = document.getElementById('signupForm');
const googleLoginBtn = document.getElementById('googleLoginBtn');
const googleSignupBtn = document.getElementById('googleSignupBtn');
const errorContainer = document.getElementById('errorContainer');
// Function to display errors
const showError = (message) => {
errorContainer.textContent = message;
errorContainer.style.display = 'block';
};
// Redirect if user is already logged in
onAuthStateChanged(auth, (user) => {
if (user) {
window.location.href = 'home.php';
}
});
// Email/Password Sign Up
if (signupForm) {
signupForm.addEventListener('submit', (e) => {
e.preventDefault();
const email = signupForm.querySelector('#signupEmail').value;
const password = signupForm.querySelector('#signupPassword').value;
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
window.location.href = 'home.php';
})
.catch((error) => {
showError(error.message);
});
});
}
// Email/Password Login
if (loginForm) {
loginForm.addEventListener('submit', (e) => {
e.preventDefault();
const email = loginForm.querySelector('#loginEmail').value;
const password = loginForm.querySelector('#loginPassword').value;
signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
window.location.href = 'home.php';
})
.catch((error) => {
showError(error.message);
});
});
}
// Google Sign-In
const handleGoogleSignIn = (e) => {
e.preventDefault();
signInWithPopup(auth, provider)
.then((result) => {
// This gives you a Google Access Token. You can use it to access the Google API.
const credential = GoogleAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
// The signed-in user info.
const user = result.user;
window.location.href = 'home.php';
}).catch((error) => {
// Handle Errors here.
showError(error.message);
});
};
if (googleLoginBtn) {
googleLoginBtn.addEventListener('click', handleGoogleSignIn);
}
if (googleSignupBtn) {
googleSignupBtn.addEventListener('click', handleGoogleSignIn);
}

55
home.php Normal file
View File

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home - AI Resume Builder</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<div class="container text-center vh-100 d-flex flex-column justify-content-center">
<h1 class="text-light">Welcome to the AI Resume Builder</h1>
<p class="text-light">You are logged in. Template selection coming soon!</p>
<button id="signOutBtn" class="btn btn-danger mt-3 mx-auto" style="max-width: 200px;">Sign Out</button>
</div>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.1/firebase-app.js";
import { getAuth, signOut, onAuthStateChanged } from "https://www.gstatic.com/firebasejs/9.6.1/firebase-auth.js";
const firebaseConfig = {
apiKey: "AIzaSyAuabZynwAn8r91_toMzdN2_vCVOwLsAf8",
authDomain: "ai-resume-builder-90135.firebaseapp.com",
projectId: "ai-resume-builder-90135",
storageBucket: "ai-resume-builder-90135.firebasestorage.app",
messagingSenderId: "465451014283",
appId: "1:465451014283:web:355ddebe12bc8a2dfedc8e",
measurementId: "G-4B91V0ZY58"
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
// Redirect to login if not authenticated
onAuthStateChanged(auth, (user) => {
if (!user) {
window.location.href = 'index.php';
}
});
// Sign out functionality
const signOutBtn = document.getElementById('signOutBtn');
signOutBtn.addEventListener('click', () => {
signOut(auth).then(() => {
// Sign-out successful.
window.location.href = 'index.php';
}).catch((error) => {
// An error happened.
console.error('Sign out error:', error);
alert('Failed to sign out. Please try again.');
});
});
</script>
</body>
</html>

View File

@ -39,11 +39,14 @@
</li> </li>
</ul> </ul>
<!-- Error Messages -->
<div id="errorContainer" class="alert alert-danger mt-3" style="display: none;"></div>
<!-- Tab Content --> <!-- Tab Content -->
<div class="tab-content pt-4" id="authTabsContent"> <div class="tab-content pt-4" id="authTabsContent">
<!-- Login Pane --> <!-- Login Pane -->
<div class="tab-pane fade show active" id="login" role="tabpanel" aria-labelledby="login-tab"> <div class="tab-pane fade show active" id="login" role="tabpanel" aria-labelledby="login-tab">
<form action="#" method="POST"> <form id="loginForm">
<div class="mb-3"> <div class="mb-3">
<label for="loginEmail" class="form-label visually-hidden">Email address</label> <label for="loginEmail" class="form-label visually-hidden">Email address</label>
<input type="email" class="form-control" id="loginEmail" placeholder="Email address" required> <input type="email" class="form-control" id="loginEmail" placeholder="Email address" required>
@ -55,7 +58,7 @@
<button type="submit" class="btn btn-primary mt-3">Login</button> <button type="submit" class="btn btn-primary mt-3">Login</button>
</form> </form>
<div class="divider">or</div> <div class="divider">or</div>
<button class="btn btn-google"> <button class="btn btn-google" id="googleLoginBtn">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" class="bi bi-google" viewBox="0 0 16 16"> <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" class="bi bi-google" viewBox="0 0 16 16">
<path d="M15.545 6.558a9.42 9.42 0 0 1 .139 1.626c0 2.434-.87 4.492-2.384 5.885h.002C11.978 15.292 10.158 16 8 16A8 8 0 1 1 8 0a7.689 7.689 0 0 1 5.352 2.082l-2.284 2.284A4.347 4.347 0 0 0 8 3.166c-2.087 0-3.86 1.408-4.492 3.304a4.792 4.792 0 0 0 0 3.063h.003c.635 1.893 2.405 3.301 4.492 3.301 1.078 0 2.004-.276 2.722-.764h-.003a3.702 3.702 0 0 0 1.599-2.431H8v-3.08h7.545z"/> <path d="M15.545 6.558a9.42 9.42 0 0 1 .139 1.626c0 2.434-.87 4.492-2.384 5.885h.002C11.978 15.292 10.158 16 8 16A8 8 0 1 1 8 0a7.689 7.689 0 0 1 5.352 2.082l-2.284 2.284A4.347 4.347 0 0 0 8 3.166c-2.087 0-3.86 1.408-4.492 3.304a4.792 4.792 0 0 0 0 3.063h.003c.635 1.893 2.405 3.301 4.492 3.301 1.078 0 2.004-.276 2.722-.764h-.003a3.702 3.702 0 0 0 1.599-2.431H8v-3.08h7.545z"/>
</svg> </svg>
@ -65,7 +68,7 @@
<!-- Sign Up Pane --> <!-- Sign Up Pane -->
<div class="tab-pane fade" id="signup" role="tabpanel" aria-labelledby="signup-tab"> <div class="tab-pane fade" id="signup" role="tabpanel" aria-labelledby="signup-tab">
<form action="#" method="POST"> <form id="signupForm">
<div class="mb-3"> <div class="mb-3">
<label for="signupName" class="form-label visually-hidden">Full Name</label> <label for="signupName" class="form-label visually-hidden">Full Name</label>
<input type="text" class="form-control" id="signupName" placeholder="Full Name" required> <input type="text" class="form-control" id="signupName" placeholder="Full Name" required>
@ -81,7 +84,7 @@
<button type="submit" class="btn btn-primary mt-3">Create Account</button> <button type="submit" class="btn btn-primary mt-3">Create Account</button>
</form> </form>
<div class="divider">or</div> <div class="divider">or</div>
<button class="btn btn-google"> <button class="btn btn-google" id="googleSignupBtn">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" class="bi bi-google" viewBox="0 0 16 16"> <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" class="bi bi-google" viewBox="0 0 16 16">
<path d="M15.545 6.558a9.42 9.42 0 0 1 .139 1.626c0 2.434-.87 4.492-2.384 5.885h.002C11.978 15.292 10.158 16 8 16A8 8 0 1 1 8 0a7.689 7.689 0 0 1 5.352 2.082l-2.284 2.284A4.347 4.347 0 0 0 8 3.166c-2.087 0-3.86 1.408-4.492 3.304a4.792 4.792 0 0 0 0 3.063h.003c.635 1.893 2.405 3.301 4.492 3.301 1.078 0 2.004-.276 2.722-.764h-.003a3.702 3.702 0 0 0 1.599-2.431H8v-3.08h7.545z"/> <path d="M15.545 6.558a9.42 9.42 0 0 1 .139 1.626c0 2.434-.87 4.492-2.384 5.885h.002C11.978 15.292 10.158 16 8 16A8 8 0 1 1 8 0a7.689 7.689 0 0 1 5.352 2.082l-2.284 2.284A4.347 4.347 0 0 0 8 3.166c-2.087 0-3.86 1.408-4.492 3.304a4.792 4.792 0 0 0 0 3.063h.003c.635 1.893 2.405 3.301 4.492 3.301 1.078 0 2.004-.276 2.722-.764h-.003a3.702 3.702 0 0 0 1.599-2.431H8v-3.08h7.545z"/>
</svg> </svg>
@ -93,5 +96,6 @@
</div> </div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script type="module" src="assets/js/auth.js?v=<?php echo time(); ?>"></script>
</body> </body>
</html> </html>