Commit 3bd8a389e275647819ab2b4eed020c06c5ed414f

Authored by Miguel Barao
1 parent f540e673
Exists in master and in 1 other branch dev

- generate random cookie secret

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