Skip to content

Commit

Permalink
Merge pull request #54 from Premkolte/main
Browse files Browse the repository at this point in the history
Improve the UI of the Login and Register Page
  • Loading branch information
dhairyagothi authored Oct 4, 2024
2 parents d6430c2 + 8926946 commit 2ddce2c
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 158 deletions.
4 changes: 3 additions & 1 deletion frontend/src/Pages/Herosection.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@tailwind utilities;

body {

padding: 0;
margin: 0;
background-image: url('../assets/mixbg.png');
Expand All @@ -11,5 +12,6 @@ body {
height: 100vh;
width: 100vw;
overflow-x : hidden;
position: relative;
position: relative;

}
139 changes: 53 additions & 86 deletions frontend/src/Pages/LoginPage.jsx
Original file line number Diff line number Diff line change
@@ -1,112 +1,79 @@
import React, { useState } from 'react';
import logo from '../assets/stationsaarthi.svg'; // Import your logo
import { useNavigate } from 'react-router-dom';
import React, { useState } from 'react';
import logo from '../assets/stationsaarthi.svg'; // Import your logo

const Login = () => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');

const handleLogin = (e) => {
e.preventDefault();
// Handle login logic here
};

const navigate = useNavigate();

const handleLogin = (e) => {
e.preventDefault();

// Fetch the login API from the backend
fetch('http://localhost:3000/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email,
password
}),
credentials: 'include'
})
.then(res => {
// Check if the response is OK (status 200-299)
if (res.ok) {
return res.json(); // Parse the JSON data if response is successful
} else {
// If the response is not OK, throw an error to be caught later
throw new Error(`Login failed! Status: ${res.status}`);
}
})
.then(data => {
// Handle the response data if login is successful
console.log('Login successful:', data);
setTimeout(() => {
navigate('/logged-in');
}, 500); // Short delay to allow the cookie to propagate
})
.catch(error => {
// Handle errors like incorrect login or network issues
console.error('Login failed:', error);
});
};

return (
<div className="flex flex-col items-center justify-center min-h-screen bg-gradient-to-b from-blue-200 to-blue-500">
{/* Logo, Title, and Tagline */}
<div className="text-center mb-8">
<img src={logo} alt="Station Saarthi Logo" className="mx-auto w-28 h-28" /> {/* Larger logo */}
<h1 className="text-4xl font-bold text-white mt-4">Station Saarthi</h1>
<p className="text-white opacity-80 mt-2 text-lg">Your Trusted Platform Guide</p>
return (
<div className="flex flex-col items-center justify-center min-h-screen bg-gradient-to-b from-blue-100 to-blue-5000">
{/* Logo and Title */}
<div className="text-center mb-10 ">
<img src={logo} alt="Station Saarthi Logo" className="mx-auto w-20 h-22 " />
<h1 className="text-4xl font-bold text-gray-800 mt-4 ">Station Saarthi</h1>
<p className="text-gray-600 mt-2 text-lg ">Your Trusted Platform Guide</p>
</div>


{/* Login Form */}
<form onSubmit={handleLogin} className="bg-white p-8 rounded-lg shadow-lg w-full max-w-md">
{/* Email Input */}
<div className="mb-6">
<label className="block text-gray-700 font-semibold mb-2" htmlFor="email">Email</label>
<form onSubmit={handleLogin} className="w-full max-w-sm bg-white p-8 rounded-lg shadow-md">
{/* Login Heading */}
<h2 className="text-xl font-bold text-center mb-4 py-1 bg-blue-100 border border-blue-300 rounded-3xl shadow-sm">
Login
</h2>

{/* Username Input */}
<div className="mb-5">
<label className=" block text-gray-700 font-semibold mb-2" htmlFor="username">Username</label>
<input
type="text"
id="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Enter your email"
className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition duration-300"
type="text"
id="username"
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder="Enter your username"
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition duration-300"
required
/>
</div>
/>
</div>

{/* Password Input */}
<div className="mb-6">
<label className="block text-gray-700 font-semibold mb-2" htmlFor="password">Password</label>
<input
type="password"
id="password"
value={password}
{/* Password Input */}
<div className="mb-6">
<label className="block text-gray-700 font-semibold mb-2" htmlFor="password">Password</label>
<input
type="password"
id="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Enter your password"
className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition duration-300"
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition duration-300"
required
/>
</div>

{/* Login Button */}
{/* Login Button */}
<button
type="submit"
className="w-full bg-blue-600 text-white py-3 rounded-lg font-semibold hover:bg-blue-700 transition duration-300 ease-in-out transform hover:scale-105"
className="w-full py-3 bg-blue-500 text-white font-semibold rounded-lg hover:bg-blue-600 transition duration-300 ease-in-out transform hover:scale-105"
>
Login
</button>
</form>

{/* Divider */}
<div className="mt-6 text-center">
<hr className="border-t border-gray-200" />
</div>

{/* Register Link */}
<p className="mt-4 text-white">
{/* Don't have an account link */}
<p className="mt-6 text-gray-600">
Don't have an account?{' '}
<a href="/register" className="text-white font-semibold hover:underline transition duration-300 transform hover:scale-105">
<a href="/register" className="text-blue-500 font-semibold hover:underline transition duration-300 transform hover:scale-105">
Register
</a>
</p>
</div>
);
};
</a>
</p>
</div>
);
};

export default Login;
export default Login;
89 changes: 28 additions & 61 deletions frontend/src/Pages/Register.jsx
Original file line number Diff line number Diff line change
@@ -1,135 +1,102 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import logo from '../assets/stationsaarthi.svg'; // Import your logo
import logo from '../assets/stationsaarthi.svg'; // Ensure the path is correct

const Register = () => {
const [name, setName] = useState('');
const [phoneNumber, setPhoneNumber] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');

const navigate = useNavigate();

const handleRegister = (e) => {
e.preventDefault();

// Fetch the register API from the backend
fetch('http://localhost:3000/auth/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name,
phoneNumber,
email,
password
}),
credentials: 'include'
})
.then(res => {
// Check if the response is OK (status 200-299)
if (res.ok) {
// If the response is successful, return the JSON data
return res.json();
} else {
// If the response is not OK, throw an error to be caught later
throw new Error(`HTTP error! status: ${res.status}`);
}
})
.then(data => {
// Handle the response data if successful
console.log('Registration successful:', data);
setTimeout(() => {
navigate('/logged-in');
}, 500); // Short delay to allow the cookie to propagate
})
.catch(error => {
// Handle errors such as invalid response or network issues
console.error('Registration failed:', error);
});
// Handle registration logic here
};

return (
<div className="flex flex-col items-center justify-center min-h-screen bg-gradient-to-b from-blue-200 to-blue-5000">
<div className="flex flex-col items-center justify-center min-h-screen bg-gradient-to-b from-blue-100 to-blue-5000 px-4">
{/* Logo and Title */}
<div className="text-center mb-10">
<img src={logo} alt="Station Saarthi Logo" className="mx-auto w-28 h-28" />
<h1 className="text-4xl font-bold text-gray-800 mt-4">Station Saarthi</h1>
<p className="text-gray-600 mt-2 text-lg">Register New User</p>
<div className="text-center mb-6">
<img src={logo} alt="Station Saarthi Logo" className="mx-auto w-20 h-22 mb-2" />
<h1 className="text-2xl font-bold text-gray-800">Station Saarthi</h1>
<p className="text-gray-700 mt-1 text-sm">Your Trusted Platform Guide</p>
</div>

{/* Registration Form */}
<form onSubmit={handleRegister} className="w-full max-w-md bg-white p-8 rounded-lg shadow-md">
<form onSubmit={handleRegister} className="w-full max-w-sm bg-white p-6 rounded-lg shadow-md">
{/* Register Heading */}
<h2 className="text-xl font-bold text-center mb-4 py-1 bg-blue-100 border border-blue-300 rounded-3xl shadow-sm">
Register
</h2>

{/* Name Input */}
<div className="mb-5">
<label className="block text-gray-700 font-semibold mb-2" htmlFor="name">Name</label>
<div className="mb-4">
<label className="block text-gray-700 font-semibold mb-1" htmlFor="name">Name</label>
<input
type="text"
id="name"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Enter your name"
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition duration-300"
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 text-sm"
required
/>
</div>

{/* Phone Number Input */}
<div className="mb-5">
<label className="block text-gray-700 font-semibold mb-2" htmlFor="phoneNumber">Phone Number</label>
<div className="mb-4">
<label className="block text-gray-700 font-medium mb-1" htmlFor="phoneNumber">Phone Number</label>
<input
type="tel"
id="phoneNumber"
value={phoneNumber}
onChange={(e) => setPhoneNumber(e.target.value)}
placeholder="Enter your phone number"
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition duration-300"
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 text-sm"
required
/>
</div>

{/* Email Input */}
<div className="mb-5">
<label className="block text-gray-700 font-semibold mb-2" htmlFor="email">Email</label>
<div className="mb-4">
<label className="block text-gray-700 font-medium mb-1" htmlFor="email">Email</label>
<input
type="email"
id="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Enter your email"
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition duration-300"
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 text-sm"
required
/>
</div>

{/* Password Input */}
<div className="mb-6">
<label className="block text-gray-700 font-semibold mb-2" htmlFor="password">Password</label>
<div className="mb-5">
<label className="block text-gray-700 font-medium mb-1" htmlFor="password">Password</label>
<input
type="password"
id="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Create a password"
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition duration-300"
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 text-sm"
required
/>
</div>

{/* Register Button */}
<button
type="submit"
className="w-full py-3 bg-blue-500 text-white font-semibold rounded-lg hover:bg-blue-600 transition duration-300 ease-in-out transform hover:scale-105"
className="w-full py-2 bg-blue-500 text-white font-semibold rounded-md hover:bg-blue-600 transition duration-300 ease-in-out transform hover:scale-105 text-sm"
>
Register
</button>
</form>

{/* Already have an account link */}
<p className="mt-6 text-gray-600">
<p className="mt-4 text-gray-700 text-sm">
Already have an account?{' '}
<a href="/login" className="text-blue-500 font-semibold hover:underline transition duration-300 transform hover:scale-105">
<a href="/login" className="text-blue-500 font-medium hover:underline transition duration-300 transform hover:scale-105">
Log in
</a>
</p>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/Pages/hamburger.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit 2ddce2c

Please sign in to comment.