mirror of
https://github.com/janeczku/calibre-web
synced 2025-01-12 18:30:31 +00:00
Fix for #360 and guest accounts
This commit is contained in:
parent
1eb10be253
commit
366bf9739b
@ -34,7 +34,7 @@
|
||||
</button>
|
||||
<a class="navbar-brand" href="{{url_for('index')}}">{{instance}}</a>
|
||||
</div>
|
||||
{% if g.user.is_authenticated or g.user.is_anonymous() %}
|
||||
{% if g.user.is_authenticated() or g.user.is_anonymous() %}
|
||||
<form class="navbar-form navbar-left" role="search" action="{{url_for('search')}}" method="GET">
|
||||
<div class="form-group input-group input-group-sm">
|
||||
<label for="query" class="sr-only">{{_('Search')}}</label>
|
||||
@ -46,13 +46,13 @@
|
||||
</form>
|
||||
{% endif %}
|
||||
<div class="navbar-collapse collapse">
|
||||
{% if g.user.is_authenticated or g.user.is_anonymous() %}
|
||||
{% if g.user.is_authenticated() or g.user.is_anonymous() %}
|
||||
<ul class="nav navbar-nav ">
|
||||
<li><a href="{{url_for('advanced_search')}}"><span class="glyphicon glyphicon-search"></span><span class="hidden-sm"> {{_('Advanced Search')}}</span></a></li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
<ul class="nav navbar-nav navbar-right" id="main-nav">
|
||||
{% if g.user.is_authenticated or g.user.is_anonymous() %}
|
||||
{% if g.user.is_authenticated() or g.user.is_anonymous() %}
|
||||
{% if g.user.role_upload() or g.user.role_admin()%}
|
||||
{% if g.allow_upload %}
|
||||
<li>
|
||||
@ -72,8 +72,10 @@
|
||||
<li><a id="logout" href="{{url_for('logout')}}"><span class="glyphicon glyphicon-log-out"></span><span class="hidden-sm"> {{_('Logout')}}</span></a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if g.allow_registration and not g.user.is_authenticated %}
|
||||
{% if not g.user.is_authenticated() %}
|
||||
<li><a id="login" href="{{url_for('login')}}"><span class="glyphicon glyphicon-log-in"></span> {{_('Login')}}</a></li>
|
||||
{% endif %}
|
||||
{% if g.allow_registration and not g.user.is_authenticated() %}
|
||||
<li><a id="register" href="{{url_for('register')}}"><span class="glyphicon glyphicon-user"></span> {{_('Register')}}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
@ -99,7 +101,7 @@
|
||||
{% endfor %}
|
||||
<div class="container-fluid">
|
||||
<div class="row-fluid">
|
||||
{% if g.user.is_authenticated or g.user.is_anonymous() %}
|
||||
{% if g.user.is_authenticated() or g.user.is_anonymous() %}
|
||||
<div class="col-sm-2">
|
||||
<nav class="navigation">
|
||||
<ul class="list-unstyled" id="scnd-nav" intent in-standard-append="nav.navigation" in-mobile-after="#main-nav" in-mobile-class="nav navbar-nav">
|
||||
@ -140,7 +142,7 @@
|
||||
{% if g.user.filter_language() == 'all' and g.user.show_language() %}
|
||||
<li id="nav_lang"><a href="{{url_for('language_overview')}}"><span class="glyphicon glyphicon-flag"></span> {{_('Languages')}} </a></li>
|
||||
{%endif%}
|
||||
{% if g.user.is_authenticated or g.user.is_anonymous() %}
|
||||
{% if g.user.is_authenticated() or g.user.is_anonymous() %}
|
||||
<li class="nav-head hidden-xs">{{_('Public Shelves')}}</li>
|
||||
{% for shelf in g.public_shelfes %}
|
||||
<li><a href="{{url_for('show_shelf', shelf_id=shelf.id)}}"><span class="glyphicon glyphicon-list"></span> {{shelf.name}}</a></li>
|
||||
|
@ -84,7 +84,7 @@
|
||||
bookUrl: "{{ url_for('static', filename=bookid) }}/",
|
||||
bookmarkUrl: "{{ url_for('bookmark', book_id=bookid, book_format='EPUB') }}",
|
||||
bookmark: "{{ bookmark.bookmark_key if bookmark != None }}",
|
||||
useBookmarks: {{ g.user.is_authenticated | tojson }}
|
||||
useBookmarks: {{ g.user.is_authenticated() | tojson }}
|
||||
};
|
||||
</script>
|
||||
<script src="{{ url_for('static', filename='js/libs/jquery.min.js') }}"></script>
|
||||
|
@ -2,7 +2,7 @@
|
||||
{% block body %}
|
||||
<div class="discover">
|
||||
<h2>{{title}}</h2>
|
||||
{% if g.user.is_authenticated %}
|
||||
{% if g.user.is_authenticated() %}
|
||||
{% if (g.user.role_edit_shelfs() and shelf.is_public ) or not shelf.is_public %}
|
||||
<div data-toggle="modal" data-target="#DeleteShelfDialog" class="btn btn-danger">{{ _('Delete this Shelf') }} </div>
|
||||
<a href="{{ url_for('edit_shelf', shelf_id=shelf.id) }}" class="btn btn-primary">{{ _('Edit Shelf name') }} </a>
|
||||
|
@ -51,7 +51,7 @@ DEVELOPMENT = False
|
||||
|
||||
|
||||
class UserBase:
|
||||
@staticmethod
|
||||
@classmethod
|
||||
def is_authenticated(self):
|
||||
return True
|
||||
|
||||
@ -172,6 +172,7 @@ class Anonymous(AnonymousUserMixin, UserBase):
|
||||
settings = session.query(Settings).first()
|
||||
self.nickname = data.nickname
|
||||
self.role = data.role
|
||||
self.id=data.id
|
||||
self.sidebar_view = data.sidebar_view
|
||||
self.default_language = data.default_language
|
||||
self.locale = data.locale
|
||||
@ -187,6 +188,8 @@ class Anonymous(AnonymousUserMixin, UserBase):
|
||||
def is_anonymous(self):
|
||||
return self.anon_browse
|
||||
|
||||
def is_authenticated(self):
|
||||
return False
|
||||
|
||||
# Baseclass representing Shelfs in calibre-web inapp.db
|
||||
class Shelf(Base):
|
||||
|
12
cps/web.py
12
cps/web.py
@ -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:
|
||||
@ -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'))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user