Commit 38f3c2d5 authored by Ozzieisaacs's avatar Ozzieisaacs

Reenabled multiple oauth provider

deleted duplicate download counting function
parent c6542fde
...@@ -344,18 +344,27 @@ def _configuration_update_helper(): ...@@ -344,18 +344,27 @@ def _configuration_update_helper():
_config_int("config_updatechannel") _config_int("config_updatechannel")
# GitHub OAuth configuration # GitHub OAuth configuration
if config.config_login_type == constants.LOGIN_OAUTH_GITHUB: if config.config_login_type == constants.LOGIN_OAUTH:
_config_string("config_github_oauth_client_id") active_oauths = 0
_config_string("config_github_oauth_client_secret")
if not config.config_github_oauth_client_id or not config.config_github_oauth_client_secret: for element in oauthblueprints:
return _configuration_result('Please enter Github oauth credentials', gdriveError) if to_save["config_"+str(element['id'])+"_oauth_client_id"] \
and to_save["config_"+str(element['id'])+"_oauth_client_secret"]:
# Google OAuth configuration active_oauths += 1
if config.config_login_type == constants.LOGIN_OAUTH_GOOGLE: element["active"] = 1
_config_string("config_google_oauth_client_id") ub.session.query(ub.OAuthProvider).filter(ub.OAuthProvider.id == element['id']).update(
_config_string("config_google_oauth_client_secret") {"oauth_client_id":to_save["config_"+str(element['id'])+"_oauth_client_id"],
if not config.config_google_oauth_client_id or not config.config_google_oauth_client_secret: "oauth_client_secret":to_save["config_"+str(element['id'])+"_oauth_client_secret"],
return _configuration_result('Please enter Google oauth credentials', gdriveError) "active":1})
if to_save["config_" + str(element['id']) + "_oauth_client_id"] != element['oauth_client_id'] \
or to_save["config_" + str(element['id']) + "_oauth_client_secret"] != element['oauth_client_secret']:
reboot_required = True
element['oauth_client_id'] = to_save["config_"+str(element['id'])+"_oauth_client_id"]
element['oauth_client_secret'] = to_save["config_"+str(element['id'])+"_oauth_client_secret"]
else:
ub.session.query(ub.OAuthProvider).filter(ub.OAuthProvider.id == element['id']).update(
{"active":0})
element["active"] = 0
_config_int("config_log_level") _config_int("config_log_level")
_config_string("config_logfile") _config_string("config_logfile")
......
...@@ -31,7 +31,7 @@ try: ...@@ -31,7 +31,7 @@ try:
from comicapi.comicarchive import ComicArchive, MetaDataStyle from comicapi.comicarchive import ComicArchive, MetaDataStyle
use_comic_meta = True use_comic_meta = True
except ImportError as e: except ImportError as e:
log.warning('cannot import comicapi, extracting comic metadata will not work: %s', e) log.debug('cannot import comicapi, extracting comic metadata will not work: %s', e)
import zipfile import zipfile
import tarfile import tarfile
use_comic_meta = False use_comic_meta = False
......
...@@ -84,11 +84,7 @@ class _Settings(_Base): ...@@ -84,11 +84,7 @@ class _Settings(_Base):
config_login_type = Column(Integer, default=0) config_login_type = Column(Integer, default=0)
config_oauth_provider = Column(Integer) # config_oauth_provider = Column(Integer)
#config_github_oauth_client_id = Column(String)
#config_github_oauth_client_secret = Column(String)
#config_google_oauth_client_id = Column(String)
#config_google_oauth_client_secret = Column(String)
config_ldap_provider_url = Column(String, default='localhost') config_ldap_provider_url = Column(String, default='localhost')
config_ldap_port = Column(SmallInteger, default=389) config_ldap_port = Column(SmallInteger, default=389)
...@@ -310,12 +306,3 @@ def load_configuration(session): ...@@ -310,12 +306,3 @@ def load_configuration(session):
session.commit() session.commit()
return _ConfigSQL(session) return _ConfigSQL(session)
def load_oauth(session):
#_migrate_database(session)
if not session.query(OAuthProvider).count():
session.add(_Settings())
session.commit()
return _ConfigSQL(session)
...@@ -91,8 +91,8 @@ AUTO_UPDATE_NIGHTLY = 1 << 2 ...@@ -91,8 +91,8 @@ AUTO_UPDATE_NIGHTLY = 1 << 2
LOGIN_STANDARD = 0 LOGIN_STANDARD = 0
LOGIN_LDAP = 1 LOGIN_LDAP = 1
LOGIN_OAUTH_GITHUB = 2 LOGIN_OAUTH = 2
LOGIN_OAUTH_GOOGLE = 3 # LOGIN_OAUTH_GOOGLE = 3
DEFAULT_PASSWORD = "admin123" DEFAULT_PASSWORD = "admin123"
......
...@@ -71,15 +71,6 @@ from .worker import TASK_EMAIL, TASK_CONVERT, TASK_UPLOAD, TASK_CONVERT_ANY ...@@ -71,15 +71,6 @@ from .worker import TASK_EMAIL, TASK_CONVERT, TASK_UPLOAD, TASK_CONVERT_ANY
log = logger.create() log = logger.create()
# ToDo delete duplicate
def update_download(book_id, user_id):
check = ub.session.query(ub.Downloads).filter(ub.Downloads.user_id == user_id).filter(ub.Downloads.book_id ==
book_id).first()
if not check:
new_download = ub.Downloads(user_id=user_id, book_id=book_id)
ub.session.add(new_download)
ub.session.commit()
# Convert existing book entry to new format # Convert existing book entry to new format
def convert_book_format(book_id, calibrepath, old_book_format, new_book_format, user_id, kindle_mail=None): def convert_book_format(book_id, calibrepath, old_book_format, new_book_format, user_id, kindle_mail=None):
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()
......
...@@ -32,13 +32,14 @@ try: ...@@ -32,13 +32,14 @@ try:
.. _SQLAlchemy: http://www.sqlalchemy.org/ .. _SQLAlchemy: http://www.sqlalchemy.org/
""" """
def __init__(self, model, session, def __init__(self, model, session, provider_id,
user=None, user_id=None, user_required=None, anon_user=None, user=None, user_id=None, user_required=None, anon_user=None,
cache=None): cache=None):
self.provider_id = provider_id
super(OAuthBackend, self).__init__(model, session, user, user_id, user_required, anon_user, cache) super(OAuthBackend, self).__init__(model, session, user, user_id, user_required, anon_user, cache)
def get(self, blueprint, user=None, user_id=None): def get(self, blueprint, user=None, user_id=None):
if blueprint.name + '_oauth_token' in session and session[blueprint.name + '_oauth_token'] != '': if self.provider_id + '_oauth_token' in session and session[self.provider_id + '_oauth_token'] != '':
return session[blueprint.name + '_oauth_token'] return session[blueprint.name + '_oauth_token']
# check cache # check cache
cache_key = self.make_cache_key(blueprint=blueprint, user=user, user_id=user_id) cache_key = self.make_cache_key(blueprint=blueprint, user=user, user_id=user_id)
...@@ -49,15 +50,15 @@ try: ...@@ -49,15 +50,15 @@ try:
# if not cached, make database queries # if not cached, make database queries
query = ( query = (
self.session.query(self.model) self.session.query(self.model)
.filter_by(provider=blueprint.name) .filter_by(provider=self.provider_id)
) )
uid = first([user_id, self.user_id, blueprint.config.get("user_id")]) uid = first([user_id, self.user_id, blueprint.config.get("user_id")])
u = first(_get_real_user(ref, self.anon_user) u = first(_get_real_user(ref, self.anon_user)
for ref in (user, self.user, blueprint.config.get("user"))) for ref in (user, self.user, blueprint.config.get("user")))
use_provider_user_id = False use_provider_user_id = False
if blueprint.name + '_oauth_user_id' in session and session[blueprint.name + '_oauth_user_id'] != '': if self.provider_id + '_oauth_user_id' in session and session[self.provider_id + '_oauth_user_id'] != '':
query = query.filter_by(provider_user_id=session[blueprint.name + '_oauth_user_id']) query = query.filter_by(provider_user_id=session[self.provider_id + '_oauth_user_id'])
use_provider_user_id = True use_provider_user_id = True
if self.user_required and not u and not uid and not use_provider_user_id: if self.user_required and not u and not uid and not use_provider_user_id:
...@@ -94,7 +95,7 @@ try: ...@@ -94,7 +95,7 @@ try:
# if there was an existing model, delete it # if there was an existing model, delete it
existing_query = ( existing_query = (
self.session.query(self.model) self.session.query(self.model)
.filter_by(provider=blueprint.name) .filter_by(provider=self.provider_id)
) )
# check for user ID # check for user ID
has_user_id = hasattr(self.model, "user_id") has_user_id = hasattr(self.model, "user_id")
...@@ -108,7 +109,7 @@ try: ...@@ -108,7 +109,7 @@ try:
existing_query.delete() existing_query.delete()
# create a new model for this token # create a new model for this token
kwargs = { kwargs = {
"provider": blueprint.name, "provider": self.provider_id,
"token": token, "token": token,
} }
if has_user_id and uid: if has_user_id and uid:
...@@ -126,7 +127,7 @@ try: ...@@ -126,7 +127,7 @@ try:
def delete(self, blueprint, user=None, user_id=None): def delete(self, blueprint, user=None, user_id=None):
query = ( query = (
self.session.query(self.model) self.session.query(self.model)
.filter_by(provider=blueprint.name) .filter_by(provider=self.provider_id)
) )
uid = first([user_id, self.user_id, blueprint.config.get("user_id")]) uid = first([user_id, self.user_id, blueprint.config.get("user_id")])
u = first(_get_real_user(ref, self.anon_user) u = first(_get_real_user(ref, self.anon_user)
......
This diff is collapsed.
...@@ -260,12 +260,12 @@ ...@@ -260,12 +260,12 @@
<a href="{{prov['obtain_link']}}" target="_blank">{{_('Obtain %(provider)s OAuth Credential', provider=prov['provider_name'])}}</a> <a href="{{prov['obtain_link']}}" target="_blank">{{_('Obtain %(provider)s OAuth Credential', provider=prov['provider_name'])}}</a>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="config_{{ prov['provider_name'] }}_oauth_client_id">{{_('%(provider)s OAuth Client Id', provider=prov['provider_name'])}}</label> <label for="config_{{ prov['id'] }}_oauth_client_id">{{_('%(provider)s OAuth Client Id', provider=prov['provider_name'])}}</label>
<input type="text" class="form-control" id="config_{{ prov['provider_name'] }}_oauth_client_id" name="config_{{ prov['provider_name'] }}_oauth_client_id" value="{% if prov['active'] %}{{ prov['oauth_client_id'] }}{% endif %}" autocomplete="off"> <input type="text" class="form-control" id="config_{{ prov['id'] }}_oauth_client_id" name="config_{{ prov['id'] }}_oauth_client_id" value="{% if prov['oauth_client_id']%}{{ prov['oauth_client_id'] }}{% endif %}" autocomplete="off">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="config_{{ prov['provider_name'] }}_oauth_client_secret">{{_('%(provider)s OAuth Client Secret', provider=prov['provider_name'])}}</label> <label for="config_{{ prov['id'] }}_oauth_client_secret">{{_('%(provider)s OAuth Client Secret', provider=prov['provider_name'])}}</label>
<input type="text" class="form-control" id="config_{{ prov['provider_name'] }}_oauth_client_secret" name="config_{{ prov['provider_name'] }}_oauth_client_secret" value="{% if prov['active'] %}{{ prov['oauth_client_id'] }}{% endif %}" autocomplete="off"> <input type="text" class="form-control" id="config_{{ prov['id'] }}_oauth_client_secret" name="config_{{ prov['id'] }}_oauth_client_secret" value="{% if prov['oauth_client_secret']%}{{ prov['oauth_client_secret'] }}{% endif %}" autocomplete="off">
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
......
...@@ -47,13 +47,13 @@ ...@@ -47,13 +47,13 @@
</div> </div>
{% if registered_oauth.keys()| length > 0 %} {% if registered_oauth.keys()| length > 0 %}
{% for oauth, name in registered_oauth.iteritems() %} {% for id, name in registered_oauth.items() %}
<div class="form-group"> <div class="form-group">
<label>{{ name }} {{_('OAuth Settings')}}</label> <label>{{ name }} {{_('OAuth Settings')}}</label>
{% if oauth not in oauth_status %} {% if id not in oauth_status %}
<div><a href="{{ url_for(oauth +'.login') }}" id="config_{{ oauth }}_oauth" class="btn btn-primary">{{_('Link')}}</a></div> <div><a href="{{ url_for('oauth.'+ name +'_login') }}" id="config_{{ id }}_oauth" class="btn btn-primary">{{_('Link')}}</a></div>
{% else %} {% else %}
<div><a href="{{ url_for('oauth.'+ oauth +'_login_unlink') }}" id="config_{{ oauth }}_oauth" class="btn btn-primary">{{_('Unlink')}}</a></div> <div><a href="{{ url_for('oauth.'+ name +'_login_unlink') }}" id="config_{{ id }}_oauth" class="btn btn-primary">{{_('Unlink')}}</a></div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
......
...@@ -180,12 +180,14 @@ class User(UserBase, Base): ...@@ -180,12 +180,14 @@ class User(UserBase, Base):
default_language = Column(String(3), default="all") default_language = Column(String(3), default="all")
mature_content = Column(Boolean, default=True) mature_content = Column(Boolean, default=True)
if oauth_support: if oauth_support:
class OAuth(OAuthConsumerMixin, Base): class OAuth(OAuthConsumerMixin, Base):
provider_user_id = Column(String(256)) provider_user_id = Column(String(256))
user_id = Column(Integer, ForeignKey(User.id)) user_id = Column(Integer, ForeignKey(User.id))
user = relationship(User) user = relationship(User)
class OAuthProvider(Base): class OAuthProvider(Base):
__tablename__ = 'oauthProvider' __tablename__ = 'oauthProvider'
...@@ -194,17 +196,6 @@ class OAuthProvider(Base): ...@@ -194,17 +196,6 @@ class OAuthProvider(Base):
oauth_client_id = Column(String) oauth_client_id = Column(String)
oauth_client_secret = Column(String) oauth_client_secret = Column(String)
active = Column(Boolean) active = Column(Boolean)
# scope = relationship('OAuthScope', backref='oauthProvider')
'''class OAuthScope(Base):
__tablename__ = 'oauthScope'
id = Column(Integer, primary_key=True)
scope = Column(String, unique=True)
provider_id = Column(Integer, ForeignKey('oauthProvider.id'))
def __repr__(self):
return u"{0}".format(self.scope)'''
# Class for anonymous user is derived from User base and completly overrides methods and properties for the # Class for anonymous user is derived from User base and completly overrides methods and properties for the
......
...@@ -42,7 +42,7 @@ try: ...@@ -42,7 +42,7 @@ try:
from wand.exceptions import PolicyError from wand.exceptions import PolicyError
use_generic_pdf_cover = False use_generic_pdf_cover = False
except (ImportError, RuntimeError) as e: except (ImportError, RuntimeError) as e:
log.warning('cannot import Image, generating pdf covers for pdf uploads will not work: %s', e) log.debug('cannot import Image, generating pdf covers for pdf uploads will not work: %s', e)
use_generic_pdf_cover = True use_generic_pdf_cover = True
try: try:
...@@ -50,21 +50,21 @@ try: ...@@ -50,21 +50,21 @@ try:
from PyPDF2 import __version__ as PyPdfVersion from PyPDF2 import __version__ as PyPdfVersion
use_pdf_meta = True use_pdf_meta = True
except ImportError as e: except ImportError as e:
log.warning('cannot import PyPDF2, extracting pdf metadata will not work: %s', e) log.debug('cannot import PyPDF2, extracting pdf metadata will not work: %s', e)
use_pdf_meta = False use_pdf_meta = False
try: try:
from . import epub from . import epub
use_epub_meta = True use_epub_meta = True
except ImportError as e: except ImportError as e:
log.warning('cannot import epub, extracting epub metadata will not work: %s', e) log.debug('cannot import epub, extracting epub metadata will not work: %s', e)
use_epub_meta = False use_epub_meta = False
try: try:
from . import fb2 from . import fb2
use_fb2_meta = True use_fb2_meta = True
except ImportError as e: except ImportError as e:
log.warning('cannot import fb2, extracting fb2 metadata will not work: %s', e) log.debug('cannot import fb2, extracting fb2 metadata will not work: %s', e)
use_fb2_meta = False use_fb2_meta = False
try: try:
...@@ -72,7 +72,7 @@ try: ...@@ -72,7 +72,7 @@ try:
from PIL import __version__ as PILversion from PIL import __version__ as PILversion
use_PIL = True use_PIL = True
except ImportError as e: except ImportError as e:
log.warning('cannot import Pillow, using png and webp images as cover will not work: %s', e) log.debug('cannot import Pillow, using png and webp images as cover will not work: %s', e)
use_generic_pdf_cover = True use_generic_pdf_cover = True
use_PIL = False use_PIL = False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment