Skip to content

Commit 526fd6a

Browse files
committed
make email confirmation fully optional #38
1 parent 1f97c05 commit 526fd6a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

rest_auth_toolkit/views.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class SignupView(generics.GenericAPIView):
3131
email confirmation instance using the ID and call the confirm
3232
method. To use a field that's not named 'id', define the setting
3333
email_confirmation_lookup_param (this will change the URL pattern).
34+
35+
If the setting is false, the user will be active immediately.
3436
"""
3537
authentication_classes = ()
3638
permission_classes = ()
@@ -48,13 +50,18 @@ def post(self, request):
4850
"""
4951
deserializer = self.get_serializer(data=request.data)
5052
deserializer.is_valid(raise_exception=True)
51-
user = deserializer.save()
5253

53-
if self.email_confirmation_class is None:
54-
raise MissingSetting('email_confirmation_string')
54+
confirm_email = get_setting('email_confirmation_send_email', True)
55+
56+
if not confirm_email:
57+
deserializer.save(is_active=True)
58+
else:
59+
user = deserializer.save()
60+
61+
if self.email_confirmation_class is None:
62+
raise MissingSetting('email_confirmation_class')
5563

56-
confirmation = self.email_confirmation_class.objects.create(user=user)
57-
if get_setting('email_confirmation_send_email', True):
64+
confirmation = self.email_confirmation_class.objects.create(user=user)
5865
email_field = user.get_email_field_name()
5966
send_email(request, user, getattr(user, email_field), confirmation)
6067

0 commit comments

Comments
 (0)