forked from github/plane
b6321438ce
* chore: update docker environment variables and compose file for better readability * dev: update single dockerfile * dev: update WEB_URL configuration * dev: move database settings to environment variable * chore: remove port configuration from default compose file * dev: update example env to add EMAIL_FROM and default values for AWS
35 lines
1006 B
Python
35 lines
1006 B
Python
# Django imports
|
|
from django.core.mail import EmailMultiAlternatives
|
|
from django.template.loader import render_to_string
|
|
from django.utils.html import strip_tags
|
|
from django.conf import settings
|
|
|
|
# Third party imports
|
|
from celery import shared_task
|
|
from sentry_sdk import capture_exception
|
|
|
|
|
|
@shared_task
|
|
def magic_link(email, key, token, current_site):
|
|
try:
|
|
realtivelink = f"/magic-sign-in/?password={token}&key={key}"
|
|
abs_url = current_site + realtivelink
|
|
|
|
from_email_string = settings.EMAIL_FROM
|
|
|
|
subject = f"Login for Plane"
|
|
|
|
context = {"magic_url": abs_url, "code": token}
|
|
|
|
html_content = render_to_string("emails/auth/magic_signin.html", context)
|
|
|
|
text_content = strip_tags(html_content)
|
|
|
|
msg = EmailMultiAlternatives(subject, text_content, from_email_string, [email])
|
|
msg.attach_alternative(html_content, "text/html")
|
|
msg.send()
|
|
return
|
|
except Exception as e:
|
|
capture_exception(e)
|
|
return
|