-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Create Email Transporter Object Create Email Object that uses takes gmail email and password from .env || SendMail function takes in (recipient email, email subject, and email contact) parameters to send out an email * Update isAuthenticated to involve 2fa User needs session two be authenticated in order to proceed. * Add 2fa routing Route to email authentication page utilizing time-based one time password to authenticate * Adding ToTP Generator 1. Take in Request 2. Generate token and key 3. Send Token to Email 4. Save Key in Request for Authentication * Create Two Factor View * Nodemail log-in var * Update local.js * Update RingdownForm.js (#288) (#290) * Update RingdownForm.js * Prettier * prettier * cicd * redirects when authenticated * cicd * Making generateToTP a reusable function * Switched from notp to OTPAuth * Save Token to Database instead of Session * MailCatcher up and Running! * Link logo to send to user back to Login from 2fa * turn sendEmail into a separate function * WIP * Migration for TwoFactorAuth * rector ssodata to twofactordata * correcting JSON formatting * Playwright Tests * Tests! * Test edits * yml * Fix typo in package.json script * Fix formatting * eslint & migration * Commented out home page tests * prettier * Remove previous addition of Auth-Related Columns * Adding two Factor Flow to all tests * Put 2fa for tests into helper fx for cleaner code * Parameterize SMTP settings, update example.env * Refactoring * refactoring, adding else statement before next() * Code style changes --------- Co-authored-by: holliskuang <[email protected]> Co-authored-by: Francis Li <[email protected]>
- Loading branch information
1 parent
ef53bbe
commit a05e47b
Showing
22 changed files
with
667 additions
and
436 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -9,6 +9,11 @@ REACT_APP_DISABLE_CODE_3= | |
REACT_APP_DISABLE_PILOT_HOSPITALS= | ||
REACT_APP_PILOT_SHOW_ALL_RINGDOWNS= | ||
SESSION_SECRET=makeitasecretinprod | ||
SMTP_HOST=mail | ||
SMTP_PORT=1025 | ||
SMTP_USER= | ||
SMTP_PASSWORD= | ||
SMTP_REPLY_TO=[email protected] | ||
|
||
EMS_USER=[email protected] | ||
EMS_PASS=abcd1234 | ||
|
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const nodemailer = require('nodemailer'); | ||
const nodemailermock = require('nodemailer-mock'); | ||
|
||
// create reusable transporter class using the default SMTP transport with functions | ||
function createTransport() { | ||
// nodeMailer options | ||
const options = { | ||
host: process.env.SMTP_HOST, | ||
port: process.env.SMTP_PORT, | ||
auth: { | ||
user: process.env.SMTP_USER, | ||
pass: process.env.SMTP_PASSWORD, | ||
}, | ||
}; | ||
// mock Transporter in testing env | ||
const transporter = process.env.NODE_ENV === 'test' ? nodemailermock.createTransport(options) : nodemailer.createTransport(options); | ||
return transporter; | ||
} | ||
// send mail with defined transport object | ||
function sendMail(transporter, recipient, subject, content) { | ||
const mailOptions = { | ||
from: process.env.SMTP_REPLY_TO, | ||
to: recipient, | ||
subject: subject, | ||
text: content, | ||
}; | ||
transporter.sendMail(mailOptions, (error, info) => { | ||
if (error) { | ||
console.log(error); | ||
} else { | ||
console.log('Email sent: ' + info.response); | ||
} | ||
}); | ||
} | ||
|
||
module.exports = { createTransport, sendMail }; |
13 changes: 13 additions & 0 deletions
13
server/migrations/20230503083739-add-twofactor-to-batsuser.js
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
await queryInterface.sequelize.transaction(async (transaction) => { | ||
await queryInterface.addColumn('batsuser', 'twofactordata', Sequelize.JSONB, { transaction }); | ||
}); | ||
}, | ||
|
||
async down(queryInterface, Sequelize) { | ||
await queryInterface.sequelize.transaction(async (transaction) => { | ||
await queryInterface.removeColumn('batsuser', 'twofactordata', { transaction }); | ||
}); | ||
}, | ||
}; |
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
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,27 @@ | ||
/* eslint-env mocha */ | ||
|
||
const assert = require('assert'); | ||
const HttpStatus = require('http-status-codes'); | ||
const session = require('supertest-session'); | ||
|
||
const helper = require('../../helper'); | ||
const app = require('../../../app'); | ||
const nodemailermock = require('nodemailer-mock'); | ||
|
||
describe('/api/ambulances', () => { | ||
let testSession; | ||
|
||
beforeEach(async () => { | ||
await helper.loadFixtures(['organizations', 'users', 'ambulances']); | ||
|
||
testSession = session(app); | ||
await testSession | ||
.post('/auth/local/login') | ||
.set('Accept', 'application/json') | ||
.send({ username: '[email protected]', password: 'abcd1234' }); | ||
await helper.twoFactorAuthSession(testSession); | ||
}); | ||
afterEach(async () => { | ||
nodemailermock.mock.reset(); | ||
}); | ||
|
||
describe('GET /identifiers', () => { | ||
|
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,9 +1,12 @@ | ||
/* eslint-env mocha */ | ||
|
||
const assert = require('assert'); | ||
const HttpStatus = require('http-status-codes'); | ||
const session = require('supertest-session'); | ||
|
||
const helper = require('../../helper'); | ||
const app = require('../../../app'); | ||
const nodemailermock = require('nodemailer-mock'); | ||
|
||
describe('/api/emscalls', () => { | ||
let testSession; | ||
|
@@ -24,6 +27,10 @@ describe('/api/emscalls', () => { | |
.post('/auth/local/login') | ||
.set('Accept', 'application/json') | ||
.send({ username: '[email protected]', password: 'abcd1234' }); | ||
await helper.twoFactorAuthSession(testSession); | ||
}); | ||
afterEach(async () => { | ||
nodemailermock.mock.reset(); | ||
}); | ||
|
||
describe('GET /dispatch-call-numbers', () => { | ||
|
Oops, something went wrong.