Skip to content

Commit

Permalink
Merge 422b32d into 1dd2cba
Browse files Browse the repository at this point in the history
  • Loading branch information
anneKay committed Sep 2, 2018
2 parents 1dd2cba + 422b32d commit dae573c
Show file tree
Hide file tree
Showing 30 changed files with 2,987 additions and 474 deletions.
13 changes: 13 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
FACEBOOK_APP_ID=
FACEBOOK_APP_SECRET=
PROJECT_ID=
CLIENT_EMAIL=
PRIVATE_KEY=
DB_URL=
PROJECT_KEY_ID=
AUTH_URI=
TOKEN_URI=
AUTH_PROVIDER_X509_CERT_URL=
CLIENT_X509_CERT_URL=
SECRETE_KEY=
VERIFYTOKEN_EXPIRY=
URL_HOST=
NO_REPLY_MAIL=
1 change: 0 additions & 1 deletion config/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { } from 'dotenv/config';
module.exports = {
development: {
username: process.env.DB_USER,
Expand Down
12 changes: 12 additions & 0 deletions config/serviceAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
type: 'service_account',
project_id: process.env.PROJECT_ID,
private_key_id: process.env.PRIVATE_KEY_ID,
private_key: process.env.PRIVATE_KEY.replace(/\\n/g, '\n'),
client_email: process.env.CLIENT_EMAIL,
client_id: process.env.CLIENT_ID,
auth_uri: process.env.AUTH_URI,
token_uri: process.env.TOKEN_URI,
auth_provider_x509_cert_url: process.env.AUTH_PROVIDER_X509_CERT_URL,
client_x509_cert_url: process.env.CLIENT_X509_CERT_URL
};
1 change: 0 additions & 1 deletion controllers/ArticleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class ArticleController {
.catch(() => createArticleHelper(res, articleObject));
}

// if there no image was provided go ahead to create the article
return createArticleHelper(res, articleObject);
}

Expand Down
82 changes: 38 additions & 44 deletions controllers/UsersController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,28 @@ export default class UsersController {
}
User.find({
where: {
[Op.or]: [{ email }, { username }]
[Op.or]: [{ email }, { username }],
},
}).then((user) => {
if (!user) {
User.create({
email,
username,
hashedPassword: hash,
}).then((registeredUser) => {
const token = utils.signToken({ id: registeredUser.id });
sendVerificationEmail.sendEmail(registeredUser);
res.status(200).json(utils.userToJson(registeredUser, token));
}).catch(next);
} else {
res.status(409).json({
success: false,
errors: {
body: ['Username or email already exists'],
}
});
}
})
.then((user) => {
if (!user) {
User.create({
email,
username,
hashedPassword: hash
})
.then((registeredUser) => {
const token = utils.signToken({ id: registeredUser.id });
sendVerificationEmail.sendEmail(registeredUser);
res.status(200).json(utils.userToJson(registeredUser, token));
})
.catch(next);
} else {
res.status(409).json({
success: false,
errors: {
body: ['Username or email already exists']
}
});
}
})
.catch(next);
});
}
Expand Down Expand Up @@ -96,14 +93,14 @@ export default class UsersController {
}

/**
* @function editProfile
* @summary Returns a user's details for their profile
* @param {object} req - Request object
* @param {object} res - Response object
* @param {*} next - Incase of errors
* @returns {object} An object containing all the data related to the user
*/
static getProfile(req, res, next) {
* @function getProfile
* @summary Returns a user's details for their profile
* @param {object} req - Request object
* @param {object} res - Response object
* @param {*} next - Incase of errors
* @returns {object} An object containing all the data related to the user
*/
static getProfile(req, res) {
User.findOne({ where: { username: req.params.username } })
.then((user) => {
if (!user) {
Expand All @@ -115,8 +112,7 @@ export default class UsersController {
});
}
return res.status(200).json(utils.userToJson(user));
})
.catch(next);
});
}

/**
Expand All @@ -140,17 +136,14 @@ export default class UsersController {
});
}
if (req.userId === user.id) {
User.update(
{
username,
image,
bio
},
{
returning: true,
where: { id: user.id }
}
)
User.update({
username,
image,
bio,
}, {
returning: true,
where: { id: user.id }
})
.then(([rows, [updatedUser]]) => {
if (rows === 0) {
return res.status(401).json({
Expand All @@ -168,6 +161,7 @@ export default class UsersController {
.catch(next);
}


/**
* Verify the email sent to the newly registered user
* @param {*} req - request object
Expand Down
236 changes: 236 additions & 0 deletions helpers/articleTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
exports.emailTemplate = (link, name) => `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Check out this Article</title>
<style type="text/css" rel="stylesheet" media="all">
/* Base ------------------------------ */
*:not(br):not(tr):not(html) {
font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
width: 100% !important;
height: 100%;
margin: 0;
line-height: 1.4;
background-color: #F5F7F9;
color: #839197;
-webkit-text-size-adjust: none;
}
a {
color: #414EF9;
}
/* Layout ------------------------------ */
.email-wrapper {
width: 100%;
margin: 0;
padding: 0;
background-color: #F5F7F9;
}
.email-content {
width: 100%;
margin: 0;
padding: 0;
}
/* Masthead ----------------------- */
.email-masthead {
padding: 25px 0;
text-align: center;
}
.email-masthead_logo {
max-width: 400px;
border: 0;
}
.email-masthead_name {
font-size: 16px;
font-weight: bold;
color: #839197;
text-decoration: none;
text-shadow: 0 1px 0 white;
}
/* Body ------------------------------ */
.email-body {
width: 100%;
margin: 0;
padding: 0;
border-top: 1px solid #E7EAEC;
border-bottom: 1px solid #E7EAEC;
background-color: #FFFFFF;
}
.email-body_inner {
width: 570px;
margin: 0 auto;
padding: 0;
}
.email-footer {
width: 570px;
margin: 0 auto;
padding: 0;
text-align: center;
}
.email-footer p {
color: #839197;
}
.body-action {
width: 100%;
margin: 30px auto;
padding: 0;
text-align: center;
}
.body-sub {
margin-top: 25px;
padding-top: 25px;
border-top: 1px solid #E7EAEC;
}
.content-cell {
padding: 35px;
}
.align-right {
text-align: right;
}
/* Type ------------------------------ */
h1 {
margin-top: 0;
color: #292E31;
font-size: 19px;
font-weight: bold;
text-align: left;
}
h2 {
margin-top: 0;
color: #292E31;
font-size: 16px;
font-weight: bold;
text-align: left;
}
h3 {
margin-top: 0;
color: #292E31;
font-size: 14px;
font-weight: bold;
text-align: left;
}
p {
margin-top: 0;
color: #839197;
font-size: 16px;
line-height: 1.5em;
text-align: left;
}
p.sub {
font-size: 12px;
}
p.center {
text-align: center;
}
/* Buttons ------------------------------ */
.button {
display: inline-block;
width: 200px;
background-color: #414EF9;
border-radius: 3px;
color: #ffffff;
font-size: 15px;
line-height: 45px;
text-align: center;
text-decoration: none;
-webkit-text-size-adjust: none;
mso-hide: all;
}
.button--green {
background-color: #28DB67;
}
.button--red {
background-color: #FF3665;
}
.button--blue {
background-color: #414EF9;
}
/*Media Queries ------------------------------ */
@media only screen and (max-width: 600px) {
.email-body_inner,
.email-footer {
width: 100% !important;
}
}
@media only screen and (max-width: 500px) {
.button {
width: 100% !important;
}
}
</style>
</head>
<body>
<table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table class="email-content" width="100%" cellpadding="0" cellspacing="0">
<!-- Logo -->
<tr>
<td class="email-masthead">
<a class="email-masthead_name">Authors Haven</a>
</td>
</tr>
<!-- Email Body -->
<tr>
<td class="email-body" width="100%">
<table class="email-body_inner" align="center" width="570" cellpadding="0" cellspacing="0">
<!-- Body content -->
<tr>
<td class="content-cell">
<h1>Engage with these Trending Articles</h1>
<p>Check out this new awesome article from ${name}.</p>
<!-- Action -->
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<div>
<!--[if mso]><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="{{action_url}}" style="height:45px;v-text-anchor:middle;width:200px;" arcsize="7%" stroke="f" fill="t">
<v:fill type="tile" color="#414EF9" />
<w:anchorlock/>
<center style="color:#ffffff;font-family:sans-serif;font-size:15px;">Verify Email</center>
</v:roundrect><![endif]-->
<a href="${link}" class="button button--blue">Read Article</a>
</div>
</td>
</tr>
</table>
<p>Thanks,<br>Fargo 38</p>
<!-- Sub copy -->
<table class="body-sub">
<tr>
<td>
<p class="sub">If you’re having trouble clicking the button, copy and paste the URL below into your web browser.
</p>
${link}
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0">
<tr>
<td class="content-cell">
<p class="sub center">
Authors Haven
<br>Sims@fargo-ah
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>`;
Loading

0 comments on commit dae573c

Please sign in to comment.