Skip to content

Commit

Permalink
Generate a secret key file, and load SECRET_KEY from said file.
Browse files Browse the repository at this point in the history
  • Loading branch information
aronasorman committed Sep 24, 2015
1 parent 45b1e7c commit 2962ec8
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions kalite/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,22 @@
USE_L10N = getattr(local_settings, "USE_L10N", False)

# Make this unique, and don't share it with anybody.
SECRET_KEY = getattr(local_settings, "SECRET_KEY",
"8qq-!fa$92i=s1gjjitd&%s@4%ka9lj+=@n7a&fzjpwu%3kd#u")
SECRET_KEY_FILE = os.path.join(USER_DATA_ROOT, "secretkey.txt")


def generate_secret_key():
import uuid
import base64
key = base64.b64encode(str(uuid.uuid4()))
with open(SECRET_KEY_FILE, "w") as f:
f.write(key)
f.flush()

if not os.path.exists(SECRET_KEY_FILE):
generate_secret_key()

with open(SECRET_KEY_FILE) as f:
SECRET_KEY = getattr(local_settings, "SECRET_KEY", f.read())

LANGUAGE_COOKIE_NAME = "django_language"

Expand Down Expand Up @@ -467,7 +481,7 @@
# Separate session caching from file caching.
SESSION_ENGINE = getattr(
local_settings, "SESSION_ENGINE", 'django.contrib.sessions.backends.signed_cookies' + (''))

# Expire session cookies whenever we close the browser.
SESSION_EXPIRE_AT_BROWSER_CLOSE = True

Expand Down

0 comments on commit 2962ec8

Please sign in to comment.