Compare commits

..

4 Commits

Author SHA1 Message Date
缪宸硕 e48008550a Merge branch 'Bug394-MiaoChenShuo' into master 2022-06-12 21:50:36 +08:00
李凯 fde3be4c23 更新 'app/Article.py' 2022-06-11 23:21:17 +08:00
李凯 5d5f4cf8f2 更新 'app/Article.py' 2022-06-11 23:13:08 +08:00
miaochenshuo 260f62967b 修复 Bug394 2022-06-05 23:36:55 +08:00
4 changed files with 41 additions and 58 deletions

View File

@ -61,14 +61,22 @@ def get_today_article(user_word_list, articleID):
if within_range(text_level, user_level, (8.0 - user_level) * factor):
d = reading
break
article_date = d['date']
s = '<div class="alert alert-success" role="alert">According to your word list, your level is <span class="badge bg-success">%4.2f</span> and we have chosen an article with a difficulty level of <span class="badge bg-success">%4.2f</span> for you.</div>' % (
user_level, text_level)
s += '<p class="text-muted">Article added on: %s</p>' % (d['date'])
s += '<div class="p-3 mb-2 bg-light text-dark">'
article_title = get_article_title(d['text'])
article_body = get_article_body(d['text'])
question_part = get_question_part(d['question'])
answer_part = get_answer_part(d['question'])
return user_level,text_level,article_date,article_title,article_body,question_part,answer_part
s += '<p class="display-3">%s</p>' % (article_title)
s += '<p class="lead"><font id="article" size=2>%s</font></p>' % (article_body)
s += '<p><small class="text-muted">%s</small></p>' % (d['source'])
s += '<p><b>%s</b></p>' % (get_question_part(d['question']))
s = s.replace('\n', '<br/>')
s += '%s' % (get_answer_part(d['question']))
s += '</div>'
session['articleID'] = d['article_id']
return s
def load_freq_history(path):
@ -95,7 +103,7 @@ def get_question_part(s):
flag = 0
elif flag == 1:
result.append(line)
return result
return '\n'.join(result)
def get_answer_part(s):
@ -109,4 +117,20 @@ def get_answer_part(s):
elif flag == 1:
result.append(line)
# https://css-tricks.com/snippets/javascript/showhide-element/
return result
js = '''
<script type="text/javascript">
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
</script>
'''
html_code = js
html_code += '\n'
html_code += '<button onclick="toggle_visibility(\'answer\');">ANSWER</button>\n'
html_code += '<div id="answer" style="display:none;">%s</div>\n' % ('\n'.join(result))
return html_code

View File

@ -5,6 +5,10 @@ from UseSqlite import InsertQuery, RecordQuery
path_prefix = '/var/www/wordfreq/wordfreq/'
path_prefix = './' # comment this line in deployment
def verify_pass(newpass,oldpass):
if(newpass==oldpass):
return True
def verify_user(username, password):
rq = RecordQuery(path_prefix + 'static/wordfreqapp.db')
@ -47,6 +51,8 @@ def change_password(username, old_password, new_password):
if not verify_user(username, old_password): # 旧密码错误
return False
# 将用户名和密码一起加密,以免暴露不同用户的相同密码
if verify_pass(new_password,old_password): #新旧密码一致
return False
password = md5(username + new_password)
rq = InsertQuery(path_prefix + 'static/wordfreqapp.db')
rq.instructions_with_parameters("UPDATE user SET password=:password WHERE name=:username", dict(

View File

@ -30,48 +30,8 @@
<p><a class="btn btn-success" href="/{{ username }}/reset" role="button"> 下一篇 Next Article </a></p>
<p><b>阅读文章并回答问题</b></p>
</div>
<div id="text-content">{{ today_article|safe }}</div>
<div id="text-content">
<div class="alert alert-success" role="alert">
According to your word list, your level is
<span class="badge bg-success">{{ user_level }}</span>
and we have chosen an article with a difficulty level of
<span class="badge bg-success">{{ text_level }}</span>
for you.
</div>
<p class="text-muted">Article added on: {{ article_date }}</p>
<div class="p-3 mb-2 bg-light text-dark">
<p class="display-3">{{ article_title }}</p>
<p class="lead"><font id="article" size=2>{{ article_body }}</font></p>
<p><b>
{% for x in question_part %}
{{ x }}
</br>
{% endfor %}
</b></p>
<script type="text/javascript">
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
</script>
</br>
<button onclick="toggle_visibility('answer')">ANSWER</button></br>
<div id="answer" style="display:none;">
{% for x in answer_part %}
{{ x }}
</br>
{% endfor %}
</div></br>
</div>
</div>
<div class="container-fluid">
<input type="checkbox" onclick="ChangeHighlight()" checked/>生词高亮
<input type="checkbox" onclick="onReadClick()" checked/>大声朗读
<input type="checkbox" onclick="onChooseClick()" checked/>划词入库

View File

@ -117,19 +117,11 @@ def userpage(username):
words = ''
for x in lst3:
words += x[0] + ' '
user_level,text_level,article_date,article_title,article_body,question_part,answer_part = get_today_article(user_freq_record, session['articleID'])
return render_template('userpage_get.html',
username=username,
session=session,
flashed_messages=get_flashed_messages_if_any(),
d=d,
user_level=user_level,
text_level=text_level,
article_date=article_date,
article_title=article_title,
article_body=article_body,
question_part=question_part,
answer_part=answer_part,
today_article=get_today_article(user_freq_record, session['articleID']),
d_len=len(d),
lst3=lst3,
yml=Yaml.yml,
@ -138,6 +130,7 @@ def userpage(username):
@userService.route("/<username>/mark", methods=['GET', 'POST'])
def user_mark_word(username):
'''