From d4ab394c3f7fcef832451897c50dcaff28f8399d Mon Sep 17 00:00:00 2001 From: Miguel BarĂ£o Date: Mon, 29 Jan 2018 15:16:20 +0000 Subject: [PATCH] - removed unused learn.css file. - added log warning if user already logged in. --- BUGS.md | 1 + learnapp.py | 41 +++++++++++++++++++++-------------------- static/css/learn.css | 91 ------------------------------------------------------------------------------------------- static/css/maintopics.css | 4 ++-- static/css/topic.css | 15 +++++++++------ 5 files changed, 33 insertions(+), 119 deletions(-) delete mode 100644 static/css/learn.css diff --git a/BUGS.md b/BUGS.md index 8cce300..b5d781e 100644 --- a/BUGS.md +++ b/BUGS.md @@ -32,6 +32,7 @@ # FIXED +- check if user already logged in - mover javascript para ficheiros externos e carregar com script defer src - implementar xsrf. Ver [http://www.tornadoweb.org/en/stable/guide/security.html#cross-site-request-forgery-protection]() - se refs de um topic estao invalidos, nao carrega esse topico. devia haver um error nos logs a indicar qual o ref invalido. diff --git a/learnapp.py b/learnapp.py index 01c622e..d750220 100644 --- a/learnapp.py +++ b/learnapp.py @@ -47,35 +47,36 @@ class LearnApp(object): # ------------------------------------------------------------------------ # login # ------------------------------------------------------------------------ - def login(self, uid, try_pw): + def login(self, uid, pw): + with self.db_session() as s: student = s.query(Student).filter(Student.id == uid).one_or_none() if student is None: logger.info(f'User "{uid}" does not exist!') return False # student does not exist - hashedtry = bcrypt.hashpw(try_pw.encode('utf-8'), student.password) - if hashedtry != student.password: - logger.info(f'User "{uid}" wrong password!') - return False # wrong password - - # success - logger.info(f'User "{uid}" logged in') + if bcrypt.checkpw(pw.encode('utf-8'), student.password): + if uid in self.online: + logger.warning(f'User "{uid}" already logged in, overwriting state') - tt = s.query(StudentTopic).filter(StudentTopic.student_id == uid) - state = {} - for t in tt: - state[t.topic_id] = { + tt = s.query(StudentTopic).filter(StudentTopic.student_id == uid) + state = {t.topic_id: + { 'level': t.level, - 'date': datetime.strptime(t.date, "%Y-%m-%d %H:%M:%S.%f"), + 'date': datetime.strptime(t.date, "%Y-%m-%d %H:%M:%S.%f") + } for t in tt} + + self.online[uid] = { + 'number': student.id, + 'name': student.name, + 'state': StudentKnowledge(self.deps, state=state) } + logger.info(f'User "{uid}" logged in successfully') + return True - self.online[uid] = { - 'number': student.id, - 'name': student.name, - 'state': StudentKnowledge(self.deps, state=state) - } - return True + else: + logger.info(f'User "{uid}" wrong password!') + return False # ------------------------------------------------------------------------ # logout @@ -297,7 +298,7 @@ def build_dependency_graph(config={}): # if questions not in configuration then load all, preserving order if not tnode['questions']: tnode['questions'] = [q['ref'] for q in loaded_questions] - + # make questions factory (without repeating same question) tnode['factory'] = {} for q in loaded_questions: diff --git a/static/css/learn.css b/static/css/learn.css deleted file mode 100644 index c4c8315..0000000 --- a/static/css/learn.css +++ /dev/null @@ -1,91 +0,0 @@ -body { - margin: 0; - padding-top: 100px; -} - -img { - display: block; - margin: auto; - width: 80%; -} - -/* progress bars have height of 4 pixels */ -.progress { - height: 8px; - border-radius: 0px; -} - -/* make markdown tables beautiful */ -table { - border-collapse: collapse; - margin-left: 50px; -} -thead, tbody, td, th { - padding: 5px; - border-bottom: 1px solid #ddd; -} - -textarea { - font-family: monospace !important; -} - -/* Hack to avoid name clash between pygments and mathjax */ -.MathJax .mo, -.MathJax .mi { - color: inherit; -} - -/* ======================================================================== */ -body,html,.row-offcanvas { - height:100%; -} - - -#sidebar { - width: inherit; - min-width: 220px; - max-width: 220px; - background-color:#f5f5f5; - float: left; - height:100%; - position:relative; - overflow-y:auto; - overflow-x:hidden; -} -#main { - padding-top: 10px; - height:100%; - overflow:auto; -} -#body { - padding-bottom: 50px; -} - -/* https://medium.com/wdstack/bootstrap-sidebar-examples-e363021395ff#.ek5vc75p8 - * off Canvas sidebar - * -------------------------------------------------- - */ -@media screen and (max-width: 768px) { - .row-offcanvas { - position: relative; - -webkit-transition: all 0.25s ease-out; - -moz-transition: all 0.25s ease-out; - transition: all 0.25s ease-out; - width:calc(100% + 220px); - } - - .row-offcanvas-left - { - left: -220px; - } - - .row-offcanvas-left.active { - left: 0; - } - - .sidebar-offcanvas { - position: absolute; - top: 0; - } -} - diff --git a/static/css/maintopics.css b/static/css/maintopics.css index c77956e..f735abe 100644 --- a/static/css/maintopics.css +++ b/static/css/maintopics.css @@ -1,5 +1,5 @@ body { margin: 0; - padding-top: 100px; - margin-bottom: 80px; /* Margin bottom by footer height */ + padding-top: 120px; + margin-bottom: 60px; /* Margin bottom by footer height */ } diff --git a/static/css/topic.css b/static/css/topic.css index 2b6eb5b..9474ca7 100644 --- a/static/css/topic.css +++ b/static/css/topic.css @@ -1,21 +1,24 @@ .progress { - height: 20px; + /*position: fixed;*/ + top: 0; + height: 90px; border-radius: 0px; } body { margin: 0; - padding-top: 70px; - margin-bottom: 80px; /* Margin bottom by footer height */ + padding-top: 0px; + margin-bottom: 60px; /* Margin bottom by footer height */ } + .footer { position: absolute; bottom: 0; width: 100%; - /* Set the fixed height of the footer here */ - height: 60px; - line-height: 60px; /* Vertically center the text there */ + height: 40px; + line-height: 60px; background-color: #f5f5f5; } + html { position: relative; min-height: 100%; -- libgit2 0.21.2