Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix login without sign up. #719

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@
<li><a href="Html-Files/contact.html"><i class="bi bi-telephone"></i>Contact us</a></li>
<li><a href="rateus.html"><i class="bi bi-star"></i>Rate Us</a></li>

<li><a href="login.html"><i class="bi bi-box-arrow-right"></i> Sign in/Sign up</a></li>
<!-- <li><a href="login.html" id="login" ><i class="bi bi-box-arrow-right"></i> Sign in/Sign up</a></li> -->
<li><a href="login.html" id="login" ><i class="bi bi-box-arrow-right "></i> Sign in/Sign up</a></li>
<a href="./Html-Files/Doctor Experience.html"><button>Find a Doctor</button></a>
</ul>
<div class="hamburger">
Expand Down Expand Up @@ -621,6 +622,20 @@ <h1 class="about-us-heading">About Us</h1>
</section>

<script>

window.onload=()=>{
const username=sessionStorage.getItem('username');
if(username)
document.getElementById('login').innerHTML=username;
};

window.onload=()=>{
const username=sessionStorage.getItem('username');
if(username)
document.getElementById('login').innerHTML=username;
};


document.querySelectorAll('.about-us-community').forEach(function(element) {
element.addEventListener('mouseover', function() {
element.querySelector('img').src = './images/checkuphover.png';
Expand Down
40 changes: 20 additions & 20 deletions log/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ document.addEventListener("DOMContentLoaded", function() {
loginForm.scrollIntoView({ behavior: "smooth" });
});

registerForm.addEventListener("submit", (event) => {
event.preventDefault();
// Your registration logic goes here
// registerForm.addEventListener("submit", (event) => {
// event.preventDefault();
// // Your registration logic goes here

// Simulate registration success
document.getElementById("registerMessage").style.display = "block";
setTimeout(() => {
container.classList.remove("right-panel-active");
loginForm.scrollIntoView({ behavior: "smooth" });
}, 2000);
});
// // Simulate registration success
// document.getElementById("registerMessage").style.display = "block";
// setTimeout(() => {
// container.classList.remove("right-panel-active");
// loginForm.scrollIntoView({ behavior: "smooth" });
// }, 2000);
// });

loginForm.addEventListener("submit", (event) => {
event.preventDefault();
// Your login logic goes here
// loginForm.addEventListener("submit", (event) => {
// event.preventDefault();
// // Your login logic goes here

// Simulate login success
alert("Login successful!");
// Redirect to the homepage after login
setTimeout(() => {
window.location.href = "index.html"; // Change "index.html" to your desired URL
}, 1000); // Redirect after 1 second (1000 milliseconds)
});
// // Simulate login success
// alert("Login successful!");
// // Redirect to the homepage after login
// setTimeout(() => {
// window.location.href = "index.html"; // Change "index.html" to your desired URL
// }, 1000); // Redirect after 1 second (1000 milliseconds)
// });
});
14 changes: 8 additions & 6 deletions login.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<link rel="icon" type="image/x-icon" href="log/favicon.ico">
<link href="https://cdn.lineicons.com/4.0/lineicons.css" rel="stylesheet" />
<link rel="stylesheet" href="log/login.css">
<script src="scriptsignup.js" defer type="module"></script>
<!-- <script src="scriptsignup.js" defer type="module"></script> -->
<!-- <script src="scriptsignup.js" defer type="module"></script> -->
<script src="signupjs.js" defer type="module"></script>
<script src="signupjs1.js" defer type="module"></script>
<meta name="google-signin-client_id" content="646664380070-n07i34glgcc6sanb59p3m1k5k0cgn1v1.apps.googleusercontent.com">
Expand All @@ -20,9 +21,9 @@
<div class="form-container register-container">
<form action="#" id="registerForm">
<h1>RAPIDOC </h1>
<input type="text" placeholder="Name">
<input type="email" placeholder="Email">
<input type="password" placeholder="Password">
<input type="text" id="name" placeholder="Name" autocomplete="on">
<input type="email" id="email" placeholder="Email" autocomplete="on">
<input type="password" id="password" placeholder="Password" autocomplete="on">
<button type="submit">Register</button>
<span id="registerMessage" style="display: none;">Account created successfully</span>
<div class="social-container">
Expand All @@ -36,8 +37,8 @@ <h1>RAPIDOC </h1>
<div class="form-container login-container">
<form action="#" id="loginForm">
<h1>RAPIDOC</h1>
<input type="email" placeholder="Email">
<input type="password" placeholder="Password">
<input type="email" id="loginEmail" placeholder="Email" autocomplete="on">
<input type="password" id="loginPassword" placeholder="Password" autocomplete="on">
<div class="content">
<div class="checkbox">
<input type="checkbox" name="checkbox" id="checkbox">
Expand All @@ -48,6 +49,7 @@ <h1>RAPIDOC</h1>
</div>
</div>
<button type="submit">Login</button>
<span id="login-failed" style="display: none;">create account!</span>
<span>or use your account</span>
<div class="social-container">
<a href="www.facebook.com" class="social"><i class="lni lni-facebook-fill"></i></a>
Expand Down
85 changes: 68 additions & 17 deletions signupjs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.11.1/firebase-app.js";
import { getAuth, GoogleAuthProvider, signInWithPopup } from "https://www.gstatic.com/firebasejs/10.11.1/firebase-auth.js";
import {initializeApp} from "https://www.gstatic.com/firebasejs/10.11.1/firebase-app.js";
import {
getAuth,
GoogleAuthProvider,
signInWithPopup,
signInWithEmailAndPassword
} from "https://www.gstatic.com/firebasejs/10.11.1/firebase-auth.js";
import {
getDatabase,
ref,
orderByChild,
query,
get,
equalTo,
} from "https://www.gstatic.com/firebasejs/10.11.1/firebase-database.js";


const firebaseConfig = {
apiKey: "AIzaSyDx_FcoL3XJryt6BInhOaDsMKiSmxzrYBI",
Expand All @@ -11,38 +25,75 @@ const firebaseConfig = {
};

const app = initializeApp(firebaseConfig);
const database = getDatabase();
const dbref = ref(database, "data");
const auth = getAuth(app);

auth.languageCode = 'en';

const provider = new GoogleAuthProvider();

document.getElementById("google").addEventListener("click", function() {
//signin
document.getElementById("google").addEventListener("click", function () {
signInWithPopup(auth, provider)
.then((result) => {
const credential = GoogleAuthProvider.credentialFromResult(result);
const user = result.user;
console.log(user);
sessionStorage.setItem("username", user.displayName);
window.location.href = "./signedup.html";
}).catch((error) => {
})
.catch((error) => {
console.error("Error during Google sign-in:", error);
});
});

document.getElementById("signup-form").addEventListener("submit", function(event) {
document.getElementById("loginForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form from submitting the default way
const name = document.getElementById("name").value;
const email = document.getElementById("email").value;
const password = document.getElementById("password").value;
const email = document.getElementById("loginEmail").value;
const password = document.getElementById("loginPassword").value;

if (validateForm(name, email, password)) {
// Simulate a successful registration (Replace with actual Firebase sign-up logic)
console.log("Form submitted with:", { name, email, password });
window.location.href = "./signedup.html";
if (setTimeout(validateForm(email, password), 500)){
signInWithEmailAndPassword(auth,email,password)
.then((userCredential)=>{
console.log(userCredential);
sessionStorage.setItem("username", userCredential.user.displayName); // set username into session storage
window.location.href = "./index.html";
})
.catch((error)=>{
document.getElementById("login-failed").removeAttribute("style");
console.log(error);
})
}
});
// const email = document.getElementById("loginEmail").value;
// const password = document.getElementById("loginPassword").value;
// if (setTimeout(validateForm(email, password), 500)) {
// const usersRef = ref(database, "users/");
// const squery = query(usersRef, orderByChild("email"), equalTo(email));
// let name = null;
// get(squery).then((res) => {
// console.log(res);
// if (res.exists()) {
// const user = res.val();
// console.log(user);
// for (const userId in user) {
// const userd = user[userId];
// name = userd.username;
// }
//
//
// // localStorage.setItem('username',)
// } else {
// console.log("no results found");
// document.getElementById("login-failed").removeAttribute("style");
// }
})
// Simulate a successful registration (Replace with actual Firebase sign-up logic)
// console.log("Form submitted with:", {email, password});
//}
// });

function validateForm(name, email, password) {
if (name === "" || email === "" || password === "") {
function validateForm( email, password) {
if ( email === "" || password === "") {
alert("All fields are required!");
return false;
}
Expand All @@ -62,4 +113,4 @@ function validateEmail(email) {
return re.test(email);
}

/*646664380070-n07i34glgcc6sanb59p3m1k5k0cgn1v1.apps.googleusercontent.com*/
/*646664380070-n07i34glgcc6sanb59p3m1k5k0cgn1v1.apps.googleusercontent.com*/
29 changes: 26 additions & 3 deletions signupjs1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.11.1/firebase-app.js";
import { getAuth, GoogleAuthProvider, signInWithPopup } from "https://www.gstatic.com/firebasejs/10.11.1/firebase-auth.js";
import { getAuth, GoogleAuthProvider, signInWithPopup ,createUserWithEmailAndPassword,updateProfile} from "https://www.gstatic.com/firebasejs/10.11.1/firebase-auth.js";
import { getDatabase, ref, set } from "https://www.gstatic.com/firebasejs/10.11.1/firebase-database.js"

const firebaseConfig = {
apiKey: "AIzaSyDx_FcoL3XJryt6BInhOaDsMKiSmxzrYBI",
Expand All @@ -12,6 +13,8 @@ const firebaseConfig = {

const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const database=getDatabase();
const dbRef=ref(database,'data');
auth.languageCode = 'en';

const provider = new GoogleAuthProvider();
Expand All @@ -28,16 +31,36 @@ document.getElementById("google1").addEventListener("click", function() {
});
});

document.getElementById("signup-form").addEventListener("submit", function(event) {
document.getElementById("registerForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form from submitting the default way
const name = document.getElementById("name").value;
const email = document.getElementById("email").value;
const password = document.getElementById("password").value;

if (validateForm(name, email, password)) {
try {
createUserWithEmailAndPassword(auth,email,password)
.then((credential)=>
{
set(ref(database, 'users/' + credential.user.uid), { // set userdetails in realtime database
username: name,
email: email,
})
updateProfile(credential.user,{ // update profile for username
displayName:name,
})
window.location.href = "index.html";
});

} catch (error) {
console.log(error);
//alert("error occured!")
}

// Simulate a successful registration (Replace with actual Firebase sign-up logic)

console.log("Form submitted with:", { name, email, password });
window.location.href = "./signed.html";
//
}
});

Expand Down