Browser viewer: Show an error message when trying to use the Sync function without being logged in

This commit is contained in:
Kovid Goyal 2018-04-13 16:02:10 +05:30
parent 8fa2c9a54f
commit 8e89d862fb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 2 deletions

View File

@ -148,7 +148,7 @@ def book_manifest(ctx, rd, book_id, fmt):
ans = jsonlib.load(f)
ans['metadata'] = book_as_json(db, book_id)
user = rd.username or None
ans['last_read_positions'] = db.get_last_read_positions(book_id, fmt, user)
ans['last_read_positions'] = db.get_last_read_positions(book_id, fmt, user) if user else []
return ans
except EnvironmentError as e:
if e.errno != errno.ENOENT:
@ -189,6 +189,8 @@ def get_last_read_position(ctx, rd, library_id, which):
'''
db = get_db(ctx, rd, library_id)
user = rd.username or None
if not user:
raise HTTPNotFound('login required for sync')
ans = {}
allowed_book_ids = ctx.allowed_book_ids(rd, db)
for item in which.split('_'):

View File

@ -137,7 +137,10 @@ class SyncBook: # {{{
return
self.overlay.hide()
if load_type is not 'load':
error_dialog(_('Failed to fetch sync data'), _('Failed to download last read data from server, click "Show details" for more information.'), xhr.error_html)
if xhr.responseText is 'login required for sync':
error_dialog(_('Failed to fetch sync data'), _('You must setup user accounts and login to use the sync functionality'))
else:
error_dialog(_('Failed to fetch sync data'), _('Failed to download last read data from server, click "Show details" for more information.'), xhr.error_html)
return
data = JSON.parse(xhr.responseText)
book = self.overlay.view.book