Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Pass email string to send_email, not User #7429

Merged
merged 1 commit into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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