Skip to content

Commit

Permalink
fix: update email workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
GareArc committed Dec 26, 2024
1 parent e127283 commit ae0aee5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 31 deletions.
2 changes: 1 addition & 1 deletion api/controllers/console/workspace/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def get(self):
account = current_user

token, code = AccountService.generate_account_deletion_verification_code(account)
AccountService.send_account_delete_verification_email(account, code)
AccountService.send_account_deletion_verification_email(account, code)

return {"result": "success", "data": token}

Expand Down
9 changes: 2 additions & 7 deletions api/services/account_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@ def generate_account_deletion_verification_code(account: Account) -> tuple[str,

@classmethod
def send_account_deletion_verification_email(cls, account: Account, code: str):
language, email = account.interface_language, account.email
email = account.email
if cls.email_code_account_deletion_rate_limiter.is_rate_limited(email):
from controllers.console.auth.error import EmailCodeAccountDeletionRateLimitExceededError

raise EmailCodeAccountDeletionRateLimitExceededError()

send_account_deletion_verification_code.delay(language=language, to=email, code=code)
send_account_deletion_verification_code.delay(to=email, code=code)

cls.email_code_account_deletion_rate_limiter.increment_rate_limit(email)

Expand Down Expand Up @@ -423,11 +423,6 @@ def revoke_reset_password_token(cls, token: str):
def get_reset_password_data(cls, token: str) -> Optional[dict[str, Any]]:
return TokenManager.get_token_data(token, "reset_password")

@classmethod
def send_account_delete_verification_email(cls, account: Account, code: str):
language, email = account.interface_language, account.email
send_account_deletion_verification_code.delay(language=language, to=email, code=code)

@classmethod
def send_email_code_login_email(
cls, account: Optional[Account] = None, email: Optional[str] = None, language: Optional[str] = "en-US"
Expand Down
2 changes: 1 addition & 1 deletion api/tasks/delete_account_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ def delete_account_task(account_id):
logger.error(f"Account {account_id} not found.")
return
# send success email
send_deletion_success_task.delay(account.interface_language, account.email)
send_deletion_success_task.delay(account.email)
32 changes: 10 additions & 22 deletions api/tasks/mail_account_deletion_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@shared_task(queue="mail")
def send_deletion_success_task(language, to):
def send_deletion_success_task(to):
"""Send email to user regarding account deletion.
Args:
Expand All @@ -22,20 +22,12 @@ def send_deletion_success_task(language, to):
start_at = time.perf_counter()

try:
if language == "zh-Hans":
html_content = render_template(
"delete_account_success_template_zh-CN.html",
to=to,
email=to,
)
mail.send(to=to, subject="Dify 账户删除成功", html=html_content)
else:
html_content = render_template(
"delete_account_success_template_en-US.html",
to=to,
email=to,
)
mail.send(to=to, subject="Dify Account Deleted", html=html_content)
html_content = render_template(
"delete_account_success_template_en-US.html",
to=to,
email=to,
)
mail.send(to=to, subject="Your Dify.AI Account Has Been Successfully Deleted", html=html_content)

end_at = time.perf_counter()
logging.info(
Expand All @@ -48,7 +40,7 @@ def send_deletion_success_task(language, to):


@shared_task(queue="mail")
def send_account_deletion_verification_code(language, to, code):
def send_account_deletion_verification_code(to, code):
"""Send email to user regarding account deletion verification code.
Args:
Expand All @@ -62,12 +54,8 @@ def send_account_deletion_verification_code(language, to, code):
start_at = time.perf_counter()

try:
if language == "zh-Hans":
html_content = render_template("delete_account_code_email_template_zh-CN.html", to=to, code=code)
mail.send(to=to, subject="Dify 的删除账户验证码", html=html_content)
else:
html_content = render_template("delete_account_code_email_en-US.html", to=to, code=code)
mail.send(to=to, subject="Delete Your Dify Account", html=html_content)
html_content = render_template("delete_account_code_email_template_en-US.html", to=to, code=code)
mail.send(to=to, subject="Dify.AI Account Deletion and Verification", html=html_content)

end_at = time.perf_counter()
logging.info(
Expand Down

0 comments on commit ae0aee5

Please sign in to comment.