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

#167730738 Build signup feature with token as response #30

Merged
merged 87 commits into from
Sep 12, 2019

Conversation

zanio
Copy link
Collaborator

@zanio zanio commented Sep 3, 2019

What does this PR do?

It Builds signup feature and provide token as response and also send email to newly signed up user for account verification. When User verifies his/her email the user table field ( isVerified) is updated to true

Description of Task to be completed?

N/A

How should this be manually tested?

Please Note: This is a follow up ticket to the ticket ft-email-verification-167730740

  1. git clone -b ft-signup-user-167730738 https://github.com/andela/firestar-backend.git .
  2. run npm install and create a .env file and provide the following information to it
DB_USERNAME=database username
DB_PASSWORD=database password
DB_NAME=name of database for development
DB_HOST=Host url
PORT=port number to listen for connections
DB_TEST_NAME=name of test database
JWT_SECRET=secret variable to sign and decode tokens
SECRET_KEY_SIGN_UP = choose any random character
EMAIL_VERIFY_TOKEN_SECRET_KEY = choose any random character
TOKENEXPIRY=18000
CLIENT_URL="https://firestar_backend.herokuapp.com"
YOUR_EMAIL="" (description: email to create test account and receive reset email link, must be able to access the email)

Please kindly make a reference to the file env.example for their description and the slack channel for this project for any env variable value

  1. Create two databases name in your postgres database ( barefoot and barefoot_test )

image

  1. Run npm run migrate:dev to create a user table. ** Note At any point in time you can drop this table by runing sequelize db:migrate:undo:all and run npm run seed:dev to seed some datas. The purpose for this is to make sure our roles table is filled with sample data

  2. start the server with npm run start:dev

  3. Now use postman and go to localhost:PORT/api/v1/users/auth/register using a POST request with a body of

body:{ 
email: 'youremail',//A valid email address, you would be sent verification link
firstName: 'Yourfirstname', // At least 3 characters long and less than 30
lastName: 'Yourlastname', // At least 3 characters long and less than 30
password: 'Strongpassword' // Password must be at least 8 character long, with at least an uppercase, lowercase, digit and special character
}

Screenshot (58)

Also feel free to use invalid details to see the different response on each error

  1. If successful you would see a response containing the token similar to the response of the screenshot on postman or the below response, also check your database to be sure it was added and isVerified is false
{
    "status": "success",
    "message": "user Added!",
    "data": {
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwiaWF0esoxNTY3NTUzMzg2fQ.JQe7CEY4okMlsQafEa3TSzqQ0-IpgdFq1v1NN75E8bg",
        "emailToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Im5vZGVkZXdldd5YWhvby5jb20iLCJpYXQiOjE1Njc1NTMzNzgsImV4cCI6MTU2NzYzOTc3OH0.20Pk4DbKGH_-quxsm26gLczauaeAZ7dxrMd3lzaQ044",
        "id": 4,
        "email": "nodedeweb@yahoo.com",
        "firstName": "Aniefiok",
        "lastName": "Akpan"
    }
}

Screenshot (59)

Observe as well that the the user table contain a field isVerified which checks if user is verified.

  1. Visit the email you provided and see the newly delivered email which contains your name and link to verify your account. Make sure your server is still ruining. Click on this email or copy full URL address
    Screenshot (60)

  2. make a get request with the copied link that looks like this http://localhost:PORT/api/v1/users/email/verify?id=token to verify your account

Screenshot (61)

  1. Use any GUI database tool to see your User table isVerified updated from false to true which indicates that your account has been verified. Also you can see the newly inserted data from logins table

  2. You can also decide to access other protected routes. to do this copy the token gotten during signup and use it in postman header as Authorization. An example of a protected route is http://localhost:PORT/api/v1/users/myaccount You can test it as well

Screenshot (63)

  1. To start using this feature on your own ticket all you have to do is call in two middleware named authorization and jwtVerify as shown on the screenshot

Screenshot (64)

Any background context you want to provide?

Please note that two token are used, In this feature.
token that is used as query string on verification link which also expires in 24hrs
User token upon signup which would be used as Authorization in header to access other protected route

What are the relevant pivotal tracker stories?

#167730738

Screenshots or gifs (if appropriate)

Test coverage information

image

Questions:

correct EMAIL_VERIFY_TOKEN_SECRET_KEY to SECRET_KEY_EMAIL_VERIFY_TOKEN in
firestar-backend/src/utils/index.js

@rovilay rovilay temporarily deployed to firestar-backend-staging-pr-30 September 3, 2019 14:25 Inactive
@zanio zanio added the work in progress This PR is still a work in progress. do not merge! label Sep 3, 2019
@rovilay rovilay temporarily deployed to firestar-backend-staging-pr-30 September 4, 2019 00:32 Inactive
@zanio zanio self-assigned this Sep 4, 2019
@zanio zanio added the peer Review This PR is up for team members reviews label Sep 4, 2019
@zanio zanio removed the work in progress This PR is still a work in progress. do not merge! label Sep 4, 2019
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 15:40 Failure
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 15:50 Failure
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 16:07 Failure
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 16:45 Failure
@OlawaleJoseph OlawaleJoseph temporarily deployed to firestar-backend-staging September 11, 2019 16:46 Inactive
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 17:03 Failure
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 17:10 Failure
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 17:18 Failure
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 17:20 Failure
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 17:23 Failure
@OlawaleJoseph OlawaleJoseph temporarily deployed to firestar-backend-staging September 11, 2019 17:33 Inactive
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 17:58 Failure
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 18:04 Failure
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 18:06 Failure
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 18:16 Failure
@rovilay rovilay had a problem deploying to firestar-backend-staging-pr-30 September 11, 2019 18:17 Failure
@OlawaleJoseph OlawaleJoseph temporarily deployed to firestar-backend-staging September 11, 2019 19:32 Inactive
@rovilay rovilay merged commit 8eac525 into stage Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for merge This PR is ready for TTL review and merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants