Skip to content

Commit

Permalink
add case with no form and only User object.
Browse files Browse the repository at this point in the history
added this case because some django backends are not supporting native forms and could be used only as REST API's. My change does not change anything in the current functionality of the project, just extends it.
  • Loading branch information
Nick Koutroumpinis committed Aug 3, 2022
1 parent e9a8056 commit a960b57
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions verify_email/email_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ def __send_email(self, msg, useremail):
)

# Public :
def send_verification_link(self, request, form):
inactive_user = form.save(commit=False)
def send_verification_link(self, request, inactive_user=None, form=None):

if form:
inactive_user = form.save(commit=False)

inactive_user.is_active = False
inactive_user.save()

try:
useremail = form.cleaned_data.get(self.settings.get('email_field_name'))

useremail = form.cleaned_data.get(self.settings.get('email_field_name')) if form else user.email
if not useremail:
raise KeyError(
'No key named "email" in your form. Your field should be named as email in form OR set a variable'
Expand Down

0 comments on commit a960b57

Please sign in to comment.