make is_active, is_authenticated, and is_anonymous properties on the Anonymous class so that the login_required decorator will work correctly and disable anonymous browsing
This commit is contained in:
+10
-10
@@ -866,7 +866,7 @@ def get_opds_download_link(book_id, book_format):
|
||||
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
||||
data = db.session.query(db.Data).filter(db.Data.book == book.id).filter(db.Data.format == book_format.upper()).first()
|
||||
app.logger.info(data.name)
|
||||
if current_user.is_authenticated():
|
||||
if current_user.is_authenticated:
|
||||
helper.update_download(book_id, int(current_user.id))
|
||||
file_name = book.title
|
||||
if len(book.authors) > 0:
|
||||
@@ -1309,7 +1309,7 @@ def show_book(book_id):
|
||||
for entry in shelfs:
|
||||
book_in_shelfs.append(entry.shelf)
|
||||
|
||||
if not current_user.is_anonymous():
|
||||
if not current_user.is_anonymous:
|
||||
matching_have_read_book = ub.session.query(ub.ReadBook).filter(ub.and_(ub.ReadBook.user_id == int(current_user.id),
|
||||
ub.ReadBook.book_id == book_id)).all()
|
||||
have_read = len(matching_have_read_book) > 0 and matching_have_read_book[0].is_read
|
||||
@@ -1717,7 +1717,7 @@ def feed_get_cover(book_id):
|
||||
|
||||
|
||||
def render_read_books(page, are_read, as_xml=False):
|
||||
if not current_user.is_anonymous():
|
||||
if not current_user.is_anonymous:
|
||||
readBooks = ub.session.query(ub.ReadBook).filter(ub.ReadBook.user_id == int(current_user.id)).filter(ub.ReadBook.is_read == True).all()
|
||||
readBookIds = [x.book_id for x in readBooks]
|
||||
if are_read:
|
||||
@@ -1791,7 +1791,7 @@ def read_book(book_id, book_format):
|
||||
if not os.path.exists(book_dir):
|
||||
os.mkdir(book_dir)
|
||||
bookmark = None
|
||||
if current_user.is_authenticated():
|
||||
if current_user.is_authenticated:
|
||||
bookmark = ub.session.query(ub.Bookmark).filter(ub.and_(ub.Bookmark.user_id == int(current_user.id),
|
||||
ub.Bookmark.book_id == book_id,
|
||||
ub.Bookmark.format == book_format.upper())).first()
|
||||
@@ -1842,7 +1842,7 @@ def get_download_link(book_id, book_format):
|
||||
data = db.session.query(db.Data).filter(db.Data.book == book.id).filter(db.Data.format == book_format.upper()).first()
|
||||
if data:
|
||||
# collect downloaded books only for registered user and not for anonymous user
|
||||
if current_user.is_authenticated():
|
||||
if current_user.is_authenticated:
|
||||
helper.update_download(book_id, int(current_user.id))
|
||||
file_name = book.title
|
||||
if len(book.authors) > 0:
|
||||
@@ -1876,7 +1876,7 @@ def get_download_link_ext(book_id, book_format, anyname):
|
||||
def register():
|
||||
if not config.config_public_reg:
|
||||
abort(404)
|
||||
if current_user is not None and current_user.is_authenticated():
|
||||
if current_user is not None and current_user.is_authenticated:
|
||||
return redirect(url_for('index'))
|
||||
|
||||
if request.method == "POST":
|
||||
@@ -1913,7 +1913,7 @@ def register():
|
||||
def login():
|
||||
if not config.db_configured:
|
||||
return redirect(url_for('basic_configuration'))
|
||||
if current_user is not None and current_user.is_authenticated():
|
||||
if current_user is not None and current_user.is_authenticated:
|
||||
return redirect(url_for('index'))
|
||||
if request.method == "POST":
|
||||
form = request.form.to_dict()
|
||||
@@ -1940,7 +1940,7 @@ def login():
|
||||
@app.route('/logout')
|
||||
@login_required
|
||||
def logout():
|
||||
if current_user is not None and current_user.is_authenticated():
|
||||
if current_user is not None and current_user.is_authenticated:
|
||||
logout_user()
|
||||
return redirect(url_for('login'))
|
||||
|
||||
@@ -2206,7 +2206,7 @@ def delete_shelf(shelf_id):
|
||||
@app.route("/shelf/<int:shelf_id>")
|
||||
@login_required_if_no_ano
|
||||
def show_shelf(shelf_id):
|
||||
if current_user.is_anonymous():
|
||||
if current_user.is_anonymous:
|
||||
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
|
||||
else:
|
||||
shelf = ub.session.query(ub.Shelf).filter(ub.or_(ub.and_(ub.Shelf.user_id == int(current_user.id),
|
||||
@@ -2241,7 +2241,7 @@ def order_shelf(shelf_id):
|
||||
setattr(book, 'order', to_save[str(book.book_id)])
|
||||
counter += 1
|
||||
ub.session.commit()
|
||||
if current_user.is_anonymous():
|
||||
if current_user.is_anonymous:
|
||||
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
|
||||
else:
|
||||
shelf = ub.session.query(ub.Shelf).filter(ub.or_(ub.and_(ub.Shelf.user_id == int(current_user.id),
|
||||
|
||||
Reference in New Issue
Block a user