Skip to content

Commit

Permalink
Address a few requests in PR : Rename REREGISTRATION_SHOW_RESPONSE to…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
oliver-zhou committed Jul 21, 2017
1 parent 12ef654 commit 9a1e5d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions djoser/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'USE_HTML_EMAIL_TEMPLATES': False,
'SEND_ACTIVATION_EMAIL': False,
'SEND_CONFIRMATION_EMAIL': False,
'SEND_REREGISTRATION_EMAIL': False,
'RESEND_REGISTRATION_EMAIL': False,
'SET_PASSWORD_RETYPE': False,
'SET_USERNAME_RETYPE': False,
'PASSWORD_RESET_CONFIRM_RETYPE': False,
Expand All @@ -39,7 +39,7 @@
},
'LOGOUT_ON_PASSWORD_CHANGE': False,
'USER_EMAIL_FIELD_NAME': 'email',
'REREGISTRATION_SHOW_RESPONSE': True,
'REGISTRATION_SHOW_EMAIL_FOUND': True,
}

SETTINGS_TO_IMPORT = ['TOKEN_MODEL']
Expand Down
13 changes: 7 additions & 6 deletions djoser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ class RegistrationView(generics.CreateAPIView):

def create(self, request, *args, **kwargs):
try:
email_users = self.get_email_users(request.data.get('email'))
for user in email_users:
email_field_name = get_user_email_field_name(User)
users = self.get_email_users(request.data.get(email_field_name))
for user in users:
serializer = self.get_serializer(instance=user)
if settings.SEND_REREGISTRATION_EMAIL:
self.send_reregistration_email(user)
if settings.RESEND_REGISTRATION_EMAIL:
self.resend_registration_email(user)
headers = self.get_success_headers(serializer.data)
if not settings.REREGISTRATION_SHOW_RESPONSE and email_users:
if not settings.REGISTRATION_SHOW_EMAIL_FOUND and users:
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
except User.DoesNotExist:
pass
Expand Down Expand Up @@ -95,7 +96,7 @@ def send_confirmation_email(self, user):
email = email_factory.create()
email.send()

def send_reregistration_email(self, user):
def resend_registration_email(self, user):
if user.is_active:
email_factory = utils.UserReregistrationEmailFactory.from_request(
self.request, user=user
Expand Down
6 changes: 3 additions & 3 deletions docs/source/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ If ``True``, register or activation endpoint will send confirmation email to use

**Default**: ``False``

SEND_REREGISTRATION_EMAIL
RESEND_REGISTRATION_EMAIL
-------------------------

If ``True``, register endpoint will send warning and reminder email to user.
Expand All @@ -67,10 +67,10 @@ If User.is_active is False, will send a warning

**Default**: ``False``

REREGISTRATION_SHOW_RESPONSE
REGISTRATION_SHOW_EMAIL_FOUND
----------------------------

If ``False`` (default), the ``/register/`` endpoint will always return
If ``True`` (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

Expand Down

0 comments on commit 9a1e5d7

Please sign in to comment.