Merge pull request #16 from janeczku/master

merge from janeczku/master
pull/610/head
Ethan Lin 7 years ago committed by GitHub
commit 282e79f4d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -42,7 +42,7 @@
{% if g.user.kindle_mail and g.user.is_authenticated %} {% if g.user.kindle_mail and g.user.is_authenticated %}
<a href="{{url_for('send_to_kindle', book_id=entry.id)}}" id="sendbtn" class="btn btn-primary" role="button"><span class="glyphicon glyphicon-send"></span> {{_('Send to Kindle')}}</a> <a href="{{url_for('send_to_kindle', book_id=entry.id)}}" id="sendbtn" class="btn btn-primary" role="button"><span class="glyphicon glyphicon-send"></span> {{_('Send to Kindle')}}</a>
{% endif %} {% endif %}
{% if (g.user.role_download() and g.user.is_anonymous()) or g.user.is_authenticated %} {% if (g.user.role_download() and g.user.is_anonymous) or g.user.is_authenticated %}
<div class="btn-group" role="group"> <div class="btn-group" role="group">
<button id="read-in-browser" type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <button id="read-in-browser" type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-eye-open"></span> {{_('Read in browser')}} <span class="glyphicon glyphicon-eye-open"></span> {{_('Read in browser')}}
@ -157,7 +157,7 @@
</p> </p>
</div> </div>
{% endif %} {% endif %}
{% if not g.user.is_anonymous() %} {% if not g.user.is_anonymous %}
<div class="custom_columns"> <div class="custom_columns">
<p> <p>

@ -34,7 +34,7 @@
<id>{{url_for('feed_discover')}}</id> <id>{{url_for('feed_discover')}}</id>
<content type="text">{{_('Show Random Books')}}</content> <content type="text">{{_('Show Random Books')}}</content>
</entry> </entry>
{% if not current_user.is_anonymous() %} {% if not current_user.is_anonymous %}
<entry> <entry>
<title>{{_('Read Books')}}</title> <title>{{_('Read Books')}}</title>
<link rel="subsection" href="{{url_for('feed_read_books')}}" type="application/atom+xml;profile=opds-catalog"/> <link rel="subsection" href="{{url_for('feed_read_books')}}" type="application/atom+xml;profile=opds-catalog"/>

@ -34,7 +34,7 @@
</button> </button>
<a class="navbar-brand" href="{{url_for('index')}}">{{instance}}</a> <a class="navbar-brand" href="{{url_for('index')}}">{{instance}}</a>
</div> </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"> <form class="navbar-form navbar-left" role="search" action="{{url_for('search')}}" method="GET">
<div class="form-group input-group input-group-sm"> <div class="form-group input-group input-group-sm">
<label for="query" class="sr-only">{{_('Search')}}</label> <label for="query" class="sr-only">{{_('Search')}}</label>
@ -46,13 +46,13 @@
</form> </form>
{% endif %} {% endif %}
<div class="navbar-collapse collapse"> <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 "> <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> <li><a href="{{url_for('advanced_search')}}"><span class="glyphicon glyphicon-search"></span><span class="hidden-sm"> {{_('Advanced Search')}}</span></a></li>
</ul> </ul>
{% endif %} {% endif %}
<ul class="nav navbar-nav navbar-right" id="main-nav"> <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.user.role_upload() or g.user.role_admin()%}
{% if g.allow_upload %} {% if g.allow_upload %}
<li> <li>
@ -68,14 +68,12 @@
<li><a id="top_admin" href="{{url_for('admin')}}"><span class="glyphicon glyphicon-dashboard"></span><span class="hidden-sm"> {{_('Admin')}}</span></a></li> <li><a id="top_admin" href="{{url_for('admin')}}"><span class="glyphicon glyphicon-dashboard"></span><span class="hidden-sm"> {{_('Admin')}}</span></a></li>
{% endif %} {% endif %}
<li><a id="top_user" href="{{url_for('profile')}}"><span class="glyphicon glyphicon-user"></span><span class="hidden-sm"> {{g.user.nickname}}</span></a></li> <li><a id="top_user" href="{{url_for('profile')}}"><span class="glyphicon glyphicon-user"></span><span class="hidden-sm"> {{g.user.nickname}}</span></a></li>
{% if not g.user.is_anonymous() %} {% if not g.user.is_anonymous %}
<li><a id="logout" href="{{url_for('logout')}}"><span class="glyphicon glyphicon-log-out"></span><span class="hidden-sm"> {{_('Logout')}}</span></a></li> <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 %}
{% endif %} {% endif %}
{% if not g.user.is_authenticated() %} {% if g.allow_registration and not g.user.is_authenticated %}
<li><a id="login" href="{{url_for('login')}}"><span class="glyphicon glyphicon-log-in"></span> {{_('Login')}}</a></li> <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> <li><a id="register" href="{{url_for('register')}}"><span class="glyphicon glyphicon-user"></span> {{_('Register')}}</a></li>
{% endif %} {% endif %}
</ul> </ul>
@ -101,7 +99,7 @@
{% endfor %} {% endfor %}
<div class="container-fluid"> <div class="container-fluid">
<div class="row-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"> <div class="col-sm-2">
<nav class="navigation"> <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"> <ul class="list-unstyled" id="scnd-nav" intent in-standard-append="nav.navigation" in-mobile-after="#main-nav" in-mobile-class="nav navbar-nav">
@ -138,11 +136,13 @@
{% if g.user.show_series() %} {% if g.user.show_series() %}
<li id="nav_serie"><a href="{{url_for('series_list')}}"><span class="glyphicon glyphicon-bookmark"></span> {{_('Series')}}</a></li> <li id="nav_serie"><a href="{{url_for('series_list')}}"><span class="glyphicon glyphicon-bookmark"></span> {{_('Series')}}</a></li>
{%endif%} {%endif%}
{% if g.user.show_author() %}
<li id="nav_author"><a href="{{url_for('author_list')}}"><span class="glyphicon glyphicon-user"></span> {{_('Authors')}}</a></li> <li id="nav_author"><a href="{{url_for('author_list')}}"><span class="glyphicon glyphicon-user"></span> {{_('Authors')}}</a></li>
{%endif%}
{% if g.user.filter_language() == 'all' and g.user.show_language() %} {% 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> <li id="nav_lang"><a href="{{url_for('language_overview')}}"><span class="glyphicon glyphicon-flag"></span> {{_('Languages')}} </a></li>
{%endif%} {%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> <li class="nav-head hidden-xs">{{_('Public Shelves')}}</li>
{% for shelf in g.public_shelfes %} {% 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> <li><a href="{{url_for('show_shelf', shelf_id=shelf.id)}}"><span class="glyphicon glyphicon-list"></span> {{shelf.name}}</a></li>
@ -151,7 +151,7 @@
{% for shelf in g.user.shelf %} {% for shelf in g.user.shelf %}
<li><a href="{{url_for('show_shelf', shelf_id=shelf.id)}}"><span class="glyphicon glyphicon-list"></span> {{shelf.name}}</a></li> <li><a href="{{url_for('show_shelf', shelf_id=shelf.id)}}"><span class="glyphicon glyphicon-list"></span> {{shelf.name}}</a></li>
{% endfor %} {% endfor %}
{% if not g.user.is_anonymous() %} {% if not g.user.is_anonymous %}
<li id="nav_createshelf" class="create-shelf"><a href="{{url_for('create_shelf')}}">{{_('Create a Shelf')}}</a></li> <li id="nav_createshelf" class="create-shelf"><a href="{{url_for('create_shelf')}}">{{_('Create a Shelf')}}</a></li>
<li id="nav_about"><a href="{{url_for('stats')}}"><span class="glyphicon glyphicon-info-sign"></span> {{_('About')}}</a></li> <li id="nav_about"><a href="{{url_for('stats')}}"><span class="glyphicon glyphicon-info-sign"></span> {{_('About')}}</a></li>
{% endif %} {% endif %}

@ -84,7 +84,7 @@
bookUrl: "{{ url_for('static', filename=bookid) }}/", bookUrl: "{{ url_for('static', filename=bookid) }}/",
bookmarkUrl: "{{ url_for('bookmark', book_id=bookid, book_format='EPUB') }}", bookmarkUrl: "{{ url_for('bookmark', book_id=bookid, book_format='EPUB') }}",
bookmark: "{{ bookmark.bookmark_key if bookmark != None }}", bookmark: "{{ bookmark.bookmark_key if bookmark != None }}",
useBookmarks: {{ g.user.is_authenticated() | tojson }} useBookmarks: {{ g.user.is_authenticated | tojson }}
}; };
</script> </script>
<script src="{{ url_for('static', filename='js/libs/jquery.min.js') }}"></script> <script src="{{ url_for('static', filename='js/libs/jquery.min.js') }}"></script>

@ -2,7 +2,7 @@
{% block body %} {% block body %}
<div class="discover"> <div class="discover">
<h2>{{title}}</h2> <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 %} {% 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> <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> <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: class UserBase:
@classmethod @property
def is_authenticated(self): def is_authenticated(self):
return True return True
@ -97,11 +97,11 @@ class UserBase:
def role_delete_books(self): def role_delete_books(self):
return bool((self.role is not None)and(self.role & ROLE_DELETE_BOOKS == ROLE_DELETE_BOOKS)) return bool((self.role is not None)and(self.role & ROLE_DELETE_BOOKS == ROLE_DELETE_BOOKS))
@classmethod @property
def is_active(self): def is_active(self):
return True return True
@classmethod @property
def is_anonymous(self): def is_anonymous(self):
return False return False
@ -182,12 +182,15 @@ class Anonymous(AnonymousUserMixin, UserBase):
def role_admin(self): def role_admin(self):
return False return False
@property
def is_active(self): def is_active(self):
return False return False
@property
def is_anonymous(self): def is_anonymous(self):
return self.anon_browse return self.anon_browse
@property
def is_authenticated(self): def is_authenticated(self):
return False return False

@ -384,9 +384,12 @@ app.jinja_env.globals['url_for_other_page'] = url_for_other_page
def login_required_if_no_ano(func): def login_required_if_no_ano(func):
if config.config_anonbrowse == 1: @wraps(func)
return func def decorated_view(*args, **kwargs):
return login_required(func) if config.config_anonbrowse == 1:
return func(*args, **kwargs)
return login_required(func)(*args, **kwargs)
return decorated_view
def remote_login_required(f): def remote_login_required(f):
@ -866,7 +869,7 @@ def get_opds_download_link(book_id, book_format):
book = db.session.query(db.Books).filter(db.Books.id == book_id).first() 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() 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) app.logger.info(data.name)
if current_user.is_authenticated(): if current_user.is_authenticated:
helper.update_download(book_id, int(current_user.id)) helper.update_download(book_id, int(current_user.id))
file_name = book.title file_name = book.title
if len(book.authors) > 0: if len(book.authors) > 0:
@ -1309,7 +1312,7 @@ def show_book(book_id):
for entry in shelfs: for entry in shelfs:
book_in_shelfs.append(entry.shelf) 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), 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() ub.ReadBook.book_id == book_id)).all()
have_read = len(matching_have_read_book) > 0 and matching_have_read_book[0].is_read have_read = len(matching_have_read_book) > 0 and matching_have_read_book[0].is_read
@ -1717,7 +1720,7 @@ def feed_get_cover(book_id):
def render_read_books(page, are_read, as_xml=False): 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() 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] readBookIds = [x.book_id for x in readBooks]
if are_read: if are_read:
@ -1791,7 +1794,7 @@ def read_book(book_id, book_format):
if not os.path.exists(book_dir): if not os.path.exists(book_dir):
os.mkdir(book_dir) os.mkdir(book_dir)
bookmark = None 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), 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.book_id == book_id,
ub.Bookmark.format == book_format.upper())).first() ub.Bookmark.format == book_format.upper())).first()
@ -1842,7 +1845,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() data = db.session.query(db.Data).filter(db.Data.book == book.id).filter(db.Data.format == book_format.upper()).first()
if data: if data:
# collect downloaded books only for registered user and not for anonymous user # 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)) helper.update_download(book_id, int(current_user.id))
file_name = book.title file_name = book.title
if len(book.authors) > 0: if len(book.authors) > 0:
@ -1876,7 +1879,7 @@ def get_download_link_ext(book_id, book_format, anyname):
def register(): def register():
if not config.config_public_reg: if not config.config_public_reg:
abort(404) 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')) return redirect(url_for('index'))
if request.method == "POST": if request.method == "POST":
@ -1913,7 +1916,7 @@ def register():
def login(): def login():
if not config.db_configured: if not config.db_configured:
return redirect(url_for('basic_configuration')) 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')) return redirect(url_for('index'))
if request.method == "POST": if request.method == "POST":
form = request.form.to_dict() form = request.form.to_dict()
@ -1940,7 +1943,7 @@ def login():
@app.route('/logout') @app.route('/logout')
@login_required @login_required
def logout(): 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() logout_user()
return redirect(url_for('login')) return redirect(url_for('login'))
@ -2206,7 +2209,7 @@ def delete_shelf(shelf_id):
@app.route("/shelf/<int:shelf_id>") @app.route("/shelf/<int:shelf_id>")
@login_required_if_no_ano @login_required_if_no_ano
def show_shelf(shelf_id): 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() shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
else: else:
shelf = ub.session.query(ub.Shelf).filter(ub.or_(ub.and_(ub.Shelf.user_id == int(current_user.id), shelf = ub.session.query(ub.Shelf).filter(ub.or_(ub.and_(ub.Shelf.user_id == int(current_user.id),
@ -2241,7 +2244,7 @@ def order_shelf(shelf_id):
setattr(book, 'order', to_save[str(book.book_id)]) setattr(book, 'order', to_save[str(book.book_id)])
counter += 1 counter += 1
ub.session.commit() 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() shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
else: else:
shelf = ub.session.query(ub.Shelf).filter(ub.or_(ub.and_(ub.Shelf.user_id == int(current_user.id), shelf = ub.session.query(ub.Shelf).filter(ub.or_(ub.and_(ub.Shelf.user_id == int(current_user.id),

Loading…
Cancel
Save