Skip to content

Commit

Permalink
add next to login route
Browse files Browse the repository at this point in the history
  • Loading branch information
cdhigh committed Apr 30, 2024
1 parent 3ec5c3d commit 28f9a08
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 48 deletions.
5 changes: 4 additions & 1 deletion application/base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ def login_required(forAjax=False):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
current_url = request.url
if (session.get('login', '') == 1) and get_login_user():
return func(*args, **kwargs)
elif forAjax:
return redirect(url_for("bpLogin.NeedLoginAjax"))
else:
return redirect(url_for("bpLogin.NeedLoginAjax") if forAjax else url_for("bpLogin.Login"))
return redirect(url_for("bpLogin.Login", next=current_url))
return wrapper
return decorator

Expand Down
6 changes: 4 additions & 2 deletions application/lib/calibre/ptempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def app_prefix(prefix):
return '%s_%s_%s'%(__appname__, __version__, prefix)

def base_dir():
return ""

global _base_dir
if _base_dir is None:
_base_dir = os.environ.get('KE_TEMP_DIR', '')
return _base_dir

def reset_base_dir():
pass
Expand Down
8 changes: 6 additions & 2 deletions application/lib/calibre/web/feeds/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ def build_index(self):
if feeds is None:
feeds = self.parse_feeds()

default_log.warning(feeds)
if not feeds:
raise ValueError('No articles found, aborting')

Expand Down Expand Up @@ -1868,7 +1869,7 @@ def parse_feeds(self):
if not feeds:
self.log.warning(f'There are no feeds in "{self.title}"')
return []

parsed_feeds = []
br = self.browser
for obj in feeds:
Expand Down Expand Up @@ -1915,7 +1916,7 @@ def parse_feeds(self):
remove = [fl for fl in parsed_feeds if len(fl) == 0 and self.remove_empty_feeds]
for f in remove:
parsed_feeds.remove(f)

return parsed_feeds

@classmethod
Expand Down Expand Up @@ -2142,6 +2143,9 @@ class WebPageUrlNewsRecipe(BasicNewsRecipe):

#返回一个Feed实例列表
def parse_feeds(self):
if not self.url_extract_rules:
return super().parse_feeds()

main_urls = self.get_feeds()
if not main_urls:
self.log.warning(f'There are no urls in "{self.title}"')
Expand Down
3 changes: 1 addition & 2 deletions application/lib/calibre/web/feeds/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def render(self, *args, **kwargs):
class EmbeddedContent(Template):

def _generate(self, article, style=None, extra_css=None):
ac = article.content
content = ' '.join([e.value for e in ac]) if isinstance(ac, list) else (ac or '')
content = article.content if article.content else ''
summary = article.summary if article.summary else ''
text = content if len(content) > len(summary) else summary
head = HEAD(META(charset="utf-8"), TITLE(article.title))
Expand Down
5 changes: 2 additions & 3 deletions application/lib/recipe_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ def GenerateRecipeSource(title, feeds, user, isfulltext=False, language=None, ma
desc = desc[:100]
oldest_article = user.book_cfg('oldest_article')
#至少到feedparser 6.0.11为止,其提取xml内的内容有bug,经常提取不到,在他修复之前,我们先暂停全文rss功能
#全部都当非全文rss使用
isfulltext = False
auto_cleanup = 'False' if isfulltext else 'True'
isfulltext = 'True' if isfulltext else 'None'
use_embedded_content = 'True' if isfulltext else 'None'
language = language or user.book_cfg('language')
timefmt = user.book_cfg('time_fmt')
if timefmt and (user.book_cfg('title_fmt') == 'title_[time]'):
Expand All @@ -50,7 +49,7 @@ class {className}({base}):
language = '{language}'
max_articles_per_feed = {max_articles}
oldest_article = {oldest_article}
use_embedded_content = {isfulltext}
use_embedded_content = {use_embedded_content}
auto_cleanup = {auto_cleanup}
timefmt = '{timefmt}'
cover_url = {cover_url}
Expand Down
2 changes: 2 additions & 0 deletions application/lib/urlopener.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def build_url(self, url, data, method):
#读取本地文件
def open_local_file(self, url):
url = url[7:] if url.startswith('file://') else url[5:]
if url.startswith('//'):
url = url[1:]
plat = sys.platform.lower()
if ('win32' in plat or 'win64' in plat) and url.startswith('/'): #windows平台
url = url[1:]
Expand Down
5 changes: 4 additions & 1 deletion application/static/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,10 @@ function SubscribeRecipe(id, separated) {

//点击了退订内置或上传的Recipe
function UnsubscribeRecipe(id, title) {
if (!confirm(i18n.areYouSureUnsubscribe.format(title))) {
if (!(event.ctrlKey || event.metaKey) && !confirm(i18n.areYouSureUnsubscribe.format(title))) {
return;
}

$.post("/recipe/unsubscribe", {id: id}, function (data) {
if (data.status == "ok") {
for (var idx = 0; idx < my_booked_recipes.length; idx++) {
Expand Down Expand Up @@ -487,6 +488,8 @@ function ShowDeleteCustomRssDialog(event, rssid, title, url, isfulltext) {
DeleteCustomRss(rssid, title, url, isfulltext, $('#chkReportInvalid').prop('checked'));
}).catch(function(){});
}
} else {
DeleteCustomRss(rssid, title, url, isfulltext, false);
}
}

Expand Down
1 change: 1 addition & 0 deletions application/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<label for="password">{{_("Password")}}</label>
<input name="password" type="password" class="pure-u-1 pure-u-sm-1-2" />
</div>
<input type="hidden" name="next" value="{{next}}">
<div class="pure-control-group" style="text-align:center;">
<button type="submit" class="pure-button pure-button-primary pure-input-rounded">{{_("Login")}}</button>
</div>
Expand Down
6 changes: 4 additions & 2 deletions application/templates/my.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
</div>
<div class="pure-u-2-5 pure-u-sm-1-4 pure-u-md-1-6">
<div>
<label style="white-space:nowrap;"><input type="checkbox" name="fulltext" id="isfulltext" />
{{_("Content embedded")}}</label>
<label style="white-space:nowrap;">
<input type="checkbox" name="fulltext" id="isfulltext" {% if isfulltext %}checked="checked"{% endif %}/>
{{_("Content embedded")}}
</label>
</div>
</div>
</div>
Expand Down
10 changes: 6 additions & 4 deletions application/view/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ def Login():
# 则增加一个管理员帐号 ADMIN_NAME,密码 ADMIN_NAME,后续可以修改密码
tips = ''
adminName = app.config['ADMIN_NAME']
next_url = request.args.get('next', '')
if CreateAccountIfNotExist(adminName):
tips = (_("Please use {}/{} to login at first time.").format(adminName, adminName))

return render_template('login.html', tips=tips)
return render_template('login.html', tips=tips, next=next_url)

@bpLogin.post("/login")
def LoginPost():
name = request.form.get('username', '').strip()
passwd = request.form.get('password', '')
next_url = request.form.get('next', '')
tips = ''
if not name:
tips = _("Username is empty.")
Expand All @@ -40,7 +42,7 @@ def LoginPost():
tips = _("The username includes unsafe chars.")

if tips:
return render_template('login.html', tips=tips)
return render_template('login.html', tips=tips, next=next_url)

adminName = app.config['ADMIN_NAME']
isFirstTime = CreateAccountIfNotExist(adminName) #确认管理员账号是否存在
Expand Down Expand Up @@ -75,7 +77,7 @@ def LoginPost():
elif not user.cfg('kindle_email'):
url = url_for("bpSetting.Setting")
else:
url = url_for("bpSubscribe.MySubscription")
url = next_url if next_url else url_for("bpSubscribe.MySubscription")
default_log.info(f"Login event: {name}")
return redirect(url)
else: #账号或密码错
Expand All @@ -89,7 +91,7 @@ def LoginPost():
session.pop('login', None)
session.pop('userName', None)
session.pop('role', None)
return render_template('login.html', userName=name, tips=tips)
return render_template('login.html', userName=name, tips=tips, next=next_url)

#判断账号是否存在
#如果账号不存在,创建一个,并返回True,否则返回False
Expand Down
6 changes: 4 additions & 2 deletions application/view/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
def MySubscription(tips=None):
user = get_login_user()
share_key = user.share_links.get('key', '')
title_to_add = request.args.get('title_to_add') #from Bookmarklet
url_to_add = request.args.get('url_to_add')
args = request.args
title_to_add = args.get('title_to_add') #from Bookmarklet/browser extension
url_to_add = args.get('url_to_add')
isfulltext = str_to_bool(args.get('isfulltext'))
my_custom_rss = [item.to_dict(only=[Recipe.id, Recipe.title, Recipe.url, Recipe.isfulltext,
Recipe.translator, Recipe.tts]) for item in user.all_custom_rss()]

Expand Down
63 changes: 34 additions & 29 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
requests>=2.31.0,<3.0.0
chardet>=5.2.0,<6.0.0
pillow>=10.2.0,<11.0.0
lxml>=5.0.0,<6.0.0
sendgrid>=6.11.0,<7.0.0
mailjet_rest>=1.3.4,<2.0.0
python-dateutil>=2.8.2,<3.0.0
css_parser>=1.0.10,<=2.0.0
beautifulsoup4>=4.12.2,<5.0.0
html2text>=2020.1.16
html5lib>=1.1,<2.0
requests~=2.31.0
chardet~=5.2.0
pillow~=10.3.0
lxml~=5.2.0
lxml_html_clean~=0.1.1
sendgrid~=6.11.0
mailjet_rest~=1.3.4
python-dateutil~=2.9.0
css_parser~=1.0.10
beautifulsoup4~=4.12.2
html2text~=2024.2.26
html5lib~=1.1
#html5-parser~=0.4.0
gunicorn>=21.2.0,<22.0.0
Flask>=3.0.0,<4.0.0
flask-babel>=4.0.0,<5.0.0
six>=1.16.0,<2.0.0
feedparser>=6.0.11,<7.0.0
peewee>=3.1.7,<4.0.0
flask-apscheduler>=1.13.1,<2.0.0
gunicorn~=22.0.0
Flask~=3.0.3
flask-babel~=4.0.0
six~=1.16.0
feedparser~=6.0.11
qrcode~=7.4.2
#gtts~=2.5.1
peewee~=3.17.1
flask-apscheduler~=1.13.1
redis~=5.0.3

#pymysql>=1.1.0,<2.0.0
#psycopg2>=2.9.9,<3.0.0
#weedata>=0.2.1,<1.0.0
#google-cloud-datastore>=2.19.0,<3.0.0
#pymongo>=3.7.2,<4.0.0
#redis>=4.5.0,<6.0.0
#google-cloud-tasks>=2.15.0,<3.0.0
#celery>=5.3.6,<6.0.0
#eventlet>=0.35.1,<1.0.0
#flask-rq2>=18.3,<19.0
#appengine-python-standard>=1.1.6,<2.0.0
#pymysql~=1.1.0
#psycopg2-binary~=2.9.9
#weedata>=0.2.5,<1.0.0
#google-cloud-datastore~=2.19.0
#pymongo~=4.6.3
#google-cloud-tasks~=2.16.3
#celery~=5.3.6
#eventlet~=0.36.1
#flask-rq2~=18.3
#appengine-python-standard~=1.1.6
#google-cloud-texttospeech~=2.16.3
#sqlalchemy~=2.0.29

0 comments on commit 28f9a08

Please sign in to comment.