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

Reregistration Flows #215

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

oliver-zhou
Copy link
Contributor

Changes to address #213

REREGISTRATION_SHOW_RESPONSE

If False (default), the /register/ endpoint will always return
a HTTP_201_CREATED response, as well as the UserSerializer serializer.data response
of one of those users, so that it makes it difficult to distinguish if a User has this email

Default: True

SEND_REREGISTRATION_EMAIL

If True, register endpoint will send warning and reminder email to user.
Only active users are able to reset their passwords (User.is_active is True).
The email will ask the User to reset their password since someone is trying to
re-register their account.
If User.is_active is False, will send a warning

Default: False

Reregistration Email is also different - if the User is_active or not, they will either have the option to reset password or will be reminded to complete activation.

…esponse, UserReregistrationEmailFactory, override RegistrationView.create(), add RegistrationView.send_reregistration_email()
… either is_active or not, also allow for all combinations of settings.REREGISTRATION_SHOW_RESPONSE and settings.SEND_REREGISTRATION_EMAIL
@coveralls
Copy link

coveralls commented Jul 12, 2017

Coverage Status

Coverage decreased (-3.7%) to 93.069% when pulling b3c694c on oliver-zhou:reregistration into 1ffeb41 on sunscrapers:master.

@coveralls
Copy link

coveralls commented Jul 12, 2017

Coverage Status

Coverage decreased (-3.7%) to 93.069% when pulling 12ef654 on oliver-zhou:reregistration into 1ffeb41 on sunscrapers:master.

Copy link
Contributor

@pszpetkowski pszpetkowski left a comment

Choose a reason for hiding this comment

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

I'd like to introduce few changes to this PR. Also it would be nice to have some tests, since you are bringing new features.

djoser/conf.py Outdated
@@ -15,6 +15,7 @@
'USE_HTML_EMAIL_TEMPLATES': False,
'SEND_ACTIVATION_EMAIL': False,
'SEND_CONFIRMATION_EMAIL': False,
'SEND_REREGISTRATION_EMAIL': False,
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about calling it RESEND_REGISTRATION_EMAIL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds fine to me - will try to keep nouns consistent and modify the verbs if it pops up elsewhere as well.

djoser/conf.py Outdated
@@ -38,6 +39,7 @@
},
'LOGOUT_ON_PASSWORD_CHANGE': False,
'USER_EMAIL_FIELD_NAME': 'email',
'REREGISTRATION_SHOW_RESPONSE': True,
Copy link
Contributor

Choose a reason for hiding this comment

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

Documentation states that the default is False however you have provided True as a default.

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 had it mixed up in what I wrote for the docs : the Default was set to True, but in-line the description was False. Fixing the docs to match.

except User.DoesNotExist:
pass
response = super(RegistrationView, self).create(request, *args, **kwargs)
return response
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be simplified into one line:

return super(RegistrationView, self).create(request, *args, **kwargs)

djoser/views.py Outdated

def create(self, request, *args, **kwargs):
try:
email_users = self.get_email_users(request.data.get('email'))
Copy link
Contributor

Choose a reason for hiding this comment

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

The field does not necessarily needs to be called email.

djoser/views.py Outdated
@@ -79,6 +95,28 @@ def send_confirmation_email(self, user):
email = email_factory.create()
email.send()

def send_reregistration_email(self, user):
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, how about calling it resend_registration_email?


<p>{% blocktrans %}The {{ site_name }} team{% endblocktrans %}</p>
</body></html>
{% endautoescape %}
Copy link
Contributor

Choose a reason for hiding this comment

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

This template as well as djoser/templates/reregistration_inactive_email_body.txt could be merged with djoser/templates/reregistration_email_body.[html|txt] and you could simply use the if statement controlled by context variable.

djoser/conf.py Outdated
@@ -38,6 +39,7 @@
},
'LOGOUT_ON_PASSWORD_CHANGE': False,
'USER_EMAIL_FIELD_NAME': 'email',
'REREGISTRATION_SHOW_RESPONSE': True,
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, to keep it consistent I would rather call it REGISTRATION_SHOW_EMAIL_FOUND.

Only active users are able to reset their passwords (User.is_active is True).
The email will ask the User to reset their password since someone is trying to
re-register their account.
If User.is_active is False, will send a warning
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of code values are decorated with higlight like ``True``, but it seems that you have forgot about the others.

if not settings.REREGISTRATION_SHOW_RESPONSE and email_users:
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
except User.DoesNotExist:
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if this try ... except ... block could not be replaced with some smart if statement, since you are not doing anything with the exception.


<p>{% blocktrans %}The {{ site_name }} team{% endblocktrans %}</p>
</body></html>
{% endautoescape %}
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, wouldn't we prefer to resend activation email in case of such API call? Emails tend to (rarely) get lost e.g. temporary mail server downtime.

It might be a good idea to have a discussion on that @haxoza @KaczuH

… REGISTRATION_SHOW_EMAIL_FOUND, use "get_email_field_name" to properly find the User model's email field, rename SEND_REREGISTRATION_EMAIL to RESEND_REGISTRATION_EMAIL
@coveralls
Copy link

coveralls commented Jul 21, 2017

Coverage Status

Coverage decreased (-3.6%) to 93.083% when pulling 9a1e5d7 on oliver-zhou:reregistration into 1ffeb41 on sunscrapers:master.

@oliver-zhou
Copy link
Contributor Author

oliver-zhou commented May 15, 2018

I have some time to revisit this pull request, and bring this up to speed with Djoser 1.15 - before I spend the investment - what are the plans for the branches in development right now? If I'm working off 1.15, will it be future resistant - or should I wait for 2.0? @piotr-szpetkowski

@zefciu
Copy link
Contributor

zefciu commented Jan 24, 2019

@oliver-zhou It would be great to pull this into 1.0 branch. The 2.0 needs to be refactored so there is no point in waiting with it.

@dekoza
Copy link
Contributor

dekoza commented Jul 23, 2019

@oliver-zhou Sorry for such long delay with this PR. Do you feel it is suitable for version 2.0 that was released recently? I'd like to revisit this feature request.

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.

5 participants