|
|
@ -60,8 +60,9 @@ particular calls to non-Kobo specific endpoints such as the CalibreWeb book down
|
|
|
|
from binascii import hexlify
|
|
|
|
from binascii import hexlify
|
|
|
|
from datetime import datetime
|
|
|
|
from datetime import datetime
|
|
|
|
from os import urandom
|
|
|
|
from os import urandom
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
from flask import g, Blueprint, url_for, abort
|
|
|
|
from flask import g, Blueprint, url_for, abort, request
|
|
|
|
from flask_login import login_user, login_required
|
|
|
|
from flask_login import login_user, login_required
|
|
|
|
from flask_babel import gettext as _
|
|
|
|
from flask_babel import gettext as _
|
|
|
|
|
|
|
|
|
|
|
@ -119,28 +120,37 @@ kobo_auth = Blueprint("kobo_auth", __name__, url_prefix="/kobo_auth")
|
|
|
|
@kobo_auth.route("/generate_auth_token/<int:user_id>")
|
|
|
|
@kobo_auth.route("/generate_auth_token/<int:user_id>")
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
def generate_auth_token(user_id):
|
|
|
|
def generate_auth_token(user_id):
|
|
|
|
# Invalidate any prevously generated Kobo Auth token for this user.
|
|
|
|
host = ':'.join(request.host.rsplit(':')[0:-1])
|
|
|
|
auth_token = ub.session.query(ub.RemoteAuthToken).filter(
|
|
|
|
if host == '127.0.0.1' or host.lower() == 'localhost' or host =='[::ffff:7f00:1]':
|
|
|
|
ub.RemoteAuthToken.user_id == user_id
|
|
|
|
warning = _('PLease access calibre-web from non localhost to get valid api_endpoint for kobo device')
|
|
|
|
).filter(ub.RemoteAuthToken.token_type==1).first()
|
|
|
|
return render_title_template(
|
|
|
|
|
|
|
|
"generate_kobo_auth_url.html",
|
|
|
|
if not auth_token:
|
|
|
|
title=_(u"Kobo Set-up"),
|
|
|
|
auth_token = ub.RemoteAuthToken()
|
|
|
|
warning = warning
|
|
|
|
auth_token.user_id = user_id
|
|
|
|
)
|
|
|
|
auth_token.expiration = datetime.max
|
|
|
|
else:
|
|
|
|
auth_token.auth_token = (hexlify(urandom(16))).decode("utf-8")
|
|
|
|
# Invalidate any prevously generated Kobo Auth token for this user.
|
|
|
|
auth_token.token_type = 1
|
|
|
|
auth_token = ub.session.query(ub.RemoteAuthToken).filter(
|
|
|
|
|
|
|
|
ub.RemoteAuthToken.user_id == user_id
|
|
|
|
ub.session.add(auth_token)
|
|
|
|
).filter(ub.RemoteAuthToken.token_type==1).first()
|
|
|
|
ub.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
if not auth_token:
|
|
|
|
return render_title_template(
|
|
|
|
auth_token = ub.RemoteAuthToken()
|
|
|
|
"generate_kobo_auth_url.html",
|
|
|
|
auth_token.user_id = user_id
|
|
|
|
title=_(u"Kobo Set-up"),
|
|
|
|
auth_token.expiration = datetime.max
|
|
|
|
kobo_auth_url=url_for(
|
|
|
|
auth_token.auth_token = (hexlify(urandom(16))).decode("utf-8")
|
|
|
|
"kobo.TopLevelEndpoint", auth_token=auth_token.auth_token, _external=True
|
|
|
|
auth_token.token_type = 1
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
ub.session.add(auth_token)
|
|
|
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
|
|
|
return render_title_template(
|
|
|
|
|
|
|
|
"generate_kobo_auth_url.html",
|
|
|
|
|
|
|
|
title=_(u"Kobo Set-up"),
|
|
|
|
|
|
|
|
kobo_auth_url=url_for(
|
|
|
|
|
|
|
|
"kobo.TopLevelEndpoint", auth_token=auth_token.auth_token, _external=True
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
warning = False
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@kobo_auth.route("/deleteauthtoken/<int:user_id>")
|
|
|
|
@kobo_auth.route("/deleteauthtoken/<int:user_id>")
|
|
|
|