forked from mrlan/EnglishPal
Compare commits
4 Commits
Bug400-Qiu
...
master
Author | SHA1 | Date |
---|---|---|
缪宸硕 | e48008550a | |
李凯 | fde3be4c23 | |
李凯 | 5d5f4cf8f2 | |
miaochenshuo | 260f62967b |
|
@ -5,6 +5,10 @@ from UseSqlite import InsertQuery, RecordQuery
|
||||||
path_prefix = '/var/www/wordfreq/wordfreq/'
|
path_prefix = '/var/www/wordfreq/wordfreq/'
|
||||||
path_prefix = './' # comment this line in deployment
|
path_prefix = './' # comment this line in deployment
|
||||||
|
|
||||||
|
def verify_pass(newpass,oldpass):
|
||||||
|
if(newpass==oldpass):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def verify_user(username, password):
|
def verify_user(username, password):
|
||||||
rq = RecordQuery(path_prefix + 'static/wordfreqapp.db')
|
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): # 旧密码错误
|
if not verify_user(username, old_password): # 旧密码错误
|
||||||
return False
|
return False
|
||||||
# 将用户名和密码一起加密,以免暴露不同用户的相同密码
|
# 将用户名和密码一起加密,以免暴露不同用户的相同密码
|
||||||
|
if verify_pass(new_password,old_password): #新旧密码一致
|
||||||
|
return False
|
||||||
password = md5(username + new_password)
|
password = md5(username + new_password)
|
||||||
rq = InsertQuery(path_prefix + 'static/wordfreqapp.db')
|
rq = InsertQuery(path_prefix + 'static/wordfreqapp.db')
|
||||||
rq.instructions_with_parameters("UPDATE user SET password=:password WHERE name=:username", dict(
|
rq.instructions_with_parameters("UPDATE user SET password=:password WHERE name=:username", dict(
|
||||||
|
|
|
@ -6,8 +6,6 @@ css:
|
||||||
# 全局引入的js文件地址
|
# 全局引入的js文件地址
|
||||||
js:
|
js:
|
||||||
head: # 在页面加载之前加载
|
head: # 在页面加载之前加载
|
||||||
- static/js/jquery.js
|
|
||||||
- static/js/word_operation.js
|
|
||||||
# - static/js/APlayer.js
|
# - static/js/APlayer.js
|
||||||
# - static/js/Meting.js
|
# - static/js/Meting.js
|
||||||
bottom: # 在页面加载完之后加载
|
bottom: # 在页面加载完之后加载
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,43 +0,0 @@
|
||||||
function familiar(index) {
|
|
||||||
var username = $("#username").text();
|
|
||||||
var word = $("#word_" + index).text();
|
|
||||||
var freq = $("#freq_" + index).text();
|
|
||||||
$.ajax({
|
|
||||||
type:"get",
|
|
||||||
url:"/" + username + "/" + word + "/familiar",
|
|
||||||
success:function(resp){
|
|
||||||
var new_freq = freq - 1;
|
|
||||||
if(new_freq <1) {
|
|
||||||
$("#p_" + index).remove();
|
|
||||||
} else {
|
|
||||||
$("#freq_" + index).text(new_freq);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function unfamiliar(index) {
|
|
||||||
var username = $("#username").text();
|
|
||||||
var word = $("#word_" + index).text();
|
|
||||||
var freq = $("#freq_" + index).text();
|
|
||||||
$.ajax({
|
|
||||||
type:"get",
|
|
||||||
url:"/" + username + "/" + word + "/unfamiliar",
|
|
||||||
success:function(resp){
|
|
||||||
var new_freq = parseInt(freq) + 1;
|
|
||||||
$("#freq_" + index).text(new_freq);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function del_word(index) {
|
|
||||||
var username = $("#username").text();
|
|
||||||
var word = $("#word_" + index).text();
|
|
||||||
$.ajax({
|
|
||||||
type:"get",
|
|
||||||
url:"/" + username + "/" + word + "/del",
|
|
||||||
success:function(resp){
|
|
||||||
$("#p_" + index).remove();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -22,7 +22,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<p><b>English Pal for <font id="username" color="red">{{ username }}</font></b>
|
<p><b>English Pal for <font color="red">{{ username }}</font></b>
|
||||||
<a class="btn btn-secondary" href="/logout" role="button">退出</a>
|
<a class="btn btn-secondary" href="/logout" role="button">退出</a>
|
||||||
<a class="btn btn-secondary" href="/reset" role="button">重设密码</a>
|
<a class="btn btn-secondary" href="/reset" role="button">重设密码</a>
|
||||||
</p>
|
</p>
|
||||||
|
@ -57,20 +57,37 @@
|
||||||
<p><b>我的生词簿</b></p>
|
<p><b>我的生词簿</b></p>
|
||||||
{% for x in lst3 %}
|
{% for x in lst3 %}
|
||||||
{% set word = x[0] %}
|
{% set word = x[0] %}
|
||||||
|
|
||||||
{% set freq = x[1] %}
|
{% set freq = x[1] %}
|
||||||
{% if session.get('thisWord') == x[0] and session.get('time') == 1 %}
|
{% if session.get('thisWord') == x[0] and session.get('time') == 1 %}
|
||||||
<a name="aaa"></a>
|
<a name="aaa"></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<p id='p_{{ loop.index0 }}' class="new-word" >
|
{% if freq > 1 %}
|
||||||
<a id="word_{{ loop.index0 }}" class="btn btn-light" href='http://youdao.com/w/eng/{{ word }}/#keyfrom=dict2.index'
|
<p class="new-word">
|
||||||
role="button">{{ word }}</a>
|
<a class="btn btn-light" href='http://youdao.com/w/eng/{{ word }}/#keyfrom=dict2.index'
|
||||||
(
|
role="button">{{ word }}</a>
|
||||||
<a id="freq_{{ loop.index0 }}" title="{{ word }}">{{ freq }}</a>
|
(
|
||||||
)
|
<a title="{{ word }}">{{ freq }}</a>
|
||||||
<a class="btn btn-success" onclick="familiar({{ loop.index0 }})" role="button">熟悉</a>
|
)
|
||||||
<a class="btn btn-warning" onclick="unfamiliar({{ loop.index0 }})" role="button">不熟悉</a>
|
|
||||||
<a class="btn btn-danger" onclick="del_word({{ loop.index0 }})" role="button">删除</a>
|
<a class="btn btn-success" href={{ username }}/{{ word }}/familiar role="button">熟悉</a>
|
||||||
</p>
|
<a class="btn btn-warning" href={{ username }}/{{ word }}/unfamiliar role="button">不熟悉</a>
|
||||||
|
<a class="btn btn-danger" href={{ username }}/{{ word }}/del role="button">删除</a>
|
||||||
|
</p>
|
||||||
|
{% else %}
|
||||||
|
<p class="new-word">
|
||||||
|
<a class="btn btn-light" href='http://youdao.com/w/eng/{{ word }}/#keyfrom=dict2.index'
|
||||||
|
role="button">{{ word }}</a>
|
||||||
|
(
|
||||||
|
<a title="{{ word }}">{{ freq }}</a>
|
||||||
|
)
|
||||||
|
<a class="btn btn-success" href={{ username }}/{{ word }}/familiar role="button">熟悉</a>
|
||||||
|
<a class="btn btn-warning" href={{ username }}/{{ word }}/unfamiliar role="button">不熟悉</a>
|
||||||
|
<a class="btn btn-danger" href={{ username }}/{{ word }}/del role="button">删除</a>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
<a href='http://youdao.com/w/eng/{{ word }}/#keyfrom=dict2.index'>{{ word }}</a>{{ freq }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<input id="selected-words2" type="hidden" value="{{ words }}">
|
<input id="selected-words2" type="hidden" value="{{ words }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -1,91 +0,0 @@
|
||||||
from time import sleep
|
|
||||||
from selenium import webdriver
|
|
||||||
|
|
||||||
# 获取浏览器驱动,并且打开响应的网址
|
|
||||||
driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\Google\ChromeDriver\chromedriver.exe")
|
|
||||||
|
|
||||||
HOME_PAGE = "http://127.0.0.1:5000/"
|
|
||||||
|
|
||||||
|
|
||||||
def test_word_operation():
|
|
||||||
try:
|
|
||||||
login()
|
|
||||||
unfamiliar()
|
|
||||||
familiar()
|
|
||||||
delete()
|
|
||||||
finally:
|
|
||||||
driver.quit()
|
|
||||||
|
|
||||||
|
|
||||||
def login():
|
|
||||||
driver.get(HOME_PAGE)
|
|
||||||
|
|
||||||
assert 'English Pal -' in driver.page_source
|
|
||||||
|
|
||||||
# login
|
|
||||||
elem = driver.find_element_by_link_text('登录')
|
|
||||||
elem.click()
|
|
||||||
sleep(2)
|
|
||||||
uname = 'peter'
|
|
||||||
password = 'peter'
|
|
||||||
|
|
||||||
elem = driver.find_element_by_name('username')
|
|
||||||
elem.send_keys(uname)
|
|
||||||
|
|
||||||
elem = driver.find_element_by_name('password')
|
|
||||||
elem.send_keys(password)
|
|
||||||
|
|
||||||
# find the login button
|
|
||||||
elem = driver.find_element_by_xpath('/html/body/form/p[3]/input')
|
|
||||||
elem.click()
|
|
||||||
|
|
||||||
assert 'EnglishPal Study Room for ' + uname in driver.title
|
|
||||||
|
|
||||||
|
|
||||||
def familiar():
|
|
||||||
sleep(5)
|
|
||||||
|
|
||||||
elem = driver.find_element_by_xpath('//*[@id="p_0"]/a[3]')
|
|
||||||
|
|
||||||
count = int(elem.find_element_by_xpath('//*[@id="freq_0"]').text)
|
|
||||||
|
|
||||||
loop = 3
|
|
||||||
|
|
||||||
for i in range(loop):
|
|
||||||
elem.click()
|
|
||||||
sleep(1)
|
|
||||||
|
|
||||||
new_count = int(driver.find_element_by_xpath('//*[@id="freq_0"]').text)
|
|
||||||
|
|
||||||
assert count - loop == new_count
|
|
||||||
|
|
||||||
|
|
||||||
def unfamiliar():
|
|
||||||
sleep(5)
|
|
||||||
|
|
||||||
elem = driver.find_element_by_xpath('//*[@id="p_0"]/a[4]')
|
|
||||||
|
|
||||||
count = int(elem.find_element_by_xpath('//*[@id="freq_0"]').text)
|
|
||||||
|
|
||||||
loop = 2
|
|
||||||
|
|
||||||
for i in range(loop):
|
|
||||||
elem.click()
|
|
||||||
sleep(1)
|
|
||||||
|
|
||||||
new_count = int(driver.find_element_by_xpath('//*[@id="freq_0"]').text)
|
|
||||||
|
|
||||||
assert count + loop == new_count
|
|
||||||
|
|
||||||
|
|
||||||
def delete():
|
|
||||||
sleep(3)
|
|
||||||
word = driver.find_element_by_xpath('//*[@id="word_0"]').text
|
|
||||||
elem = driver.find_element_by_xpath('//*[@id="p_0"]/a[5]')
|
|
||||||
elem.click()
|
|
||||||
sleep(5)
|
|
||||||
driver.refresh()
|
|
||||||
driver.refresh()
|
|
||||||
driver.refresh()
|
|
||||||
find_word = word in driver.page_source
|
|
||||||
assert find_word is False
|
|
|
@ -48,7 +48,7 @@ def unfamiliar(username, word):
|
||||||
pickle_idea.unfamiliar(user_freq_record, word)
|
pickle_idea.unfamiliar(user_freq_record, word)
|
||||||
session['thisWord'] = word # 1. put a word into session
|
session['thisWord'] = word # 1. put a word into session
|
||||||
session['time'] = 1
|
session['time'] = 1
|
||||||
return "success"
|
return redirect(url_for('user_bp.userpage', username=username))
|
||||||
|
|
||||||
|
|
||||||
@userService.route("/<username>/<word>/familiar", methods=['GET', 'POST'])
|
@userService.route("/<username>/<word>/familiar", methods=['GET', 'POST'])
|
||||||
|
@ -63,7 +63,7 @@ def familiar(username, word):
|
||||||
pickle_idea.familiar(user_freq_record, word)
|
pickle_idea.familiar(user_freq_record, word)
|
||||||
session['thisWord'] = word # 1. put a word into session
|
session['thisWord'] = word # 1. put a word into session
|
||||||
session['time'] = 1
|
session['time'] = 1
|
||||||
return "success"
|
return redirect(url_for('user_bp.userpage', username=username))
|
||||||
|
|
||||||
|
|
||||||
@userService.route("/<username>/<word>/del", methods=['GET', 'POST'])
|
@userService.route("/<username>/<word>/del", methods=['GET', 'POST'])
|
||||||
|
@ -77,7 +77,7 @@ def deleteword(username, word):
|
||||||
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
|
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
|
||||||
pickle_idea2.deleteRecord(user_freq_record, word)
|
pickle_idea2.deleteRecord(user_freq_record, word)
|
||||||
flash(f'<strong>{word}</strong> is no longer in your word list.')
|
flash(f'<strong>{word}</strong> is no longer in your word list.')
|
||||||
return "success"
|
return redirect(url_for('user_bp.userpage', username=username))
|
||||||
|
|
||||||
|
|
||||||
@userService.route("/<username>", methods=['GET', 'POST'])
|
@userService.route("/<username>", methods=['GET', 'POST'])
|
||||||
|
|
Loading…
Reference in New Issue