Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#167484585 implemented email verification link approach #14

Merged
merged 5 commits into from
Aug 11, 2019

Conversation

placideirandora
Copy link
Contributor

@placideirandora placideirandora commented Aug 8, 2019

What does this PR do?

It implements the approach of sending an email verification link to the user upon a successful registration.

Description of Task to be done?

  1. Adding a helper for sending emails.
  2. Using the helper in the user controller to pass required information for sending an email.
  3. Modifying the message property to include a message for notifying the user to check their email for the verification link.
  4. Adding a route for verifying the email verification link.
  5. Changing the status of a user from inactive to active after verifying their email address.

Screenshots

Screen Shot 2019-08-08 at 14 19 30

Screen Shot 2019-08-10 at 18 08 37

Screen Shot 2019-08-10 at 18 10 50

Screen Shot 2019-08-10 at 18 31 10

How should this be manually tested?

  1. Create an account on sendgrid.com
  2. Create an API key for sending emails on www.sendgrid.com.
  3. Update your .env file with the following: SENDGRID_API_KEY=putthekeyhere, EMAIL_SENDER=no-reply@authorshaven.com, APP_URL=localhost.
  4. Clone this branch.
  5. Do npm install.
  6. Register a new user and after successful registration, Check your email for a verification link. If you do not get it your inbox, check your spam folder. It should be there!
  7. Copy the link and paste it in Postman and check for the verification confirmation link.

@@ -0,0 +1,45 @@
import dotenv from 'dotenv';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@raymond42 raymond42 temporarily deployed to codinggeeks-ah-backnd-st-pr-14 August 8, 2019 12:24 Inactive
@placideirandora placideirandora added the Need Reviews Feedback to PR raised label Aug 8, 2019
@raymond42 raymond42 temporarily deployed to codinggeeks-ah-backnd-st-pr-14 August 8, 2019 12:33 Inactive
Copy link
Contributor

@malaba6 malaba6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about you Placide, but I've tested this on my pc and it's not sending me a verification email. I used my two email addresses, and none has sent. Any reason why this is happening?

@placideirandora
Copy link
Contributor Author

I don't know about you Placide, but I've tested this on my pc and it's not sending me a verification email. I used my two email addresses, and none has sent. Any reason why this is happening?

If you don't get the email in your inbox. You should check your Spam folder. It should be there!

@malaba6
Copy link
Contributor

malaba6 commented Aug 8, 2019

I don't know about you Placide, but I've tested this on my pc and it's not sending me a verification email. I used my two email addresses, and none has sent. Any reason why this is happening?

If you don't get the email in your inbox. You should check your Spam folder. It should be there!

I don't know about you Placide, but I've tested this on my pc and it's not sending me a verification email. I used my two email addresses, and none has sent. Any reason why this is happening?

If you don't get the email in your inbox. You should check your Spam folder. It should be there!

I have and there is nothing there. Actually this is the error it's throwing after creating the user
Screen Shot 2019-08-08 at 17 08 49

@placideirandora
Copy link
Contributor Author

I don't know about you Placide, but I've tested this on my pc and it's not sending me a verification email. I used my two email addresses, and none has sent. Any reason why this is happening?

If you don't get the email in your inbox. You should check your Spam folder. It should be there!

I don't know about you Placide, but I've tested this on my pc and it's not sending me a verification email. I used my two email addresses, and none has sent. Any reason why this is happening?

If you don't get the email in your inbox. You should check your Spam folder. It should be there!

I have and there is nothing there. Actually, this is the error it's throwing after creating the user
Screen Shot 2019-08-08 at 17 08 49

That is because you are not using a SendGrid API key. You should create an account on sendgrid.com and create an API key as well. Then, you will use the key in your .env file.

@malaba6
Copy link
Contributor

malaba6 commented Aug 8, 2019

I don't know about you Placide, but I've tested this on my pc and it's not sending me a verification email. I used my two email addresses, and none has sent. Any reason why this is happening?

If you don't get the email in your inbox. You should check your Spam folder. It should be there!

I don't know about you Placide, but I've tested this on my pc and it's not sending me a verification email. I used my two email addresses, and none has sent. Any reason why this is happening?

If you don't get the email in your inbox. You should check your Spam folder. It should be there!

I have and there is nothing there. Actually, this is the error it's throwing after creating the user
Screen Shot 2019-08-08 at 17 08 49

That is because you are not using a SendGrid API key. You should create an account on sendgrid.com and create an API key as well. Then, you will use the key in your .env file.

Could you please include that and the Environment variable in the PR as suggested by @mkiterian earlier?

@placideirandora
Copy link
Contributor Author

I don't know about you Placide, but I've tested this on my pc and it's not sending me a verification email. I used my two email addresses, and none has sent. Any reason why this is happening?

If you don't get the email in your inbox. You should check your Spam folder. It should be there!

I don't know about you Placide, but I've tested this on my pc and it's not sending me a verification email. I used my two email addresses, and none has sent. Any reason why this is happening?

If you don't get the email in your inbox. You should check your Spam folder. It should be there!

I have and there is nothing there. Actually, this is the error it's throwing after creating the user
Screen Shot 2019-08-08 at 17 08 49

That is because you are not using a SendGrid API key. You should create an account on sendgrid.com and create an API key as well. Then, you will use the key in your .env file.

Could you please include that and the Environment variable in the PR as suggested by @mkiterian earlier?

Yes, I have done that!

Copy link
Collaborator

@raymond42 raymond42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, I think It's not necessary to put postman when sending a verification email. Because somebody maybe using another API testing app or browser extension like Restman and still works.

@placideirandora
Copy link
Contributor Author

In my opinion, I think It's not necessary to put postman when sending a verification email. Because somebody maybe using another API testing app or browser extension like Restman and still works.

Thank you for mentioning that! I'm gonna remove Postman.

mailer.send(message);
}
};
// eslint-disable-next-line import/prefer-default-export
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why disable this eslint rule?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, When I used export default, the function didn't get detected. But, I have improved the way I use it in the user controller and it is working. So, I can re-enable the rule.

.env.sample Outdated
@@ -6,3 +6,6 @@ DB_NAME_TEST=
DB_PORT=
DATABASE_URL=
SECRET_KEY=
SENDGRID_API_KEY =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the spaces preceding the =

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I have removed the free spaces in .env.sample.

from: EMAIL_SENDER,
subject: subjectVerify,
text: 'Authors Haven',
html: `<div style="background:#ECF0F1;width:100%;padding:20px 0;">
Copy link
Contributor

@mkiterian mkiterian Aug 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd much rather this markup string is generated by a function e.g createEmailTemplate(contentVerify, linkVerify) and used here. Would make it much cleaner

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I'm going to implement that approach. It is really good.

return message;
};

export default createEmailTemplate;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@raymond42 raymond42 temporarily deployed to codinggeeks-ah-backnd-st-pr-14 August 9, 2019 10:30 Inactive
@raymond42 raymond42 temporarily deployed to codinggeeks-ah-backnd-st-pr-14 August 9, 2019 10:49 Inactive
@raymond42 raymond42 temporarily deployed to codinggeeks-ah-backnd-st-pr-14 August 10, 2019 15:41 Inactive
@@ -1,20 +1,31 @@
import dotenv from 'dotenv';
import { config } from 'dotenv';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@@ -0,0 +1,15 @@
import { User } from '../sequelize/models/index';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@raymond42 raymond42 temporarily deployed to codinggeeks-ah-backnd-st-pr-14 August 10, 2019 16:36 Inactive
src/config/config.js Show resolved Hide resolved
@@ -33,6 +33,11 @@ export default (sequelize, DataTypes) => {
type: DataTypes.STRING,
defaultValue: 'user',
},
status: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a boolean field since we expect it to only have two states. You can name it either active/verified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented that.

@@ -0,0 +1,15 @@
import { User } from '../sequelize/models/index';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be part of the userController

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse me... You mean the whole code inside the verifyEmail.js file, should be inside the userController.js file? Or, that single line of importing from sequelize should be inside the userController?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the whole code inside the verifyEmail.js file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

@raymond42 raymond42 temporarily deployed to codinggeeks-ah-backnd-st-pr-14 August 11, 2019 12:46 Inactive
@@ -11,6 +11,7 @@ config();
*/
class Authentication {
/**
* Eric MALABA & Placide IRANDORA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for?

Copy link
Contributor Author

@placideirandora placideirandora Aug 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! It should be @author Eric MALABA & Placide IRANDORA. I tried to indicate the developers who worked on that method/function. But, I'm gonna removed it if it is not necessary.

@@ -84,7 +103,7 @@ class Authentication {
}

/**
*
* @author Carlos HARERIMANA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay!

@@ -60,6 +61,24 @@ class Authentication {
}

/**
* @author Placide IRANDORA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove @author

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay!

@@ -33,6 +33,11 @@ export default (sequelize, DataTypes) => {
type: DataTypes.STRING,
defaultValue: 'user',
},
verified: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the datatype should be DataTypes.BOOLEAN. We expect a user to either be verified or not. A True vs False value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna implement that.

@raymond42 raymond42 temporarily deployed to codinggeeks-ah-backnd-st-pr-14 August 11, 2019 13:05 Inactive
@raymond42 raymond42 temporarily deployed to codinggeeks-ah-backnd-st-pr-14 August 11, 2019 13:34 Inactive
@@ -6,6 +6,7 @@ import verifyToken from '../middleware/verifyToken';
const router = express.Router();

router.post('/api/v1/users', Validation.signupValidation, UserAuth.signup);
router.post('/api/v1/verify-email/:token', verifyToken, UserAuth.verifyEmail);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a GET route

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I'm gonna implement that.

@raymond42 raymond42 temporarily deployed to codinggeeks-ah-backnd-st-pr-14 August 11, 2019 14:09 Inactive
Copy link
Contributor

@mkiterian mkiterian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@mkiterian mkiterian merged commit 2393369 into development Aug 11, 2019
@placideirandora placideirandora added finished and removed Need Reviews Feedback to PR raised labels Aug 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants