Skip to content

Commit

Permalink
comment out exception code
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamChiu committed Dec 11, 2020
1 parent 213cbb8 commit f419746
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
39 changes: 21 additions & 18 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,20 @@ function passport_callback (accessToken, refreshToken, profile, done){
let email = profile?._json?.email
// console.log("HEREEEE HEREEEEEE!!!!")
// console.log(email)
if (EXCEPTIONS.includes(email)) {
MongoClient.connect(url, function (err, client) {
const db = client.db(dbName)
const usersCol = db.collection('users')
usersCol.findOne({ email }, (err, result) => {
if (!result) {
usersCol.insertOne({ email, location: "Butler" }, err => {
if (err) console.log(err)
})
}
})
})
return done(null, profile)
}
// if (EXCEPTIONS.includes(email)) {
// MongoClient.connect(url, function (err, client) {
// const db = client.db(dbName)
// const usersCol = db.collection('users')
// usersCol.findOne({ email }, (err, result) => {
// if (!result) {
// usersCol.insertOne({ email, location: "Butler" }, err => {
// if (err) console.log(err)
// })
// }
// })
// })
// return done(null, profile)
// }
if (!email)
done(null, false, { message: "Not a Columbia/Barnard email" })
else if (profile?._json?.hd !== "columbia.edu" && profile?._json?.hd !== "barnard.edu")
Expand Down Expand Up @@ -186,8 +186,8 @@ app.get('/success', /* istanbul ignore next */ (req, res) => {
})
app.get('/error', /* istanbul ignore next */ (req, res) => res.send("error logging in"))

app.post('/invite', /* istanbul ignore next */ async (req, res) => {
let testAccount = await nodemailer.createTestAccount();
async function handleInvite(req, res) {
await nodemailer.createTestAccount();
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
Expand All @@ -202,7 +202,10 @@ app.post('/invite', /* istanbul ignore next */ async (req, res) => {
text: "Come on over and spend some time on campus: http://localhost:3000", // plain text body
html: "<b>Come on over and spend some time on campus: <a href='http://localhost:3000'>Join here!</a></b>", // html body
})
})
res.send("Email sent")
}

app.post('/invite', /* istanbul ignore next */ handleInvite)

// TODO
// Figure out how to create a websocket route for clients to connect to and receive messages
Expand Down Expand Up @@ -426,7 +429,7 @@ function moveCheck(email, location, socket) {
return {room: room, email: email, location: location}
}

module.exports = {checkMongo, insertRooms, initializeRooms, server:server, app:app, checkDisconnect:checkDisconnect, Lions:Lions, Rooms:Rooms, io:io, moveCheck:moveCheck,
module.exports = {checkMongo, handleInvite, insertRooms, initializeRooms, server:server, app:app, checkDisconnect:checkDisconnect, Lions:Lions, Rooms:Rooms, io:io, moveCheck:moveCheck,
validLocation: validLocation, joinRoom:joinRoom, moveRoom:moveRoom, loggedIn: loggedIn, invalidRoomMsg: invalidRoomMsg,
changeRoomCallback: changeRoomCallback, initRooms:initRooms, passport_callback: passport_callback, onConnection, handleChat, handleMove, handleRoom, handleNewSocket};
// module.exports = server;
6 changes: 6 additions & 0 deletions backend/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,12 @@ describe("Test passport", () => {
passport_callback('','', profile_mock, done)
});

test("check email sending", async finished =>{
const {handleInvite} = require('./app')
handleInvite({body: {invitee: "[email protected]"}}, {send: () => {}})
finished()
});

test("check new valid email credentials", async finished =>{
const {passport_callback} = require('./app')
const MongoClient = require('mongodb').MongoClient
Expand Down

0 comments on commit f419746

Please sign in to comment.