Commit 3bd8a389e275647819ab2b4eed020c06c5ed414f
1 parent
f540e673
Exists in
master
and in
1 other branch
- generate random cookie secret
- added sounds: intro, correct and wrong
Showing
2 changed files
with
15 additions
and
2 deletions
Show diff stats
serve.py
... | ... | @@ -3,6 +3,8 @@ |
3 | 3 | # python standard library |
4 | 4 | import os |
5 | 5 | import json |
6 | +import base64 | |
7 | +import uuid | |
6 | 8 | |
7 | 9 | # installed libraries |
8 | 10 | import markdown |
... | ... | @@ -46,7 +48,7 @@ class WebApplication(tornado.web.Application): |
46 | 48 | 'static_path': os.path.join(os.path.dirname(__file__), 'static'), |
47 | 49 | 'static_url_prefix': '/static/', # this is the default |
48 | 50 | 'xsrf_cookies': False, # FIXME see how to do it... |
49 | - 'cookie_secret': '__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__', # FIXME | |
51 | + 'cookie_secret': base64.b64encode(uuid.uuid4().bytes), # FIXME improve! | |
50 | 52 | 'login_url': '/login', |
51 | 53 | 'debug': True, |
52 | 54 | } |
... | ... | @@ -88,7 +90,7 @@ class LoginHandler(BaseHandler): |
88 | 90 | |
89 | 91 | if self.learn.login_ok(uid, pw): |
90 | 92 | print('login ok') |
91 | - self.set_secure_cookie("user", str(uid)) | |
93 | + self.set_secure_cookie("user", str(uid), expires_days=30) | |
92 | 94 | self.redirect(self.get_argument("next", "/")) |
93 | 95 | else: |
94 | 96 | print('login failed') | ... | ... |
templates/learn.html
... | ... | @@ -66,6 +66,11 @@ |
66 | 66 | <!-- ===================================================================== --> |
67 | 67 | <!-- Container --> |
68 | 68 | <div class="container"> |
69 | +<audio> | |
70 | + <source id="snd-intro" src="/static/sounds/intro.mp3" type="audio/mpeg"> | |
71 | + <source id="snd-correct" src="/static/sounds/correct.mp3" type="audio/mpeg"> | |
72 | + <source id="snd-wrong" src="/static/sounds/wrong.mp3" type="audio/mpeg"> | |
73 | +</audio> | |
69 | 74 | |
70 | 75 | <form action="/question" method="post" id="question_form" autocomplete="off"> |
71 | 76 | {% module xsrf_form_html() %} |
... | ... | @@ -112,9 +117,13 @@ function updateQuestion(response){ |
112 | 117 | getQuestion(); |
113 | 118 | } |
114 | 119 | }); |
120 | + var audio = new Audio('/static/sounds/correct.mp3'); | |
121 | + audio.play(); | |
115 | 122 | $('#question_div').animateCSS('pulse'); |
116 | 123 | break; |
117 | 124 | case "shake": |
125 | + var audio = new Audio('/static/sounds/wrong.mp3'); | |
126 | + audio.play(); | |
118 | 127 | $('#question_div').animateCSS('shake'); |
119 | 128 | break; |
120 | 129 | } |
... | ... | @@ -133,6 +142,8 @@ function getQuestion() { |
133 | 142 | } |
134 | 143 | |
135 | 144 | $(document).ready(function() { |
145 | + var audio = new Audio('/static/sounds/intro.mp3'); | |
146 | + audio.play(); | |
136 | 147 | // getQuestion(); |
137 | 148 | $("#submit").click(getQuestion); |
138 | 149 | }); | ... | ... |