diff --git a/backend/server.js b/backend/server.js index e579444..35c0643 100755 --- a/backend/server.js +++ b/backend/server.js @@ -73,21 +73,32 @@ app.use((req, res, next) => { // Route for user registration app.post('/api/register', async (req, res) => { - const { userId, username, password } = req.body; + const { + userId, + username, + password, + firstname, + lastname, + email, + zipcode, + state, + area + } = req.body; - if (!userId || !username || !password) { + // Validate all required fields + if (!userId || !username || !password || !firstname || !lastname || !email || !zipcode || !state || !area) { return res.status(400).json({ error: 'All fields are required' }); } try { - const hashedPassword = await bcrypt.hash(password, 10); // Hash the password - - // Step 1: Insert into user_auth + const hashedPassword = await bcrypt.hash(password, 10); + + // Insert into user_auth const authQuery = ` - INSERT INTO user_auth (username, hashed_password) - VALUES (?, ?) + INSERT INTO user_auth (user_id, username, hashed_password) + VALUES (?, ?, ?) `; - db.run(authQuery, [username, hashedPassword], function (err) { + db.run(authQuery, [userId, username, hashedPassword], function (err) { if (err) { console.error('Error inserting into user_auth:', err.message); if (err.message.includes('UNIQUE constraint failed')) { @@ -95,22 +106,19 @@ app.post('/api/register', async (req, res) => { } return res.status(500).json({ error: 'Failed to register user' }); } - - const user_id = this.lastID; // Retrieve the auto-generated id from user_auth - - // Step 2: Insert into user_profile + + // Insert into user_profile with actual provided values const profileQuery = ` - INSERT INTO user_profile (id, user_id, firstname, lastname, email, zipcode, state, area) - VALUES (?, ?, NULL, NULL, NULL, NULL, NULL, NULL) + INSERT INTO user_profile (user_id, firstname, lastname, email, zipcode, state, area) + VALUES (?, ?, ?, ?, ?, ?, ?) `; - db.run(profileQuery, [user_id, user_id], (err) => { + db.run(profileQuery, [userId, firstname, lastname, email, zipcode, state, area], (err) => { if (err) { console.error('Error inserting into user_profile:', err.message); return res.status(500).json({ error: 'Failed to create user profile' }); } - - // Return success response after both inserts - res.status(201).json({ message: 'User registered successfully', user_id }); + + res.status(201).json({ message: 'User registered successfully', userId }); }); }); } catch (error) { @@ -119,6 +127,7 @@ app.post('/api/register', async (req, res) => { } }); + // Route to save or update user profile app.post('/api/user-profile', (req, res) => { const token = req.headers.authorization?.split(' ')[1]; diff --git a/backend/server3.js b/backend/server3.js index b664559..2c3dc49 100644 --- a/backend/server3.js +++ b/backend/server3.js @@ -66,6 +66,38 @@ const authenticatePremiumUser = (req, res, next) => { } }; +/* ------------------------------------------------------------------ +PREMIUM UPGRADE ENDPOINT +------------------------------------------------------------------ */ +app.post('/api/activate-premium', (req, res) => { + const token = req.headers.authorization?.split(' ')[1]; + if (!token) { + return res.status(401).json({ error: 'Authorization token is required' }); + } + + let userId; + try { + const decoded = jwt.verify(token, SECRET_KEY); + userId = decoded.userId; + } catch (error) { + return res.status(401).json({ error: 'Invalid or expired token' }); + } + + const query = ` + UPDATE user_profile + SET is_premium = 1, is_pro_premium = 1 + WHERE user_id = ? + `; + db.run(query, [userId], (err) => { + if (err) { + console.error('Error updating premium status:', err.message); + return res.status(500).json({ error: 'Failed to activate premium' }); + } + res.status(200).json({ message: 'Premium activated successfully' }); + }); +}); + + /* ------------------------------------------------------------------ CAREER PROFILE ENDPOINTS ------------------------------------------------------------------ */ diff --git a/src/App.js b/src/App.js index 93907df..2d8f92d 100644 --- a/src/App.js +++ b/src/App.js @@ -7,6 +7,7 @@ import { useLocation, Link, } from 'react-router-dom'; +import { Button } from './components/ui/button.js'; // Import all components import PremiumRoute from './components/PremiumRoute.js'; @@ -103,168 +104,114 @@ function App() {
+
- Registration successful! -
- )} +