Skip to content

Commit

Permalink
don't crash when there isn't a secret key
Browse files Browse the repository at this point in the history
  • Loading branch information
dublUayaychtee committed Jan 11, 2025
1 parent 4a090c5 commit c654ae3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion battery/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get("SECRET_KEY")
SECRET_KEY = os.environ.get("SECRET_KEY", "asdf")
BAD_KEY = False
if SECRET_KEY == "asdf":
BAD_KEY = True

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
Expand Down
3 changes: 2 additions & 1 deletion log/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
</form>
{% else %} You are not logged in
<a href="{% url 'login' %}"><button>Log In</button></a>
{% endif %}
{% endif %} {% if bad_key %} Security Token not found on server! Not
recommended to log in. {% endif %}
<hr />

<form method="post">
Expand Down
3 changes: 2 additions & 1 deletion log/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.http import HttpResponse, HttpResponseRedirect
from .models import Entry
from .forms import EntryForm
from battery.settings import BAD_KEY

# Create your views here.

Expand Down Expand Up @@ -32,4 +33,4 @@ def index(request):

entries = Entry.objects.all()
form = EntryForm()
return render(request, 'index.html', {'entries': entries,"form": form})
return render(request, 'index.html', {'entries': entries, 'form': form, 'bad_key': BAD_KEY})

0 comments on commit c654ae3

Please sign in to comment.