diff --git a/infrastructure/templates/infrastructure/emails/gitea-creds.txt b/infrastructure/templates/infrastructure/emails/gitea-creds.txt new file mode 100644 index 0000000..77e55c3 --- /dev/null +++ b/infrastructure/templates/infrastructure/emails/gitea-creds.txt @@ -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 diff --git a/infrastructure/views.py b/infrastructure/views.py index 7607c6c..a657676 100644 --- a/infrastructure/views.py +++ b/infrastructure/views.py @@ -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", # 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.HOSTEA["EMAIL_SENDER_ADDRESS"] + + 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()