Skip to content

Commit

Permalink
make email confirmation fully optional #38
Browse files Browse the repository at this point in the history
  • Loading branch information
merwok committed Nov 7, 2018
1 parent 1f97c05 commit 526fd6a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions rest_auth_toolkit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class SignupView(generics.GenericAPIView):
email confirmation instance using the ID and call the confirm
method. To use a field that's not named 'id', define the setting
email_confirmation_lookup_param (this will change the URL pattern).
If the setting is false, the user will be active immediately.
"""
authentication_classes = ()
permission_classes = ()
Expand All @@ -48,13 +50,18 @@ def post(self, request):
"""
deserializer = self.get_serializer(data=request.data)
deserializer.is_valid(raise_exception=True)
user = deserializer.save()

if self.email_confirmation_class is None:
raise MissingSetting('email_confirmation_string')
confirm_email = get_setting('email_confirmation_send_email', True)

if not confirm_email:
deserializer.save(is_active=True)
else:
user = deserializer.save()

if self.email_confirmation_class is None:
raise MissingSetting('email_confirmation_class')

confirmation = self.email_confirmation_class.objects.create(user=user)
if get_setting('email_confirmation_send_email', True):
confirmation = self.email_confirmation_class.objects.create(user=user)
email_field = user.get_email_field_name()
send_email(request, user, getattr(user, email_field), confirmation)

Expand Down

0 comments on commit 526fd6a

Please sign in to comment.