From 526fd6a7cb290f964012b3d8fbca6a21edd70934 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 e6d43a3..6275a2a 100644 --- a/rest_auth_toolkit/views.py +++ b/rest_auth_toolkit/views.py @@ -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 = () @@ -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)