Ver 30.03 env var done

This commit is contained in:
Flatlogic Bot 2026-04-21 22:03:32 +00:00
parent 8cf355d603
commit b551699778
3 changed files with 0 additions and 85 deletions

View File

@ -1,37 +0,0 @@
import os
from pathlib import Path
from django.shortcuts import render
from django.http import HttpResponse
from django.contrib.admin.views.decorators import staff_member_required
@staff_member_required
def setup_env(request):
# BASE_DIR is usually workspace, so its parent is where .env is.
env_path = Path(os.getcwd()).parent / ".env"
if request.method == "POST":
# Extract secrets from form
secret_key = request.POST.get("DJANGO_SECRET_KEY", "").strip()
email_user = request.POST.get("EMAIL_HOST_USER", "").strip()
email_pass = request.POST.get("EMAIL_HOST_PASSWORD", "").strip()
existing_content = ""
if env_path.exists():
existing_content = env_path.read_text()
with open(env_path, "a") as f:
# Add a newline if the file doesn't end with one
if existing_content and not existing_content.endswith("\n"):
f.write("\n")
# Append only non-empty values
if secret_key:
f.write(f"DJANGO_SECRET_KEY={secret_key}\n")
if email_user:
f.write(f"EMAIL_HOST_USER={email_user}\n")
if email_pass:
f.write(f"EMAIL_HOST_PASSWORD={email_pass}\n")
return HttpResponse("<h3>Success! Secrets safely appended to .env.</h3><p>Please return to the AI chat, ask me to restart the app, and then I will delete this temporary page.</p>")
return render(request, "core/temp_env_setup.html")

View File

@ -1,45 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secure Environment Setup</title>
<style>
body { font-family: sans-serif; padding: 2rem; max-width: 600px; margin: auto; }
.form-group { margin-bottom: 1.5rem; }
label { display: block; font-weight: bold; margin-bottom: 0.5rem; }
input[type="text"], input[type="password"] {
width: 100%; padding: 0.5rem; font-size: 1rem;
}
button {
padding: 0.75rem 1.5rem; font-size: 1rem; background-color: #007bff; color: white; border: none; cursor: pointer;
}
button:hover { background-color: #0056b3; }
.warning { color: red; font-size: 0.85rem; margin-bottom: 2rem; }
</style>
</head>
<body>
<h2>Secure Environment Setup</h2>
<p class="warning">Warning: This page is temporary and should be deleted immediately after you save your secrets. Only administrators can view this page.</p>
<form method="POST">
{% csrf_token %}
<div class="form-group">
<label for="DJANGO_SECRET_KEY">DJANGO_SECRET_KEY</label>
<input type="text" id="DJANGO_SECRET_KEY" name="DJANGO_SECRET_KEY" placeholder="Paste your Secret Key">
</div>
<div class="form-group">
<label for="EMAIL_HOST_USER">EMAIL_HOST_USER</label>
<input type="text" id="EMAIL_HOST_USER" name="EMAIL_HOST_USER" placeholder="Paste your Email User">
</div>
<div class="form-group">
<label for="EMAIL_HOST_PASSWORD">EMAIL_HOST_PASSWORD</label>
<input type="password" id="EMAIL_HOST_PASSWORD" name="EMAIL_HOST_PASSWORD" placeholder="Paste your Email Password">
</div>
<button type="submit">Save to .env</button>
</form>
</body>
</html>

View File

@ -4,7 +4,6 @@
from django.urls import path
from . import views
from . import temp_env_view
urlpatterns = [
# Dashboard — the home page after login
@ -72,6 +71,4 @@ urlpatterns = [
# Visit /run-migrate/ to apply pending database migrations on production.
path('run-migrate/', views.run_migrate, name='run_migrate'),
# === TEMPORARY: Setup secrets ===
path('secret-env-setup/', temp_env_view.setup_env, name='setup_env'),
]