Skip to content

Commit

Permalink
fix: Pass email string to send_email, not User (#7429)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamareebjamal authored Nov 11, 2020
1 parent 7b31448 commit da41414
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def reset_password_post():
link = make_frontend_url('/reset-password', {'token': user.reset_password})
if user.was_registered_with_order:
send_email(
to=user,
to=user.email,
action=PASSWORD_RESET_AND_VERIFY,
subject=MAILS[PASSWORD_RESET_AND_VERIFY]['subject'].format(
app_name=get_settings()['app_name']
Expand All @@ -354,7 +354,7 @@ def reset_password_post():

else:
send_email(
to=user,
to=user.email,
action=PASSWORD_RESET,
subject=MAILS[PASSWORD_RESET]['subject'].format(
app_name=get_settings()['app_name']
Expand Down Expand Up @@ -423,7 +423,7 @@ def change_password():
user.password = new_password
save_to_db(user)
send_email(
to=user,
to=user.email,
action=PASSWORD_CHANGE,
subject=MAILS[PASSWORD_CHANGE]['subject'].format(
app_name=get_settings()['app_name']
Expand Down
4 changes: 4 additions & 0 deletions app/api/helpers/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def send_email(to, action, subject, html, attachments=None, bcc=None):
"""
from .tasks import get_smtp_config, send_email_task_sendgrid, send_email_task_smtp

if isinstance(to, User):
logger.warning('to argument should be an email string, not a User object')
to = to.email

if string_empty(to):
logger.warning('Recipient cannot be empty')
return False
Expand Down
2 changes: 1 addition & 1 deletion app/api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def after_create_object(self, user, data, view_kwargs):
link = make_frontend_url('/verify', {'token': hash})
settings = get_settings()
send_email(
to=user,
to=user.email,
action=USER_REGISTER,
subject=MAILS[USER_REGISTER]['subject'].format(app_name=settings['app_name']),
html=render_template(
Expand Down

0 comments on commit da41414

Please sign in to comment.