forked from GlobaLexTranslate/GlobaLex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
28 additions
and
90 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
<hgroup> | ||
<h2>Contact Book</h2> | ||
</hgroup> | ||
<div> | ||
<div> | ||
<ul> | ||
<li>Bob Jones</li> | ||
<li>Amy Ho</li> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); |