-
Notifications
You must be signed in to change notification settings - Fork 3
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
48 changed files
with
870 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
MONGODB_URI=<Test database url> | ||
MONGOHQ_URL_TEST=<Test database url> | ||
MONGODB_URI=<Development database url> | ||
SECRET_KEY=<Secret key for JWT> | ||
GMAIL_PASSWORD=<password is pinned at slack channel> |
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ public/lib | |
.DS_store | ||
c4h_keys.txt | ||
.env | ||
reports/ | ||
.nyc_output/ | ||
.coverrun | ||
dist | ||
.coveralls.yml | ||
|
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* eslint no-useless-escape: 0, no-console: 0 */ | ||
import nodemailer from 'nodemailer'; | ||
import IsUrl from 'is-url'; | ||
|
||
/** | ||
* @param {string} email - is the user's email | ||
* @returns {boolean} boolean if email verification fails | ||
*/ | ||
const IsEmail = (email) => { | ||
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
return re.test(String(email).toLowerCase()); | ||
}; | ||
|
||
/** | ||
* @param {object} user - the email of the user to be invited | ||
* @param {string} link - the custom link for the current game | ||
* @description this function takes a (email, link) argument and sends | ||
* a meal bearing the game's link | ||
* @returns {null} returns nothing | ||
*/ | ||
const sendInvitationEmail = (user, link) => { | ||
if (!(IsEmail(user.email) && IsUrl(link))) { | ||
return false; | ||
} | ||
// Setup mail transport config | ||
const transporter = nodemailer.createTransport({ | ||
service: 'gmail', | ||
host: 'smtp.gmail.com', | ||
port: 587, | ||
auth: { | ||
user: 'bendevtester@gmail.com', | ||
pass: process.env.GMAIL_PASSWORD | ||
} | ||
}); | ||
|
||
const message = `Hello, <b>${user.name}</b><br/><br/><p>Your friend has invited you to join the ongoing CFH game.<br/><br/>You can click <a href="${link}">here</a> to join the game.</p>`; | ||
|
||
// Setup mail transport options | ||
const mailOptions = { | ||
from: '"Bigger Ben" <no-reply@cfh.et>', | ||
to: user.email, | ||
subject: 'CFH Invitation', | ||
html: message | ||
}; | ||
|
||
// send mail with defined transport object | ||
transporter.sendMail(mailOptions, (error, info) => { | ||
if (error) { | ||
return console.log(error); | ||
} | ||
console.log('Message sent: %s', info.messageId); | ||
}); | ||
return true; | ||
}; | ||
|
||
export default sendInvitationEmail; |
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 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
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,30 @@ | ||
/* eslint no-undef: 0 */ | ||
import { expect } from 'chai'; | ||
import sendInvitationEmail from '../../app/helpers/sendInvitationEmail'; | ||
|
||
|
||
describe('Send email invitation', () => { | ||
it('should return true if email goes through', () => { | ||
const user = { | ||
email: 'testemail@gmaill.com', | ||
}; | ||
const link = 'http://localhost:4040/app'; | ||
expect(sendInvitationEmail(user, link)).to.equal(true); | ||
}); | ||
|
||
it('should return false if wrong email address is supplied', () => { | ||
const user = { | ||
email: 'wrongEmail.com', | ||
}; | ||
const link = 'http://localhost:4040/app'; | ||
expect(sendInvitationEmail(user, link)).to.equal(false); | ||
}); | ||
|
||
it('should return false the link supplied is not a valid URL', () => { | ||
const user = { | ||
email: 'ben@gmail.com', | ||
}; | ||
const link = 'htlocalhost:4040/app'; | ||
expect(sendInvitationEmail(user, link)).to.equal(false); | ||
}); | ||
}); |
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
Oops, something went wrong.