-
Notifications
You must be signed in to change notification settings - Fork 459
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
base: master
Are you sure you want to change the base?
Reregistration Flows #215
Conversation
…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
There was a problem hiding this 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, |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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')) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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 %} |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… 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
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 |
@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. |
@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. |
Changes to address #213
REREGISTRATION_SHOW_RESPONSE
If
False
(default), the/register/
endpoint will always returna
HTTP_201_CREATED
response, as well as the UserSerializer serializer.data responseof 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.