Compare commits

...

5 Commits

Author SHA1 Message Date
Aravinth Manivannan 59c1034b93
fix: s/EMAIL_SENDER_ADDRESS/DEFAULT_FROM_EMAIL/
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/pr/woodpecker Pipeline failed Details
2022-07-04 18:26:24 +05:30
Aravinth Manivannan 5f77bbe75a
feat: Gitea root creds email with nicer content
ci/woodpecker/push/woodpecker Pipeline failed Details
ci/woodpecker/pr/woodpecker Pipeline failed Details
2022-07-04 14:57:50 +05:30
Aravinth Manivannan 2c0a010f5a
feat: instance created notification email template with nicer body 2022-07-04 14:57:34 +05:30
Aravinth Manivannan d49b9cb50f
feat: verification link email template with polished email body 2022-07-04 14:56:14 +05:30
Aravinth Manivannan b71f25545b
feat: add EMAIL_SENDER_ADDRESS to settings.py 2022-07-04 14:55:46 +05:30
9 changed files with 86 additions and 29 deletions

View File

@ -0,0 +1,9 @@
Hello {{ username }},
Please click on the link below to verify your email.
{{ link }}
If you don't recognise this activity, please delete this mail.
Cheers,
Hostea team

View File

@ -17,6 +17,7 @@ from datetime import datetime, timezone
from django.utils.crypto import get_random_string
from django.core.mail import send_mail
from django.shortcuts import redirect
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.http import urlencode
from django.conf import settings
@ -34,12 +35,24 @@ def send_verification_email(request, challenge):
f"{request.scheme}://{request.get_host()}{challenge.verification_link()}"
)
ctx = {
"link": verification_link,
"username": challenge.owned_by.username,
}
body = render_to_string(
"accounts/emails/verification-link.txt",
context=ctx,
)
email = challenge.owned_by.email
sender = settings.DEFAULT_FROM_EMAIL
send_mail(
subject="[Hostea] Please confirm your email address",
message=f"Please confirm your email address {email}.\n {verification_link}",
from_email="No reply Hostea<no-reply@exampl.org>", # TODO read from settings.py
message=body,
from_email=f"No reply Hostea<{sender}>", # TODO read from settings.py
recipient_list=[email],
)

View File

@ -85,6 +85,7 @@ HOSTEA = {
# Please see EMAIL_* configuration options:
# https://docs.djangoproject.com/en/4.1/ref/settings/#email-host
EMAIL_CONFIG = env.email("EMAIL_URL", default="smtp://admin:password@localhost:10025")
DEFAULT_FROM_EMAIL = "no-reply@hostea.org"
vars().update(EMAIL_CONFIG)

View File

@ -87,3 +87,4 @@ EMAIL_USE_SSL = False
EMAIL_PORT = 10025
EMAIL_HOST_USER = "admin"
EMAIL_HOST_PASSWORD = "password"
DEFAULT_FROM_EMAIL = "no-reply@hostea.org"

View File

@ -203,6 +203,7 @@ EMAIL_USE_SSL = False
EMAIL_PORT = 10025
EMAIL_HOST_USER = "admin"
EMAIL_HOST_PASSWORD = "password"
DEFAULT_FROM_EMAIL: "no-reply@hostea.org"
try:
from dashboard.local_settings import *

View File

@ -0,0 +1,15 @@
Hello {{ username }},
Congratulations on your new Gitea instance!
You can use the following credentials to log into an admin account on
your new Gitea instance. Great powers come with great responsibilities,
so use the admin credentials wisely. When in doubt, consult the Gitea
docs or contact support!
- username : root
- password: {{ gitea_password }}
- Gitea {{ gitea_uri }}
Cheers,
Hostea team

View File

@ -0,0 +1,11 @@
Hello {{ username }}!,
The deployment job has run to completion and your Hostea instance is now online!
Credentials to admin account was sent in an earlier email, please contact
support if didn't receive it.
Gitea: {{ gitea_uri }}
Woodpecker CI: {{ woodpecker_uri }}
Cheers,
Hostea team

View File

@ -53,19 +53,23 @@ class Worker(Thread):
job = self.job
self.job = None
email = job.instance.owned_by.email
ctx = {
"gitea_uri": gitea_uri,
"woodpecker_uri": woodpecker,
"username": job.instance.owned_by.username,
}
body = render_to_string(
"infrastructure/emails/instance-created.txt",
context=ctx,
)
sender = settings.DEFAULT_FROM_EMAIL
send_mail(
subject="[Hostea] Your Hostea instance is now online!",
message=f"""
Hello,
The deployment job has run to completion and your Hostea instance is now online!
Credentials to admin account was sent in an earlier email, please contact
support if didn't receive it.
Gitea: {gitea_uri}
Woodpecker CI: {woodpecker}
""",
from_email="No reply Hostea<no-reply@exampl.org>", # TODO read from settings.py
message=body,
from_email=f"No reply Hostea<{sender}>", # TODO read from settings.py
recipient_list=[email],
)
job.delete()

View File

@ -18,8 +18,10 @@ from django.contrib.auth import authenticate, login, logout
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.template.loader import render_to_string
from django.views.decorators.csrf import csrf_protect
from django.core.mail import send_mail
from django.conf import settings
from django.urls import reverse
from accounts.decorators import confirm_access
@ -52,27 +54,27 @@ def create_instance(request, instance_name: str):
res = create_vm_if_not_exists(instance=instance)
if res is not None:
(gitea_password, commit) = res
send_mail(
subject="[Hostea] Gitea admin credentials",
message=f"""
Congratulations on your new Gitea instance!\n
You can use the following credentials to log into an admin account on
your new Gitea instance. Great powers come with great responsibilities,
so use the admin credentials wisely. When in doubt, consult the Gitea
docs or contact support!\n
- username : root
- password: {gitea_password}
""",
from_email="No reply Hostea<no-reply@exampl.org>", # TODO read from settings.py
recipient_list=[request.user.email],
)
ctx = {
"username": request.user.username,
"gitea_password": gitea_password,
"gitea_uri": Infra.get_gitea_uri(instance=instance),
}
body = render_to_string(
"infrastructure/emails/gitea-creds.txt",
context=ctx,
)
sender = settings.DEFAULT_FROM_EMAIL
send_mail(
subject="[Hostea] Your Hostea instance is now online!",
message=body,
from_email=f"No reply Hostea<{sender}>", # TODO read from settings.py
recipient_list=[request.user.email],
)
return render(request, "infrastructure/html/create.html", ctx)
return HttpResponse()