forked from mrlan/EnglishPal
Compare commits
48 Commits
master
...
Bug502-YuG
Author | SHA1 | Date |
---|---|---|
吴宇涵 | 01ecc83768 | |
吴宇涵 | f64d06fbbf | |
Lan Hui | 688ed72473 | |
吴宇涵 | 1f150fc847 | |
Lan Hui | 0ce1c6eb6e | |
Lan Hui | d4ac709385 | |
Lan Hui | 9eb5210d3f | |
Lan Hui | 0e25737381 | |
Lan Hui | b3b154a24f | |
Lan Hui | 4d99405bfa | |
Lan Hui | 8d8b9197b6 | |
Lan Hui | 3bc61a602f | |
Hui Lan | fb6d0b23ce | |
Hui Lan | c6010ccbbd | |
吴宇涵 | f17995a35c | |
吴宇涵 | ce28a5bf65 | |
吴宇涵 | 99aa4e0990 | |
Hui Lan | a220450b03 | |
Hui Lan | 7eb276937a | |
Hui Lan | b97210a9e0 | |
Hui Lan | e27985127a | |
吴宇涵 | 7941e5d1eb | |
吴宇涵 | 2cf65123e9 | |
吴宇涵 | 3e35679a91 | |
吴宇涵 | 82896de336 | |
吴宇涵 | 13ccbaf25c | |
吴宇涵 | ec6a2249ae | |
吴宇涵 | bdda754af6 | |
吴宇涵 | 52025d55bc | |
吴宇涵 | 5cffa1fada | |
Hui Lan | 2909b4d973 | |
Hui Lan | 9075fe9eea | |
Hui Lan | 691c5b0d43 | |
吴宇涵 | 44db2218c1 | |
吴宇涵 | 48de496caa | |
吴宇涵 | 1015704e23 | |
吴宇涵 | cabf6702a7 | |
Lan Hui | b34f260d98 | |
Lan Hui | 70d44fcf5c | |
吴宇涵 | b80fbc936c | |
吴宇涵 | ade10e5843 | |
吴宇涵 | 13d8977636 | |
吴宇涵 | e2b165ada8 | |
吴宇涵 | df82748518 | |
吴宇涵 | 376ef9bcbc | |
吴宇涵 | 90db6534ab | |
yugaoxiang | 43bd0bd09d | |
yugaoxiang | 0209548896 |
|
@ -10,3 +10,4 @@ app/static/frequency/frequency.p
|
||||||
app/static/wordfreqapp.db
|
app/static/wordfreqapp.db
|
||||||
app/static/donate-the-author.jpg
|
app/static/donate-the-author.jpg
|
||||||
app/static/donate-the-author-hidden.jpg
|
app/static/donate-the-author-hidden.jpg
|
||||||
|
app/model/__pycache__/
|
|
@ -96,9 +96,9 @@ class UserName:
|
||||||
if ' ' in self.username: # a user name must not include a whitespace
|
if ' ' in self.username: # a user name must not include a whitespace
|
||||||
return 'Whitespace is not allowed in the user name.'
|
return 'Whitespace is not allowed in the user name.'
|
||||||
for c in self.username: # a user name must not include special characters, except non-leading periods or underscores
|
for c in self.username: # a user name must not include special characters, except non-leading periods or underscores
|
||||||
if c in string.punctuation and c is not '.' and c is not '_':
|
if c in string.punctuation and c != '.' and c != '_':
|
||||||
return f'{c} is not allowed in the user name.'
|
return f'{c} is not allowed in the user name.'
|
||||||
if self.username in ['signup', 'login', 'logout', 'reset', 'mark', 'back', 'unfamiliar', 'familiar', 'del']:
|
if self.username in ['signup', 'login', 'logout', 'reset', 'mark', 'back', 'unfamiliar', 'familiar', 'del', 'admin']:
|
||||||
return 'You used a restricted word as your user name. Please come up with a better one.'
|
return 'You used a restricted word as your user name. Please come up with a better one.'
|
||||||
|
|
||||||
return 'OK'
|
return 'OK'
|
||||||
|
|
|
@ -0,0 +1,142 @@
|
||||||
|
# System Library
|
||||||
|
from flask import *
|
||||||
|
|
||||||
|
# Personal library
|
||||||
|
from Yaml import yml
|
||||||
|
from model.user import *
|
||||||
|
from model.article import *
|
||||||
|
|
||||||
|
ADMIN_NAME = "lanhui" # unique admin name
|
||||||
|
_cur_page = 1 # current article page
|
||||||
|
_page_size = 5 # article sizes per page
|
||||||
|
adminService = Blueprint("admin_service", __name__)
|
||||||
|
|
||||||
|
|
||||||
|
def check_is_admin():
|
||||||
|
# 未登录,跳转到未登录界面
|
||||||
|
if not session.get("logged_in"):
|
||||||
|
return render_template("not_login.html")
|
||||||
|
|
||||||
|
# 用户名不是admin_name
|
||||||
|
if session.get("username") != ADMIN_NAME:
|
||||||
|
return "You are not admin!"
|
||||||
|
|
||||||
|
return "pass"
|
||||||
|
|
||||||
|
|
||||||
|
@adminService.route("/admin", methods=["GET"])
|
||||||
|
def admin():
|
||||||
|
is_admin = check_is_admin()
|
||||||
|
if is_admin != "pass":
|
||||||
|
return is_admin
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
"admin_index.html", yml=yml, username=session.get("username")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@adminService.route("/admin/article", methods=["GET", "POST"])
|
||||||
|
def article():
|
||||||
|
global _cur_page, _page_size
|
||||||
|
|
||||||
|
is_admin = check_is_admin()
|
||||||
|
if is_admin != "pass":
|
||||||
|
return is_admin
|
||||||
|
|
||||||
|
_article_number = get_number_of_articles()
|
||||||
|
try:
|
||||||
|
_page_size = min(
|
||||||
|
max(1, int(request.args.get("size", 5))), _article_number
|
||||||
|
) # 最小的size是1
|
||||||
|
_cur_page = min(
|
||||||
|
max(1, int(request.args.get("page", 1))), _article_number // _page_size + (_article_number % _page_size > 0)
|
||||||
|
) # 最小的page是1
|
||||||
|
except ValueError:
|
||||||
|
return "page parmas must be int!"
|
||||||
|
|
||||||
|
_articles = get_page_articles(_cur_page, _page_size)
|
||||||
|
for article in _articles: # 获取每篇文章的title
|
||||||
|
article.title = article.text.split("\n")[0]
|
||||||
|
article.content = '<br/>'.join(article.text.split("\n")[1:])
|
||||||
|
|
||||||
|
context = {
|
||||||
|
"article_number": _article_number,
|
||||||
|
"text_list": _articles,
|
||||||
|
"page_size": _page_size,
|
||||||
|
"cur_page": _cur_page,
|
||||||
|
"username": session.get("username"),
|
||||||
|
}
|
||||||
|
|
||||||
|
def _update_context():
|
||||||
|
article_len = get_number_of_articles()
|
||||||
|
context["article_number"] = article_len
|
||||||
|
context["text_list"] = get_page_articles(_cur_page, _page_size)
|
||||||
|
_articles = get_page_articles(_cur_page, _page_size)
|
||||||
|
for article in _articles: # 获取每篇文章的title
|
||||||
|
article.title = article.text.split("\n")[0]
|
||||||
|
context["text_list"] = _articles
|
||||||
|
|
||||||
|
if request.method == "GET":
|
||||||
|
try:
|
||||||
|
delete_id = int(request.args.get("delete_id", 0))
|
||||||
|
except:
|
||||||
|
return "Delete article ID must be int!"
|
||||||
|
if delete_id: # delete article
|
||||||
|
delete_article_by_id(delete_id)
|
||||||
|
_update_context()
|
||||||
|
elif request.method == "POST":
|
||||||
|
data = request.form
|
||||||
|
content = data.get("content", "")
|
||||||
|
source = data.get("source", "")
|
||||||
|
question = data.get("question", "")
|
||||||
|
level = data.get("level", "4")
|
||||||
|
if content:
|
||||||
|
if level not in ['1', '2', '3', '4']:
|
||||||
|
return "Level must be between 1 and 4."
|
||||||
|
add_article(content, source, level, question)
|
||||||
|
_update_context()
|
||||||
|
title = content.split('\n')[0]
|
||||||
|
flash(f'Article added. Title: {title}')
|
||||||
|
return render_template("admin_manage_article.html", **context)
|
||||||
|
|
||||||
|
|
||||||
|
@adminService.route("/admin/user", methods=["GET", "POST"])
|
||||||
|
def user():
|
||||||
|
is_admin = check_is_admin()
|
||||||
|
if is_admin != "pass":
|
||||||
|
return is_admin
|
||||||
|
|
||||||
|
context = {
|
||||||
|
"user_list": get_users(),
|
||||||
|
"username": session.get("username"),
|
||||||
|
}
|
||||||
|
if request.method == "POST":
|
||||||
|
data = request.form
|
||||||
|
username = data.get("username","")
|
||||||
|
new_password = data.get("new_password", "")
|
||||||
|
expiry_time = data.get("expiry_time", "")
|
||||||
|
if username:
|
||||||
|
if new_password:
|
||||||
|
update_password_by_username(username, new_password)
|
||||||
|
flash(f'Password updated to {new_password}')
|
||||||
|
if expiry_time:
|
||||||
|
update_expiry_time_by_username(username, "".join(expiry_time.split("-")))
|
||||||
|
flash(f'Expiry date updated to {expiry_time}.')
|
||||||
|
return render_template("admin_manage_user.html", **context)
|
||||||
|
|
||||||
|
|
||||||
|
@adminService.route("/admin/expiry", methods=["GET"])
|
||||||
|
def user_expiry_time():
|
||||||
|
is_admin = check_is_admin()
|
||||||
|
if is_admin != "pass":
|
||||||
|
return is_admin
|
||||||
|
|
||||||
|
username = request.args.get("username", "")
|
||||||
|
if not username:
|
||||||
|
return "Username can't be empty."
|
||||||
|
|
||||||
|
user = get_user_by_username(username)
|
||||||
|
if not user:
|
||||||
|
return "User does not exist."
|
||||||
|
|
||||||
|
return user.expiry_date
|
14
app/main.py
14
app/main.py
|
@ -5,24 +5,24 @@
|
||||||
# Copyright 2019 (C) Hui Lan <hui.lan@cantab.net>
|
# Copyright 2019 (C) Hui Lan <hui.lan@cantab.net>
|
||||||
# Written permission must be obtained from the author for commercial uses.
|
# Written permission must be obtained from the author for commercial uses.
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
|
||||||
from flask import escape
|
from flask import escape
|
||||||
from Login import *
|
from Login import *
|
||||||
from Article import *
|
from Article import *
|
||||||
import Yaml
|
import Yaml
|
||||||
from user_service import userService
|
from user_service import userService
|
||||||
from account_service import accountService
|
from account_service import accountService
|
||||||
|
from admin_service import adminService, ADMIN_NAME
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = 'lunch.time!'
|
app.secret_key = 'lunch.time!'
|
||||||
|
|
||||||
# 将蓝图注册到Lab app
|
# 将蓝图注册到Lab app
|
||||||
app.register_blueprint(userService)
|
app.register_blueprint(userService)
|
||||||
app.register_blueprint(accountService)
|
app.register_blueprint(accountService)
|
||||||
|
app.register_blueprint(adminService)
|
||||||
|
|
||||||
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 get_random_image(path):
|
def get_random_image(path):
|
||||||
'''
|
'''
|
||||||
返回随机图
|
返回随机图
|
||||||
|
@ -98,9 +98,13 @@ def mainpage():
|
||||||
d = load_freq_history(path_prefix + 'static/frequency/frequency.p')
|
d = load_freq_history(path_prefix + 'static/frequency/frequency.p')
|
||||||
d_len = len(d)
|
d_len = len(d)
|
||||||
lst = sort_in_descending_order(pickle_idea.dict2lst(d))
|
lst = sort_in_descending_order(pickle_idea.dict2lst(d))
|
||||||
return render_template('mainpage_get.html', random_ads=random_ads, number_of_essays=number_of_essays,
|
return render_template('mainpage_get.html',
|
||||||
d_len=d_len, lst=lst, yml=Yaml.yml)
|
admin_name=ADMIN_NAME,
|
||||||
|
random_ads=random_ads,
|
||||||
|
d_len=d_len,
|
||||||
|
lst=lst,
|
||||||
|
yml=Yaml.yml,
|
||||||
|
number_of_essays=number_of_essays)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
from pony.orm import *
|
||||||
|
|
||||||
|
db = Database()
|
||||||
|
db.bind("sqlite", "../static/wordfreqapp.db", create_db=True) # bind sqlite file
|
||||||
|
|
||||||
|
|
||||||
|
class User(db.Entity):
|
||||||
|
_table_ = "user" # table name
|
||||||
|
name = PrimaryKey(str)
|
||||||
|
password = Optional(str)
|
||||||
|
start_date = Optional(str)
|
||||||
|
expiry_date = Optional(str)
|
||||||
|
|
||||||
|
|
||||||
|
class Article(db.Entity):
|
||||||
|
_table_ = "article" # table name
|
||||||
|
article_id = PrimaryKey(int, auto=True)
|
||||||
|
text = Optional(str)
|
||||||
|
source = Optional(str)
|
||||||
|
date = Optional(str)
|
||||||
|
level = Optional(str)
|
||||||
|
question = Optional(str)
|
||||||
|
|
||||||
|
|
||||||
|
db.generate_mapping(create_tables=True) # must mapping after class declaration
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
with db_session:
|
||||||
|
print(Article[2].text) # test get article which id=2 text content
|
|
@ -0,0 +1,34 @@
|
||||||
|
from model import *
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def add_article(content, source="manual_input", level="5", question="No question"):
|
||||||
|
with db_session:
|
||||||
|
# add one article to sqlite
|
||||||
|
Article(
|
||||||
|
text=content,
|
||||||
|
source=source,
|
||||||
|
date=datetime.now().strftime("%-d %b %Y"), # format style of `5 Oct 2022`
|
||||||
|
level=level,
|
||||||
|
question=question,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def delete_article_by_id(article_id):
|
||||||
|
article_id &= 0xFFFFFFFF # max 32 bits
|
||||||
|
with db_session:
|
||||||
|
article = Article.select(article_id=article_id)
|
||||||
|
if article:
|
||||||
|
article.first().delete()
|
||||||
|
|
||||||
|
|
||||||
|
def get_number_of_articles():
|
||||||
|
with db_session:
|
||||||
|
return len(Article.select()[:])
|
||||||
|
|
||||||
|
|
||||||
|
def get_page_articles(num, size):
|
||||||
|
with db_session:
|
||||||
|
return [
|
||||||
|
x
|
||||||
|
for x in Article.select().order_by(desc(Article.article_id)).page(num, size)
|
||||||
|
]
|
|
@ -0,0 +1,24 @@
|
||||||
|
from model import *
|
||||||
|
from Login import md5
|
||||||
|
|
||||||
|
def get_users():
|
||||||
|
with db_session:
|
||||||
|
return User.select().order_by(User.name)[:]
|
||||||
|
|
||||||
|
def get_user_by_username(username):
|
||||||
|
with db_session:
|
||||||
|
user = User.select(name=username)
|
||||||
|
if user:
|
||||||
|
return user.first()
|
||||||
|
|
||||||
|
def update_password_by_username(username, password="123456"):
|
||||||
|
with db_session:
|
||||||
|
user = User.select(name=username)
|
||||||
|
if user:
|
||||||
|
user.first().password = md5(username + password)
|
||||||
|
|
||||||
|
def update_expiry_time_by_username(username, expiry_time="20230323"):
|
||||||
|
with db_session:
|
||||||
|
user = User.select(name=username)
|
||||||
|
if user:
|
||||||
|
user.first().expiry_date = expiry_time
|
|
@ -0,0 +1,55 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport"
|
||||||
|
content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=3.0, user-scalable=yes" />
|
||||||
|
<meta name="format-detection" content="telephone=no" />
|
||||||
|
{{ yml['header'] | safe }}
|
||||||
|
{% if yml['css']['item'] %}
|
||||||
|
{% for css in yml['css']['item'] %}
|
||||||
|
<link href="{{ css }}" rel="stylesheet">
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% if yml['js']['head'] %}
|
||||||
|
{% for js in yml['js']['head'] %}
|
||||||
|
<script src="{{ js }}"></script>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="container" style="width: 800px; margin: auto; margin-top:24px;">
|
||||||
|
<nav class="navbar navbar-expand-lg bg-light">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||||
|
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/{{ username }}">返回 {{ username }}</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="card" style="margin-top:24px;">
|
||||||
|
<div class="card-header">
|
||||||
|
请选择您需要的操作
|
||||||
|
</div>
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
<li class="list-group-item">
|
||||||
|
<div class="d-grid gap-2">
|
||||||
|
<a href="/admin/article" class="btn btn-outline-primary" type="button">管理文章</a>
|
||||||
|
<a href="/admin/user" class="btn btn-outline-primary" type="button">管理用户</a>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
|
@ -0,0 +1,103 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport"
|
||||||
|
content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=3.0, user-scalable=yes" />
|
||||||
|
<meta name="format-detection" content="telephone=no" />
|
||||||
|
<link href="../static/css/bootstrap.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="container" style="width: 800px; margin: auto; margin-top:24px;">
|
||||||
|
<nav class="navbar navbar-expand-lg bg-light">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||||
|
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/admin">前一页</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
{% for message in get_flashed_messages() %}
|
||||||
|
<div class="alert alert-success" role="alert">
|
||||||
|
{{ message }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<div class="card" style="margin-top:24px;">
|
||||||
|
{% if tips %}
|
||||||
|
<div class="alert alert-success" role="alert">
|
||||||
|
{{ tips }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<div class="card-content">
|
||||||
|
<h5 style="margin-top: 10px;padding-left: 10px;">录入文章</h5>
|
||||||
|
<form action="" method="post" class="container mb-3">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">文章内容</label>
|
||||||
|
<textarea id="content" name="content" class="form-control" rows="8" placeholder="首行是标题,后面是正文。"></textarea>
|
||||||
|
<label class="form-label">文章来源</label>
|
||||||
|
<textarea id="source" name="source" class="form-control" placeholder="推荐格式:Source: HTTP 链接。"></textarea>
|
||||||
|
<label class="form-label">文章等级</label>
|
||||||
|
<select id="level" class="form-select" name="level">
|
||||||
|
<option value="1">1</option>
|
||||||
|
<option value="2">2</option>
|
||||||
|
<option value="3">3</option>
|
||||||
|
<option selected value="4">4</option>
|
||||||
|
</select>
|
||||||
|
<label class="form-label">文章问题</label>
|
||||||
|
<textarea id="question" name="question" class="form-control" rows="6" placeholder="格式:
 QUESTION
 What?

 ANSWER
 Apple. "></textarea>
|
||||||
|
</div>
|
||||||
|
<input type="submit" value="保存" class="btn btn-outline-primary">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card" style="margin-top:24px;">
|
||||||
|
<h5 style="margin-top: 10px;padding-left: 10px;">文章列表</h5>
|
||||||
|
<div class="list-group">
|
||||||
|
{% for text in text_list %}
|
||||||
|
<div class="list-group-item list-group-item-action" aria-current="true">
|
||||||
|
<div>
|
||||||
|
<a type="button" href="/admin/article?delete_id={{text.article_id}}" class="btn btn-outline-danger btn-sm">删除</a>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex w-100 justify-content-between">
|
||||||
|
<h5 class="mb-1">{{ text.title }}</h5>
|
||||||
|
</div>
|
||||||
|
<div><small>{{ text.source }}</small></div>
|
||||||
|
<div class="d-flex w-100 justify-content-between">
|
||||||
|
<small>Level: {{text.level }}</small>
|
||||||
|
<small>Date: {{ text.date }}</small>
|
||||||
|
</div>
|
||||||
|
{{ text.content | safe }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style="margin:20px 0;">
|
||||||
|
<ul class="pagination pagination-sm justify-content-center">
|
||||||
|
<li class="page-item"><a class="page-link" href="/admin/article?page={{ cur_page - 1 }}&size={{ page_size }}">Previous</a>
|
||||||
|
</li>
|
||||||
|
{% for i in range(1, article_number // page_size + (article_number % page_size > 0) + 1) %}
|
||||||
|
{% if cur_page == i %}
|
||||||
|
<li class="page-item active"><a class="page-link" href="/admin/article?page={{ i }}&size={{ page_size }}">{{ i }}</a>
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
<li class="page-item"><a class="page-link" href="/admin/article?page={{ i }}&size={{ page_size }}">{{ i }}</a></li>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
<li class="page-item"><a class="page-link" href="/admin/article?page={{ cur_page + 1 }}&size={{ page_size }}">Next</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
|
@ -0,0 +1,99 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport"
|
||||||
|
content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=3.0, user-scalable=yes" />
|
||||||
|
<meta name="format-detection" content="telephone=no" />
|
||||||
|
<link href="../static/css/bootstrap.css" rel="stylesheet">
|
||||||
|
<script src="../static/js/jquery.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="container" style="width: 800px; margin: auto; margin-top:24px;">
|
||||||
|
<nav class="navbar navbar-expand-lg bg-light">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||||
|
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/admin">前一页</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
{% for message in get_flashed_messages() %}
|
||||||
|
<div class="alert alert-success" role="alert">
|
||||||
|
{{ message }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<div class="card" style="margin-top:24px;">
|
||||||
|
<h5 style="margin-top: 10px;padding-left: 10px;">重置选中用户的信息</h5>
|
||||||
|
<form id="user_form" action="" method="post" class="container mb-3">
|
||||||
|
<div>
|
||||||
|
<label class="form-label" style="padding-top: 10px;">用户</label>
|
||||||
|
<select onchange="loadUserExpiryDate()" id="username" name="username" class="form-select" aria-label="Default select example">
|
||||||
|
<option selected>选择用户</option>
|
||||||
|
{% for user in user_list %}
|
||||||
|
<option value="{{ user.name }}">{{ user.name }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label class="form-label" style="padding-top: 10px;">修改密码</label>
|
||||||
|
<div>
|
||||||
|
<button type="button" id="reset_pwd_btn" class="btn btn-outline-success">获取12位随机密码</button>
|
||||||
|
<input style="margin-left: 20px;border: 0; font-size: 20px;" name="new_password"
|
||||||
|
id="new_password"></input>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label class="form-label" style="padding-top: 10px;">过期时间</label>
|
||||||
|
<div>
|
||||||
|
<input type="date" id="expiry_date" name="expiry_time" placeholder="YYYY-MM-DD" pattern="yyyyMMdd">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button style="margin-top: 50px;" type="submit" class="btn btn-primary">更新用户信息</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// 密码生成器
|
||||||
|
function generatePassword(length) {
|
||||||
|
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^*()_+~`|}{[]\:;?,./-=";
|
||||||
|
let password = "";
|
||||||
|
for (let i = 0; i < length; i++) {
|
||||||
|
password += charset.charAt(Math.floor(Math.random() * charset.length));
|
||||||
|
}
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
document.getElementById("reset_pwd_btn").addEventListener("click", () => {
|
||||||
|
// 生成12位随机密码
|
||||||
|
let pwd = generatePassword(12)
|
||||||
|
document.getElementById("new_password").value = pwd
|
||||||
|
})
|
||||||
|
// 选择用户后更新其过期时间
|
||||||
|
function loadUserExpiryDate() {
|
||||||
|
const cur_user = $('#username').val();
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: `/admin/expiry?username=${cur_user}`,
|
||||||
|
success: function(resp) {
|
||||||
|
const year = resp.substr(0,4);
|
||||||
|
const month = resp.substr(4,2);
|
||||||
|
const day = resp.substr(6,2);
|
||||||
|
document.getElementById("expiry_date").value = year + '-' + month + '-' + day
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
|
@ -23,12 +23,15 @@
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<p><b><font size="+3" color="red">English Pal - Learn English smartly!</font></b></p>
|
<p><b><font size="+3" color="red">English Pal - Learn English smartly!</font></b></p>
|
||||||
{% if session['logged_in'] %}
|
{% if session['logged_in'] %}
|
||||||
<a href="/{{session['username']}}">{{session['username']}}</a></p>
|
<a href="/{{ session['username'] }}">{{ session['username'] }}</a>
|
||||||
|
{% if session['username'] == admin_name %}
|
||||||
|
<a href="/admin">管理</a></p>
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<p><a href="/login">登录</a> <a href="/signup">注册</a> <a href="/static/usr/instructions.html">使用说明</a></p >
|
<p><a href="/login">登录</a> <a href="/signup">注册</a> <a href="/static/usr/instructions.html">使用说明</a></p >
|
||||||
<p><b>{{random_ads|safe}}</b></p>
|
<p><b>{{random_ads|safe}}</b></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="alert alert-success" role="alert">共有文章 <span class="badge bg-success"> {{number_of_essays}} </span> 篇</div>
|
<div class="alert alert-success" role="alert">共有文章 <span class="badge bg-success"> {{ number_of_essays }} </span> 篇</div>
|
||||||
<p>粘贴1篇文章 (English only)</p>
|
<p>粘贴1篇文章 (English only)</p>
|
||||||
<form method="post" action="/">
|
<form method="post" action="/">
|
||||||
<textarea name="content" rows="10" cols="120"></textarea><br/>
|
<textarea name="content" rows="10" cols="120"></textarea><br/>
|
||||||
|
|
|
@ -37,8 +37,11 @@
|
||||||
<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 id="username" color="red">{{ username }}</font></b>
|
||||||
<a class="btn btn-secondary" href="/logout" role="button">退出</a>
|
{% if username == admin_name %}
|
||||||
<a class="btn btn-secondary" href="/reset" role="button">重设密码</a>
|
<a class="btn btn-secondary" href="/admin" role="button" onclick="stopRead()">管理</a>
|
||||||
|
{% endif %}
|
||||||
|
<a class="btn btn-secondary" href="/logout" role="button" onclick="stopRead()">退出</a>
|
||||||
|
<a class="btn btn-secondary" href="/reset" role="button" onclick="stopRead()">重设密码</a>
|
||||||
</p>
|
</p>
|
||||||
{{ flashed_messages|safe }}
|
{{ flashed_messages|safe }}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from admin_service import ADMIN_NAME
|
||||||
from flask import *
|
from flask import *
|
||||||
|
|
||||||
# from app import Yaml
|
# from app import Yaml
|
||||||
|
@ -131,6 +131,7 @@ def userpage(username):
|
||||||
for x in lst3:
|
for x in lst3:
|
||||||
words += x[0] + ' '
|
words += x[0] + ' '
|
||||||
return render_template('userpage_get.html',
|
return render_template('userpage_get.html',
|
||||||
|
admin_name=ADMIN_NAME,
|
||||||
username=username,
|
username=username,
|
||||||
session=session,
|
session=session,
|
||||||
flashed_messages=get_flashed_messages_if_any(),
|
flashed_messages=get_flashed_messages_if_any(),
|
||||||
|
|
4
build.sh
4
build.sh
|
@ -3,6 +3,10 @@
|
||||||
DEPLOYMENT_DIR=/home/lanhui/englishpal2/EnglishPal
|
DEPLOYMENT_DIR=/home/lanhui/englishpal2/EnglishPal
|
||||||
cd $DEPLOYMENT_DIR
|
cd $DEPLOYMENT_DIR
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
|
||||||
|
pip3 install -r requirements.txt
|
||||||
|
|
||||||
# Stop service
|
# Stop service
|
||||||
sudo docker stop EnglishPal
|
sudo docker stop EnglishPal
|
||||||
sudo docker rm EnglishPal
|
sudo docker rm EnglishPal
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
Flask==1.1.2
|
Flask==1.1.2
|
||||||
selenium==3.141.0
|
selenium==3.141.0
|
||||||
PyYAML~=6.0
|
PyYAML~=6.0
|
||||||
|
pony==0.7.16
|
||||||
|
|
Loading…
Reference in New Issue