From 888578dd4b5ef245cccecd5c715b27351da588b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Wed, 17 Oct 2018 21:32:42 -0400 Subject: [PATCH] make email confirmation fully optional #38 --- rest_auth_toolkit/views.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/rest_auth_toolkit/views.py b/rest_auth_toolkit/views.py index 51daf29..72cf8ce 100644 --- a/rest_auth_toolkit/views.py +++ b/rest_auth_toolkit/views.py @@ -43,16 +43,23 @@ def post(self, request): 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. """ 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)