Skip to content

Commit

Permalink
Version before OAuth Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ukataria committed Feb 8, 2024
1 parent e26e73d commit deb0c6e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 90 deletions.
4 changes: 0 additions & 4 deletions .env

This file was deleted.

37 changes: 0 additions & 37 deletions config/passport-setup.js

This file was deleted.

10 changes: 0 additions & 10 deletions models/user.js

This file was deleted.

2 changes: 1 addition & 1 deletion public/CallPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<hgroup>
<h2>Contact Book</h2>
</hgroup>
<div>
<div>
<ul>
<li>Bob Jones</li>
<li>Amy Ho</li>
Expand Down
2 changes: 1 addition & 1 deletion public/Login.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css">
<title>Login Page</title>
<script>
<script>
async function handleLogin(event) {
event.preventDefault();
const email = document.getElementById('email').value;
Expand Down
2 changes: 1 addition & 1 deletion public/SignUpPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css">
<title>Sign Up Page</title>
</head>
</head>
<body>
<nav class="container-fluid">
<ul><li><strong>GLOBALEX</strong></li></ul>
Expand Down
29 changes: 14 additions & 15 deletions routes/auth.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
const router = require('express').Router();
const passport = require('passport');
const express = require('express');
const bcrypt = require('bcrypt');
const router = express.Router();

router.get('/login', (req, res) => {
res.send('Login Page');
// POST /register
router.post('/api/register', async (req, res) => {
const { name, email, password } = req.body;
const hashedPassword = await bcrypt.hash(password, 10);
console.log('User registered:', { name, email, hashedPassword });
res.status(201).send('User registered successfully');
});

router.get('/logout', (req, res) => {
req.logout();
res.redirect('/');
});

router.get('/google', passport.authenticate('google', {
scope: ['profile']
}));

router.get('/google/redirect', passport.authenticate('google'), (req, res) => {
res.redirect('/profile'); // Redirect to a profile page or wherever you like
// POST /login
router.post('/api/login', async (req, res) => {
// Placeholder for authentication logic
console.log('User login attempt:', req.body);
res.send('Login successful');
});

module.exports = router;
32 changes: 11 additions & 21 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
require('dotenv').config();
const express = require('express');
const mongoose = require('mongoose');
const passport = require('passport');
const passportSetup = require('./config/passport-setup');
const bodyParser = require('body-parser');
const path = require('path');
const authRoutes = require('./routes/auth');
const cookieSession = require('cookie-session');

const app = express();
const port = 3000;

// Connect to MongoDB
mongoose.connect(process.env.MONGO_DB_URI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log('MongoDB connected'))
.catch(err => console.error(err));
// Serve static files from the 'public' folder
app.use(express.static(path.join(__dirname, 'public')));

app.use(cookieSession({
maxAge: 24 * 60 * 60 * 1000, // One day in milliseconds
keys: [process.env.SESSION_COOKIE_KEY]
}));
// Middleware to parse JSON bodies
app.use(bodyParser.json());

// Initialize passport
app.use(passport.initialize());
app.use(passport.session());

// Set up routes
app.use('/auth', authRoutes);
// Use authentication routes
app.use(authRoutes);

// Redirect root URL to Login.html
app.get('/', (req, res) => {
res.send('Home Page');
res.redirect('/Login.html');
});

app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`);
console.log(`Server running at http://localhost:${port}`);
});

0 comments on commit deb0c6e

Please sign in to comment.