Skip to content

Commit

Permalink
bug-fix(redirection): user should be redirected to a front-end url up…
Browse files Browse the repository at this point in the history
…on successful or unsuccessfull email verification

[Starts #169697292]
  • Loading branch information
BAHATI Robben authored and BAHATI Robben committed Nov 12, 2019
1 parent 0c79fab commit 56599e6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
10 changes: 7 additions & 3 deletions src/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Users {
delete data.accountVerified;
delete data.createdAt;
delete data.updatedAt;
const link = `${req.protocol}://${process.env.baseUrl}/api/v1/auth/verify/?token=${token}`;
const link = `${process.env.FRONTEND_VERIFY_URL}/verify/?token=${token}`;
let verification;
try {
const header = Emails.header({
Expand Down Expand Up @@ -121,7 +121,7 @@ class Users {
}

const token = await SessionManager.generateToken(user);
const link = `${req.protocol}://${process.env.baseUrl}/api/v1/auth/verify/?token=${token}`;
const link = `${process.env.FRONTEND_VERIFY_URL}/verify/?token=${token}`;
try {
const header = Emails.header({
to: userEmail,
Expand Down Expand Up @@ -154,8 +154,12 @@ class Users {
return Response.conflictError(res, 'Email already verified');
}
const result = userService.updateUser({ userEmail }, { accountVerified: true });
const userExists = user.dataValues;
userExists.accountVerified = true;
const userToken = await SessionManager.createSession(userExists);
return Response.customResponse(res, 201, 'Email verified succesfully', {
userEmail
userEmail,
userToken
});
} catch (error) {
return next({ message: 'error.message', stack: error.stack, status: 401 });
Expand Down
4 changes: 2 additions & 2 deletions src/test/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ const invalidComment = {
const returnTripData = {
from: 'North, Rwanda',
to: 1,
travelDate: '2019-11-12',
returnDate: '2019-11-20',
travelDate: '2020-11-12',
returnDate: '2020-11-20',
reason:
'iam travelling cause the company allows us to, i mean the company finances everything so why not',
accommodation: 'hotel',
Expand Down
3 changes: 1 addition & 2 deletions src/test/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ describe('Search Requests', () => {
it('search request by return Date', (done) => {
chai
.request(server)
.get(`${searchUrl}?returnDate=2019/11/20`)
.get(`${searchUrl}?returnDate=2020/11/20`)
.set('Authorization', `Bearer ${managerToken}`)
.end((_err, res) => {
if (_err) return done(_err);

expect(res).to.have.status(200);

expect(res.body.data.length).to.greaterThan(0);
Expand Down
33 changes: 13 additions & 20 deletions src/utils/mails/verify.email.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,19 @@ class VerifyEmail {
*/
static verificationLinkTemplate(url, user) {
const html = `<body style="margin: 0; padding: 0;">
<table border="0" cellpadding="0" cellspacing="0" width="900px" style="padding: 0 40px 0 40px; background-color:#f1f2f3;">
<tr><td align="center" style="background-color:#f9fcff; margin: 0 50px 0 50px;">
<a><img src="https://ci4.googleusercontent.com/proxy/yjFsndsERdnbRVXug6SlYieFt7eoDHpfBlnrAW-QgWtkqx__KDBeK8_s867XanT0jagLBDSwRtOoLuB56-PYcZ6oIPtCus2oJa-QQNkssZK6JaH5PTcOsfqvU_pG0w=s0-d-e1-ft#http://drive.google.com/uc?export=view&id=1Rraew69PkllzCnb5wIBJsw61xPk83sA-
" alt="Bare Foot Nomad" width="120" height="100" style="display: block;></a></td>
</tr><tr><td align = "center" style="padding: 0 50px 0 50px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color:#ffffff; padding: 0 0 0 20px;">
<tr><td align="center" style="font-family: Arial, sans-serif; font-size: 24px; color: #050505;">
<p>Hi ${user.firstName},</p></td></tr><tr>
<td align="center" style="color: #153643; font-family: Arial, sans-serif; font-size: 16px; line-height: 20px;">
<p>We need to verify your email address before you continue using your barefoot Nomad account</p>
</td></tr><tr>td align="center">
<a style="width:250px; display:inline-block; text-decoration: none; font-size: 15px;text-align: center;
background-color:#55acee;border-radius:2px;color:white;height:32px; cursor: pointer; padding-top:5px"
href=${url}>Verify Email</a></td></tr>
<tr><td align="center" style="color: #153643; font-family: Arial, sans-serif; font-size: 16px; line-height: 20px;">
<p>this link will expire after 1 hour.</p>
<p>contact <a href=#>Support@barefoot</a> if you didnt intiate this request</p>
<p>Thank you for using Bare Foot Nomad</p></td></tr></table>/td></tr><tr>
<td align="center" style="padding: 30px 30px 30px 30px;">&reg; BARE FOOT NOMAD, 2019<br/>
</td></tr></table></body>`;
<table border="0" cellpadding="0" cellspacing="0" width="900px" style="padding: 0 40px 0 40px; background-color:#f1f2f3;">
<tr><td align="center" style="background-color:#f9fcff; margin: 0 50px 0 50px;">
<a><img src="https://ci4.googleusercontent.com/proxy/yjFsndsERdnbRVXug6SlYieFt7eoDHpfBlnrAW-QgWtkqx__KDBeK8_s867XanT0jagLBDSwRtOoLuB56-PYcZ6oIPtCus2oJa-QQNkssZK6JaH5PTcOsfqvU_pG0w=s0-d-e1-ft#http://drive.google.com/uc?export=view&id=1Rraew69PkllzCnb5wIBJsw61xPk83sA-
" alt="Bare Foot Nomad"width="120" height="100" style="display: block;></a></td>
</tr><tr><td align = "center" style="padding: 0 50px 0 50px;"><table border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color:#ffffff; padding: 0 0 0 20px;">
<tr><td align="center" style="font-family: Arial, sans-serif; font-size: 24px; color: #050505;"> <p>Hi ${user.firstName},</p>
</td></tr> <tr><td align="center" style="color: #153643; font-family: Arial, sans-serif; font-size: 16px; line-height: 20px;">
<p>We need to verify your email address before you continue using your barefoot Nomad account</p></td></tr> <tr><td align="center">
<a style="width:250px; display:inline-block; text-decoration: none; font-size: 15px;text-align: center;
background-color:#55acee;border-radius:2px;color:white;height:32px; cursor: pointer; padding-top:5px" href=${url}>Verify Email</a>
</td></tr><tr><td align="center" style="color: #153643; font-family: Arial, sans-serif; font-size: 16px; line-height: 20px;"><p>this link will expire after 1 hour.</p>
<p>contact <a href=#>Support@barefoot</a> if you didnt intiate this request</p><p>Thank you for using Bare Foot Nomad</p></td></tr></table></td></tr><tr><td align="center" style="padding: 30px 30px 30px 30px;">
&reg; BARE FOOT NOMAD, 2019<br/></td></tr></table></body>`;
return { html };
}
}
Expand Down

0 comments on commit 56599e6

Please sign in to comment.