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

version 2.2.3 #2

Open
wants to merge 1 commit into
base: verifyEmail
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
3 changes: 1 addition & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Footer from './components/Footer';
import LoginPage from './components/LoginPage'; // Import your LoginPage component
import SignupPage from './components/SignupPage'; // Import your SignupPage component
import DashboardPage from './components/DashboardPage'; // Import the DashboardPage
import ConfirmationPage from './components/ConfirmationPage';
import './App.css';

function App() {
Expand Down Expand Up @@ -38,7 +37,7 @@ function App() {
{/* Add the Dashboard route */}
<Route path="/dashboard" component={DashboardPage} />
{/* Add the Confirmation route */}
<Route path="/confirm/:token" element={<ConfirmationPage />} />
<Route path="/confirm/:token" element={<LoginPage />} />

</Routes>
</div>
Expand Down
29 changes: 0 additions & 29 deletions src/components/ConfirmationPage.js

This file was deleted.

11 changes: 11 additions & 0 deletions src/components/LoginPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ const LoginPage = () => {
</div>
<button type="submit" className="login-button title-medium">Login</button>
</form>
{/* Signup Redirect Link */}
<p className="signup-redirect text-normal">
You don't have an account?{' '}
<span
className="signup-link"
onClick={() => navigate('/signup')} // Redirect to signup page
style={{ color: '#A98467', cursor: 'pointer' }} // Optional styling
>
Sign up
</span>
</p>
</div>
);
};
Expand Down
10 changes: 9 additions & 1 deletion src/components/Navbar.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import React from 'react';
import '../App.css';
import logo from '../assets/logo.png'; // Import the image
import { useNavigate } from 'react-router-dom'; // Import useNavigate

const Navbar = () => {
const navigate = useNavigate(); // Initialize useNavigate

// Function to handle logo click
const handleLogoClick = () => {
navigate('/'); // Redirect to the index/home page
};

return (
<nav className="navbar">
<div className="logo">
<div className="logo" onClick={handleLogoClick} style={{ cursor: 'pointer' }}>
<img src={logo} alt="Logo" /> {/* Use the imported image */}
</div>
<ul className="nav-links">
Expand Down
13 changes: 12 additions & 1 deletion src/components/SignupPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const SignupPage = () => {

if (response.ok) {
// Successful signup
navigate('/dashboard'); // Redirect to the dashboard after successful signup
navigate('/login'); // Redirect to the login page after successful signup
} else {
// Handle backend errors (e.g., user already exists, validation errors)
setErrorMessage(data.message || 'Signup failed. Please try again.');
Expand Down Expand Up @@ -135,6 +135,17 @@ const SignupPage = () => {
{isLoading ? 'Signing up...' : 'Sign Up'}
</button>
</form>
{/* Login Redirect Link */}
<p className="login-redirect text-normal">
You already have an account?{' '}
<span
className="login-link"
onClick={() => navigate('/login')} // Redirect to login page
style={{ color: '#A98467', cursor: 'pointer' }} // Optional styling
>
Login
</span>
</p>
</div>
);
};
Expand Down
26 changes: 18 additions & 8 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ app.use(cors({

app.use(express.json());


// Configure express-session middleware
app.use(session({
secret: '123', // Change this to a secure secret key
Expand Down Expand Up @@ -47,8 +46,6 @@ db.connect((err) => {
console.log('Connected to MySQL');
});



// Setup Nodemailer transport
const transporter = nodemailer.createTransport({
service: 'gmail', // You can use other services too
Expand All @@ -58,6 +55,11 @@ const transporter = nodemailer.createTransport({
}
});

// Function to generate a random verification code
const generateVerificationCode = () => {
return Math.floor(100000 + Math.random() * 900000).toString(); // Generates a 6-digit code
};

// Signup function
const handleSignup = (req, res) => {
console.log('Starting signup process...'); // Log the start
Expand Down Expand Up @@ -98,7 +100,7 @@ const handleSignup = (req, res) => {
// Send confirmation email
const confirmationLink = `http://localhost:3000/confirm/${token}`;
const mailOptions = {
from: 'your-email@gmail.com',
from: 'samah.ikramfarez@gmail.com', // Your email
to: email,
subject: 'Email Confirmation',
html: `<h1>Welcome ${fullName}!</h1>
Expand All @@ -119,7 +121,6 @@ const handleSignup = (req, res) => {
});
};


// Login function
const handleLogin = (req, res) => {
const { email, password } = req.body;
Expand All @@ -136,6 +137,11 @@ const handleLogin = (req, res) => {

const user = result[0];

// Check if user is verified
if (!user.isVerified) {
return res.status(403).json({ error: 'Email not confirmed. Please check your inbox.' });
}

// Compare passwords using bcrypt
bcrypt.compare(password, user.password, (err, isMatch) => {
if (err) {
Expand Down Expand Up @@ -169,10 +175,11 @@ app.get('/dashboard', (req, res) => {
}
});

// Email confirmation endpoint
app.get('/confirm/:token', (req, res) => {
const token = req.params.token;

const verifyTokenQuery = 'UPDATE Users SET isVerified = 1 WHERE token = ?';
const verifyTokenQuery = 'UPDATE Users SET isVerified = 1, token = NULL WHERE token = ?';
db.query(verifyTokenQuery, [token], (err, result) => {
if (err) {
console.error('Error confirming token:', err);
Expand All @@ -183,11 +190,14 @@ app.get('/confirm/:token', (req, res) => {
return res.status(400).json({ message: 'Invalid token or user already verified' });
}

res.status(200).json({ message: 'Email confirmed successfully!' });
// Redirect to login page
res.status(200).json({
message: 'Email confirmed successfully!',
redirectUrl: 'http://localhost:3000/login' // Adjust the URL if needed
});
});
});


// Signup route
app.post('/signup', handleSignup);

Expand Down