Skip to content

Commit

Permalink
Merge pull request #277 from riyaaryan2004/main
Browse files Browse the repository at this point in the history
All backend issue resolved. All functions and handler corrected
  • Loading branch information
ankit071105 authored Oct 9, 2024
2 parents fb16caa + d49852e commit 1ad0e83
Show file tree
Hide file tree
Showing 17 changed files with 568 additions and 274 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ FIREBASE_MESSAGING_SENDER_ID=735303265369
FIREBASE_APP_ID=1:735303265369:web:07e050aae870d80987d548
FIREBASE_MEASUREMENT_ID=G-VNMJ68NQTD
FIREBASE_DATABASE_URL=https://ticket-booking-4e35f-default-rtdb.firebaseio.com


138 changes: 70 additions & 68 deletions client/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,27 @@ <h2 class="text-3xl sm:text-4xl text-gray-800 font-extrabold tracking-tight">
required
/>
<div class="relative flex items-center " >
<input
type="password"
name="password"
id="password"
placeholder="Password"
class="w-full mt-2 py-3 px-3 rounded-lg bg-white border border-gray-400 text-gray-800 font-semibold focus:border-orange-500 focus:outline-none"
required
/>
<button type="button" id="togglePassword" class="absolute right-3 top-5 text-black-500 hover:text-orange-700">
<!-- Eye SVG (visible by default) -->
<svg id="showIcon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-6 w-6 h-6">
<path d="M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z" />
<path fill-rule="evenodd" d="M1.323 11.447C2.811 6.976 7.028 3.75 12.001 3.75c4.97 0 9.185 3.223 10.675 7.69.12.362.12.752 0 1.113-1.487 4.471-5.705 7.697-10.677 7.697-4.97 0-9.186-3.223-10.675-7.69a1.762 1.762 0 0 1 0-1.113ZM17.25 12a5.25 5.25 0 1 1-10.5 0 5.25 5.25 0 0 1 10.5 0Z" clip-rule="evenodd" />
</svg>
<!-- Eye Slash SVG (hidden by default) -->
<svg id="hideIcon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-6 w-6 h-6 hidden">
<path d="M3.53 2.47a.75.75 0 0 0-1.06 1.06l18 18a.75.75 0 1 0 1.06-1.06l-18-18ZM22.676 12.553a11.249 11.249 0 0 1-2.631 4.31l-3.099-3.099a5.25 5.25 0 0 0-6.71-6.71L7.759 4.577a11.217 11.217 0 0 1 4.242-.827c4.97 0 9.185 3.223 10.675 7.69.12.362.12.752 0 1.113Z" />
<path d="M15.75 12c0 .18-.013.357-.037.53l-4.244-4.243A3.75 3.75 0 0 1 15.75 12ZM12.53 15.713l-4.243-4.244a3.75 3.75 0 0 0 4.244 4.243Z" />
<path d="M6.75 12c0-.619.107-1.213.304-1.764l-3.1-3.1a11.25 11.25 0 0 0-2.63 4.31c-.12.362-.12.752 0 1.114 1.489 4.467 5.704 7.69 10.675 7.69 1.5 0 2.933-.294 4.242-.827l-2.477-2.477A5.25 5.25 0 0 1 6.75 12Z" />
</svg>
</button>

<input
type="password"
name="password"
id="password"
placeholder="Password"
class="w-full mt-2 py-3 px-3 rounded-lg bg-white border border-gray-400 text-gray-800 font-semibold focus:border-orange-500 focus:outline-none"
required
/>
<button type="button" id="togglePassword" class="absolute right-3 top-5 text-black-500 hover:text-orange-700">
<!-- Eye SVG (visible by default) -->
<svg id="showIcon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-6 w-6 h-6">
<path d="M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z" />
<path fill-rule="evenodd" d="M1.323 11.447C2.811 6.976 7.028 3.75 12.001 3.75c4.97 0 9.185 3.223 10.675 7.69.12.362.12.752 0 1.113-1.487 4.471-5.705 7.697-10.677 7.697-4.97 0-9.186-3.223-10.675-7.69a1.762 1.762 0 0 1 0-1.113ZM17.25 12a5.25 5.25 0 1 1-10.5 0 5.25 5.25 0 0 1 10.5 0Z" clip-rule="evenodd" />
</svg>
<!-- Eye Slash SVG (hidden by default) -->
<svg id="hideIcon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-6 w-6 h-6 hidden">
<path d="M3.53 2.47a.75.75 0 0 0-1.06 1.06l18 18a.75.75 0 1 0 1.06-1.06l-18-18ZM22.676 12.553a11.249 11.249 0 0 1-2.631 4.31l-3.099-3.099a5.25 5.25 0 0 0-6.71-6.71L7.759 4.577a11.217 11.217 0 0 1 4.242-.827c4.97 0 9.185 3.223 10.675 7.69.12.362.12.752 0 1.113Z" />
<path d="M15.75 12c0 .18-.013.357-.037.53l-4.244-4.243A3.75 3.75 0 0 1 15.75 12ZM12.53 15.713l-4.243-4.244a3.75 3.75 0 0 0 4.244 4.243Z" />
<path d="M6.75 12c0-.619.107-1.213.304-1.764l-3.1-3.1a11.25 11.25 0 0 0-2.63 4.31c-.12.362-.12.752 0 1.114 1.489 4.467 5.704 7.69 10.675 7.69 1.5 0 2.933-.294 4.242-.827l-2.477-2.477A5.25 5.25 0 0 1 6.75 12Z" />
</svg>
</button>

</div>
<p id="errorMessage" class="text-red-500 mt-2"></p>
Expand All @@ -85,61 +84,64 @@ <h2 class="text-3xl sm:text-4xl text-gray-800 font-extrabold tracking-tight">
</div>

<script>
document.getElementById('loginForm').addEventListener('submit', async function(event) {
event.preventDefault(); // Prevent the form from submitting the default way

const email = document.getElementById('email').value;
const password = document.getElementById('password').value;

try {
const response = await fetch('http://localhost:7865/api/v1/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: email,
password: password
})
});

const data = await response.json();

if (response.ok) {
alert('Login successful!');
localStorage.setItem('authToken', data.token);
window.location.href = '/dashboard.html'; // Update this with your actual dashboard path
} else {
document.getElementById('errorMessage').textContent = data.message || 'Login failed!';
}
} catch (error) {
document.getElementById('errorMessage').textContent = 'An error occurred during login!';
}
});


document.getElementById('googleSignin').addEventListener('click', function(e) {
// TODO: Handle Google Sign-In logic here
e.preventDefault();
signInWithGoogle(); // Use the same function as in register.html
});

document.getElementById('togglePassword').addEventListener('click', function() {
const passwordInput = document.getElementById('password');
const showIcon = document.getElementById('showIcon');
const hideIcon = document.getElementById('hideIcon');

// Toggle password field type between password and text
const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
passwordInput.setAttribute('type', type);

// Toggle icons
showIcon.classList.toggle('hidden');
hideIcon.classList.toggle('hidden');
});
</script>

<script src="signup.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.18.0/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.18.0/firebase-auth-compat.js"></script>
<script src="../firebase.js"></script>
<script>

document.getElementById('loginForm').addEventListener('submit', async function(event) {
console.log('hellooooooooooo');
event.preventDefault(); // Prevent the form from submitting the default way
console.log('Form submitted!');

const email = document.getElementById('email').value;
const password = document.getElementById('password').value;

if (!email || !password) {
document.getElementById('errorMessage').textContent = 'Email and password are required!';
return;
}

try {
console.log('Sending login request...');
const response = await fetch('http://localhost:7865/api/v1/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: email,
password: password
})
});

const data = await response.json();
console.log('Response:', data);

if (response.ok) {
alert('Login successful!');
localStorage.setItem('authToken', data.token);
console.log('Redirecting to dashboard...');
window.location.href = '../sell.html'; // Update this with your actual dashboard path
} else {
console.log('Login failed:', data.message);
document.getElementById('errorMessage').textContent = data.message || 'Login failed!';
}
} catch (error) {
console.error('Login error:', error);
document.getElementById('errorMessage').textContent = 'An error occurred during login!';
}
});

</script>
</body>
</html>
90 changes: 34 additions & 56 deletions client/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,70 +101,48 @@ <h2 class="text-3xl sm:text-4xl text-gray-800 font-extrabold tracking-tight">Sig
</div>
</div>

<script>
document.getElementById('closeButton').addEventListener('click', function() {
window.location.href = '..//index.html'; // Redirect to home page
});
<script>
document.getElementById('signupForm').addEventListener('submit', async function(event) {
event.preventDefault();

document.getElementById('signupForm').addEventListener('submit', async function(event) {
event.preventDefault();
const email = document.getElementById('email').value;
const username = document.getElementById('username').value;
const mobile = document.getElementById('mobile').value;
const password = document.getElementById('password').value;

const email = document.getElementById('email').value;
const username = document.getElementById('username').value;
const mobile = document.getElementById('mobile').value;
const password = document.getElementById('password').value;
try {
const response = await fetch('http://localhost:7865/api/v1/auth/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: email,
name: username,
mobileNum: mobile,
password: password
})
});

try {
const response = await fetch('http://localhost:7865/api/v1/auth/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: email,
name: username,
mobileNum: mobile,
password: password
})
});
const data = await response.json();
console.log(data); // Log the API response

const data = await response.json();
console.log(data); // Log the API response

if (response.ok) {
alert('Registration successful!');
window.location.href = "/client/login.html"; // Use this if needed
} else {
document.getElementById('errorMessage').textContent = data.message || 'Registration failed!';
}
} catch (error) {
console.error('Error:', error); // Log any network or server error
document.getElementById('errorMessage').textContent = 'An error occurred during registration!';
}
});



document.getElementById('togglePassword').addEventListener('click', function() {
const passwordInput = document.getElementById('password');
const showIcon = document.getElementById('showIcon');
const hideIcon = document.getElementById('hideIcon');
if (passwordInput.type === 'password') {
passwordInput.type = 'text';
showIcon.classList.add('hidden');
hideIcon.classList.remove('hidden');
if (response.ok) {
alert('Registration successful!');
window.location.href = "/client/login.html"; // Use this if needed
} else {
passwordInput.type = 'password';
showIcon.classList.remove('hidden');
hideIcon.classList.add('hidden');
document.getElementById('errorMessage').textContent = data.message || 'Registration failed!';
}
});
</script>


} catch (error) {
console.error('Error:', error); // Log any network or server error
document.getElementById('errorMessage').textContent = 'An error occurred during registration!';
}
});
</script>
<script src="signup.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.18.0/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.18.0/firebase-auth-compat.js"></script>
<script src="../firebase.js"></script>

</body>
</html>
100 changes: 100 additions & 0 deletions client/signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
document.getElementById('togglePassword').addEventListener('click', function() {
const passwordInput = document.getElementById('password');
const showIcon = document.getElementById('showIcon');
const hideIcon = document.getElementById('hideIcon');
if (passwordInput.type === 'password') {
passwordInput.type = 'text';
showIcon.classList.add('hidden');
hideIcon.classList.remove('hidden');
} else {
passwordInput.type = 'password';
showIcon.classList.remove('hidden');
hideIcon.classList.add('hidden');
}
});


document.getElementById('closeButton').addEventListener('submit', async function(event) {
window.location.href = '../index.html'; // Redirect to home page
});


document.getElementById('signupForm').addEventListener('submit', async function(event) {
event.preventDefault();

const email = document.getElementById('email').value;
const username = document.getElementById('username').value;
const mobile = document.getElementById('mobile').value;
const password = document.getElementById('password').value;

try {
const response = await fetch('http://localhost:7865/api/v1/auth/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: email,
name: username,
mobileNum: mobile,
password: password
})
});

const data = await response.json();
console.log(data); // Log the API response

if (response.ok) {
alert('Registration successful!');
window.location.href = "/client/login.html"; // Use this if needed
} else {
document.getElementById('errorMessage').textContent = data.message || 'Registration failed!';
}
} catch (error) {
console.error('Error:', error); // Log any network or server error
document.getElementById('errorMessage').textContent = 'An error occurred during registration!';
}
});

document.getElementById('loginForm').addEventListener('submit', async function(event) {
event.preventDefault(); // Prevent the form from submitting the default way
console.log('Form submitted!');

const email = document.getElementById('email').value;
const password = document.getElementById('password').value;

if (!email || !password) {
document.getElementById('errorMessage').textContent = 'Email and password are required!';
return;
}

try {
console.log('Sending login request...');
const response = await fetch('http://localhost:7865/api/v1/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: email,
password: password
})
});

const data = await response.json();
console.log('Response:', data);

if (response.ok) {
alert('Login successful!');
localStorage.setItem('authToken', data.token);
console.log('Redirecting to dashboard...');
window.location.href = '../sell.html'; // Update this with your actual dashboard path
} else {
console.log('Login failed:', data.message);
document.getElementById('errorMessage').textContent = data.message || 'Login failed!';
}
} catch (error) {
console.error('Login error:', error);
document.getElementById('errorMessage').textContent = 'An error occurred during login!';
}
});
Binary file added images/user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@

}

.toggle-arrow {

}


.toggle-arrow {
position: fixed;
top: 50%;
Expand Down Expand Up @@ -828,11 +825,10 @@

<ul class="nav-links" style="align-items: center;">
<li><a href="about.html"><i class="fas fa-info-circle"></i> About Us</a></li>
<li><a href="buy.html"><i class="fas fa-shopping-cart"></i> Buy</a></li>
<li><a href="buy.html"><i class="fas fa-shopping-cart"></i> Buy</a></li>
<li><a href="sell.html"><i class="fas fa-tag"></i> Sell</a></li>
<li><a href="#sxs"><i class="fas fa-envelope"></i> Contact</a></li>
<li><a href="/client/register.html" class="login-btn"><i class="fas fa-user"></i>Signup</a></li>

<li><a href="/client/register.html" class="login-btn"><i class="fas fa-user"></i></a></li>
<button id="darkModeToggle" style="width: 40px; height: 40px;">🌙</button>

</ul>
Expand Down
Loading

0 comments on commit 1ad0e83

Please sign in to comment.