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

Sign up page name field validation is missing #844

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
77 changes: 42 additions & 35 deletions Html-files/scriptsignup.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,78 @@
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,
} from "https://www.gstatic.com/firebasejs/10.11.1/firebase-auth.js";

const firebaseConfig = {
apiKey: "AIzaSyDx_FcoL3XJryt6BInhOaDsMKiSmxzrYBI",
authDomain: "fir-7f3dd.firebaseapp.com",
projectId: "fir-7f3dd",
storageBucket: "fir-7f3dd.appspot.com",
messagingSenderId: "467011865433",
appId: "1:467011865433:web:e23be9d0cc3496bb961a48"
appId: "1:467011865433:web:e23be9d0cc3496bb961a48",
};

const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
auth.languageCode = 'en';
auth.languageCode = "en";

const provider = new GoogleAuthProvider();

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

document.getElementById("signup-form").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;
document
.getElementById("signup-form")
.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 nameError = document.getElementById("name-error");
const passwordError = document.getElementById("password-error");
const emailError = document.getElementById("email-error");
const nameError = document.getElementById("name-error");
const passwordError = document.getElementById("password-error");
const emailError = document.getElementById("email-error");

// Reset error messages
nameError.textContent = "";
passwordError.textContent = "";
emailError.textContent = "";
// Reset error messages
nameError.textContent = "";
passwordError.textContent = "";
emailError.textContent = "";

// Regex to prevent <, >, ", or / in the name and password
const spcharexp = /[<>"/]/;
// Regex to prevent <, >, ", or / in the name and password
const spcharexp = /[<>"/]/;

let valid = true; // A flag to track validation status
let valid = true; // A flag to track validation status

// Name validation
if (spcharexp.test(name)) {
nameError.textContent = "Name cannot contain <, >, \", or /";
// Name validation
if (spcharexp.test(name)) {
nameError.textContent = 'Name cannot contain <, >, ", or /. Only letters and spaces are allowed.';
valid = false;
}
}

// Password validation
if (spcharexp.test(password)) {
passwordError.textContent = "Password cannot contain <, >, \", or /";
// Password validation
if (spcharexp.test(password)) {
passwordError.textContent = 'Password cannot contain <, >, ", or /';
valid = false;
}
}

if (validateForm(name, email, password) && valid) {
// Simulate a successful registration (Replace with actual Firebase sign-up logic)
console.log("Form submitted with:", { name, email, password });
window.location.href = "../Html-files/signed.html";
}
});
if (validateForm(name, email, password) && valid) {
// Simulate a successful registration (Replace with actual Firebase sign-up logic)
console.log("Form submitted with:", { name, email, password });
window.location.href = "../Html-files/signed.html";
}
});

function validateForm(name, email, password) {
if (name === "" || email === "" || password === "") {
Expand All @@ -86,4 +93,4 @@ function validateForm(name, email, password) {
function validateEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}
}
Loading
Loading