diff --git a/container.db.sqlite3 b/container.db.sqlite3 index d95a78b..f2dafaf 100644 Binary files a/container.db.sqlite3 and b/container.db.sqlite3 differ diff --git a/infra/deploy-playbook.yaml b/infra/deploy-playbook.yaml index 1e7c9ad..d5232ae 100644 --- a/infra/deploy-playbook.yaml +++ b/infra/deploy-playbook.yaml @@ -1,6 +1,10 @@ -- hosts: all +- hosts: staging tasks: + - name: Debug django_allowed_host + debug: + var: django_allowed_host + - name: Install docker ansible.builtin.apt: name: docker.io @@ -78,9 +82,11 @@ env: DJANGO_DEBUG_FALSE: "1" DJANGO_SECRET_KEY: "{{ secret_key.content | b64decode }}" - DJANGO_ALLOWED_HOST: "localhost,staging.earthmanrpg.me,www.earthmanrpg.me,dashboard.earthmanrpg.me,earthmanrpg.me,167.172.29.172" + DJANGO_ALLOWED_HOST: "{{ django_allowed_host }}" DJANGO_DB_PATH: "/home/nonroot/db.sqlite3" - EMAIL_HOST_PASSWORD: "{{ lookup('env', 'EMAIL_HOST_PASSWORD') }}" + EMAIL_HOST_USER: "{{ email_host_user }}" + EMAIL_HOST_PASSWORD: "{{ email_host_password }}" + MAILGUN_API_KEY: "{{ mailgun_api_key }}" ports: 80:8888 # container port 80 (standard http port) maps to server port 8888 (arbitrary internal port) diff --git a/infra/group_vars/production/vault.yaml b/infra/group_vars/production/vault.yaml new file mode 100644 index 0000000..b898ca8 --- /dev/null +++ b/infra/group_vars/production/vault.yaml @@ -0,0 +1,22 @@ +$ANSIBLE_VAULT;1.1;AES256 +33333861646565323863616363316265346132643135656533613763336462656361353562396163 +6461313530323231383264373737323934346239316232340a356130646163636436663162386438 +30636530373663643166616665313738303437636562643035303138613861656165663939613433 +3465316130343732660a376536373136636162316665386536363536306130383033623735396634 +66383262643630356536633366373933313637646539643137356330316463356139613738386661 +34663231656232666630653162653732363431613461396464623133303965636432626536306634 +64373530313532353531633263383335653239386530343330326237343862386436633666646235 +31613530383834656462366535643030356562313237363735386337356165663564336564623862 +34623863623738653735393734336635616135383036306231623464653432616265626233306230 +63646466323135363466393832636466646434303564653032323366346430306336363435653761 +30336437373231376261326264616131653833616236623365393334303834626162343761623037 +36666665663866643263383835626336353030626337303461396665343731666465653662396164 +34306261356130363037643637303632663830383331346334313336663163303730306265393031 +39653231373139616465326561313633306433653461653931663164363565363636316433323933 +61333536323936306538343336663966633161633565666231393261643062636239323264623364 +38376266393937376133366561663931356236396131376137653536636539613738356466363334 +32326165316434636631613366376235633337356135333531623861343039346261656239613036 +65303836323538373832646531343234666330363161343337623539633464303161343765363331 +35386233303563346662633239346363373931333764383233623161313965623266656364383037 +32393738356532346665613031346338363738666265303765363438663062663237353033393262 +6137 diff --git a/infra/group_vars/staging/vault.yaml b/infra/group_vars/staging/vault.yaml new file mode 100644 index 0000000..b898ca8 --- /dev/null +++ b/infra/group_vars/staging/vault.yaml @@ -0,0 +1,22 @@ +$ANSIBLE_VAULT;1.1;AES256 +33333861646565323863616363316265346132643135656533613763336462656361353562396163 +6461313530323231383264373737323934346239316232340a356130646163636436663162386438 +30636530373663643166616665313738303437636562643035303138613861656165663939613433 +3465316130343732660a376536373136636162316665386536363536306130383033623735396634 +66383262643630356536633366373933313637646539643137356330316463356139613738386661 +34663231656232666630653162653732363431613461396464623133303965636432626536306634 +64373530313532353531633263383335653239386530343330326237343862386436633666646235 +31613530383834656462366535643030356562313237363735386337356165663564336564623862 +34623863623738653735393734336635616135383036306231623464653432616265626233306230 +63646466323135363466393832636466646434303564653032323366346430306336363435653761 +30336437373231376261326264616131653833616236623365393334303834626162343761623037 +36666665663866643263383835626336353030626337303461396665343731666465653662396164 +34306261356130363037643637303632663830383331346334313336663163303730306265393031 +39653231373139616465326561313633306433653461653931663164363565363636316433323933 +61333536323936306538343336663966633161633565666231393261643062636239323264623364 +38376266393937376133366561663931356236396131376137653536636539613738356466363334 +32326165316434636631613366376235633337356135333531623861343039346261656239613036 +65303836323538373832646531343234666330363161343337623539633464303161343765363331 +35386233303563346662633239346363373931333764383233623161313965623266656364383037 +32393738356532346665613031346338363738666265303765363438663062663237353033393262 +6137 diff --git a/infra/inventory.ini b/infra/inventory.ini new file mode 100644 index 0000000..28cd6cf --- /dev/null +++ b/infra/inventory.ini @@ -0,0 +1,7 @@ +[staging] +staging.earthmanrpg.me + +[production] +www.earthmanrpg.me +earthmanrpg.me +dashboard.earthmanrpg.me diff --git a/requirements.dev.txt b/requirements.dev.txt index 7444205..5c17466 100644 Binary files a/requirements.dev.txt and b/requirements.dev.txt differ diff --git a/requirements.txt b/requirements.txt index 0015bcf..097df52 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ Django==6.0 django-stubs==5.2.8 django-stubs-ext==5.2.8 gunicorn==23.0.0 +requests==2.31.0 diff --git a/src/apps/lyric/views.py b/src/apps/lyric/views.py index bbd3a5e..6d18ab1 100644 --- a/src/apps/lyric/views.py +++ b/src/apps/lyric/views.py @@ -1,5 +1,7 @@ +import requests from django.contrib import auth, messages -from django.core.mail import send_mail +from django.conf import settings +# from django.core.mail import send_mail from django.shortcuts import redirect from django.urls import reverse from .models import Token @@ -11,12 +13,21 @@ def send_login_email(request): reverse("login") + "?token=" + str(token.uid), ) message_body = f"Use this magic link to login to your Dashboard:\n\n{url}" - send_mail( - "A magic login link to your Dashboard", - message_body, - "adman@howdy.earthmanrpg.me", - [email], + # Send mail via Mailgun HTTP API + response = requests.post( + f"https://api.mailgun.net/v3/{settings.MAILGUN_DOMAIN}/messages", + auth=("api", settings.MAILGUN_API_KEY), + data={ + "from": "adman@howdy.earthmanrpg.me", + "to": email, + "subject": "A magic login link to your Dashboard", + "text": message_body, + }, ) + # Log any errors + if response.status_code != 200: + print(f"Mailgun API error: {response.status_code}: {response.text}") + messages.success( request, "Check your email!—there you'll find a magic login link. But hurry… it's only temporary!", diff --git a/src/core/settings.py b/src/core/settings.py index e590263..1630cec 100644 --- a/src/core/settings.py +++ b/src/core/settings.py @@ -156,4 +156,7 @@ EMAIL_HOST = "smtp.mailgun.org" EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER") # switch back to .environ[] when collectstatic moved outside docker build process EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD") # switch back to .environ[] EMAIL_PORT = 587 -EMAIL_USER_TLS = True +EMAIL_USE_TLS = True +# Mailgun API settings (for HTTP API instead of SMTP) +MAILGUN_API_KEY = os.environ.get("MAILGUN_API_KEY") +MAILGUN_DOMAIN = "howdy.earthmanrpg.me" # Your Mailgun domain \ No newline at end of file