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

#161967011 Implements password reset #12

Merged
merged 1 commit into from
Dec 6, 2018

Conversation

gwako94
Copy link
Contributor

@gwako94 gwako94 commented Dec 5, 2018

What does this PR do?

Implements password reset using email

Description of Task to be completed?

Implements password reset using email
write tests for email reset

How should this be manually tested?

1. $ git clone https://github.com/andela/ah-jumanji.git
2. $ git checkout ft-reset-password-161967011
3. $ cd into ah-jumanji
4. $ virtualenv -p python3 venv
5. $ source venv/bin/activate
6. (venv) $ pip install -r requirements.txt
7. (venv) $ echo "DATABASE_URL=postgres://username:password@localhost/db_name" >> .env
8. (venv) $ python manage.py migrate
9. (venv) $ python manage.py runserver

Fire up Postman and test the following endpoints:

1: http://127.0.0.1:8000/api/users/reset_password

With the following payload:

{
    "email": "your-email"
}

Reset url will come with a token

2: http://127.0.0.1:8000/api/users/reset_password/<token>

With the following payload:

{
    "password": "new_password"
}

Any background context you want to provide?

What are the relevant pivotal tracker stories?

#161967011

Screenshots (if appropriate)

screenshot 2018-12-05 at 19 52 53

screenshot 2018-12-06 at 11 31 33

Questions:

Checklist:

  • My code follows the style guidelines of this project
  • At least 2 people have reviewed my PR
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • My PR has one commit.

user = instance.get_user(email=payload["email"])

password = request.data.get('password', None)
serializer = self.serializer_class(request.user, data=request.data, partial=True)

Choose a reason for hiding this comment

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

line too long (89 > 79 characters)

def put(self, request, token):
payload = jwt.decode(token, settings.SECRET_KEY)
user = instance.get_user(email=payload["email"])

Choose a reason for hiding this comment

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

blank line contains whitespace

msg.send()

return Response({"message": "A password reset email has been sent to your account!",
"url": reset_url}, status=status.HTTP_200_OK)

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent

msg.attach_alternative(html_content, "text/html")
msg.send()

return Response({"message": "A password reset email has been sent to your account!",

Choose a reason for hiding this comment

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

line too long (92 > 79 characters)

@@ -72,6 +72,13 @@

ROOT_URLCONF = 'authors.urls'

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'jumanjidevs32@gmail.com'
EMAIL_HOST_PASSWORD ='jumanji@32'

Choose a reason for hiding this comment

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

missing whitespace around operator

},
settings.SECRET_KEY, algorithm='HS256').decode()
return token

Choose a reason for hiding this comment

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

blank line at end of file
blank line contains whitespace

"exp": datetime.datetime.utcnow() + datetime.timedelta(minutes=720)
},
settings.SECRET_KEY, algorithm='HS256').decode()
return token

Choose a reason for hiding this comment

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

trailing whitespace

{
"email": email,
"iat": datetime.datetime.utcnow(),
"exp": datetime.datetime.utcnow() + datetime.timedelta(minutes=720)

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

@staticmethod
def generate_reset_token(email):
""" generates reset password token """

Choose a reason for hiding this comment

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

blank line contains whitespace

@@ -1,6 +1,9 @@
import datetime
import logging

import datetime
import logging

Choose a reason for hiding this comment

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

redefinition of unused 'logging' from line 2

@mashafrancis
Copy link
Contributor

The functionality works awesome. I have tested it. Good work.
Pending issues with our Hound barking to be fixed, then you'll be good.

@gwako94
Copy link
Contributor Author

gwako94 commented Dec 6, 2018

The functionality works awesome. I have tested it. Good work.
Pending issues with our Hound barking to be fixed, then you'll be good.

On it

Copy link
Contributor

@mashafrancis mashafrancis left a comment

Choose a reason for hiding this comment

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

Good work.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

This is ready to merge cc @mirr254

Copy link
Contributor

@EmmanuelBeja EmmanuelBeja left a comment

Choose a reason for hiding this comment

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

Nice work.

  - send a password reset email
  - update user password
[finishes #161967011]
Copy link
Contributor

@babbageLabs babbageLabs left a comment

Choose a reason for hiding this comment

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

The functionality is well implemented. However, your .gitignore has redundant entries for .vscode and .DS_store

@@ -24,6 +24,9 @@ var/
.installed.cfg
*.egg
.idea/
.DS_Store
Copy link
Contributor

Choose a reason for hiding this comment

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

.DS_Store and .vscode entries are redundant in .gitignore

@mirr254 mirr254 merged commit 8deb7e8 into develop Dec 6, 2018
@ghost ghost deleted the ft-reset-password-161967011 branch December 17, 2018 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants