Skip to content

Commit e2a21ca

Browse files
committed
[survey]Added generation token to access in the survey
1 parent 78c8a56 commit e2a21ca

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

elearning/config_dev.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,4 @@
148148
SESSION_COOKIE_SECURE = not DEBUG
149149
CSRF_COOKIE_SECURE = not DEBUG
150150
COOKIEBANNER_SECURE = not DEBUG
151+
PRESHARED_SURVEY_KEY = "**insecured_preshared_survey_key**"

elearning/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
COOKIEBANNER_AGE = config.COOKIEBANNER_AGE
6060
COOKIEBANNER_SECURE = config.COOKIEBANNER_SECURE
6161

62+
# PRESHARED SURVEY KEY
63+
PRESHARED_SURVEY_KEY = config.PRESHARED_SURVEY_KEY
6264

6365
except AttributeError as e:
6466
print("Please check you configuration file for the missing configuration variable:")

elearning/templatetags/custom_filters.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import hashlib
12
import os
3+
from datetime import datetime
24

35
from django import template
46
from django.conf import settings
@@ -72,3 +74,12 @@ def accumulate_quiz_index(value, arg):
7274
@register.simple_tag
7375
def settings_value(name):
7476
return getattr(settings, name, "")
77+
78+
79+
@register.simple_tag
80+
def generate_survey_token():
81+
preshared_key = getattr(settings, "PRESHARED_SURVEY_KEY", "")
82+
current_date = datetime.now().strftime("%Y-%m-%d")
83+
data = f"{preshared_key}{current_date}"
84+
token = hashlib.sha256(data.encode()).hexdigest()
85+
return token

0 commit comments

Comments
 (0)