Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
38f3c2d5
Commit
38f3c2d5
authored
Jul 21, 2019
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reenabled multiple oauth provider
deleted duplicate download counting function
parent
c6542fde
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
84 additions
and
166 deletions
+84
-166
admin.py
cps/admin.py
+21
-12
comic.py
cps/comic.py
+1
-1
config_sql.py
cps/config_sql.py
+1
-14
constants.py
cps/constants.py
+2
-2
helper.py
cps/helper.py
+0
-9
oauth.py
cps/oauth.py
+9
-8
oauth_bb.py
cps/oauth_bb.py
+35
-96
config_edit.html
cps/templates/config_edit.html
+4
-4
user_edit.html
cps/templates/user_edit.html
+4
-4
ub.py
cps/ub.py
+2
-11
uploader.py
cps/uploader.py
+5
-5
No files found.
cps/admin.py
View file @
38f3c2d5
...
...
@@ -344,18 +344,27 @@ def _configuration_update_helper():
_config_int
(
"config_updatechannel"
)
# GitHub OAuth configuration
if
config
.
config_login_type
==
constants
.
LOGIN_OAUTH_GITHUB
:
_config_string
(
"config_github_oauth_client_id"
)
_config_string
(
"config_github_oauth_client_secret"
)
if
not
config
.
config_github_oauth_client_id
or
not
config
.
config_github_oauth_client_secret
:
return
_configuration_result
(
'Please enter Github oauth credentials'
,
gdriveError
)
# Google OAuth configuration
if
config
.
config_login_type
==
constants
.
LOGIN_OAUTH_GOOGLE
:
_config_string
(
"config_google_oauth_client_id"
)
_config_string
(
"config_google_oauth_client_secret"
)
if
not
config
.
config_google_oauth_client_id
or
not
config
.
config_google_oauth_client_secret
:
return
_configuration_result
(
'Please enter Google oauth credentials'
,
gdriveError
)
if
config
.
config_login_type
==
constants
.
LOGIN_OAUTH
:
active_oauths
=
0
for
element
in
oauthblueprints
:
if
to_save
[
"config_"
+
str
(
element
[
'id'
])
+
"_oauth_client_id"
]
\
and
to_save
[
"config_"
+
str
(
element
[
'id'
])
+
"_oauth_client_secret"
]:
active_oauths
+=
1
element
[
"active"
]
=
1
ub
.
session
.
query
(
ub
.
OAuthProvider
)
.
filter
(
ub
.
OAuthProvider
.
id
==
element
[
'id'
])
.
update
(
{
"oauth_client_id"
:
to_save
[
"config_"
+
str
(
element
[
'id'
])
+
"_oauth_client_id"
],
"oauth_client_secret"
:
to_save
[
"config_"
+
str
(
element
[
'id'
])
+
"_oauth_client_secret"
],
"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_string
(
"config_logfile"
)
...
...
cps/comic.py
View file @
38f3c2d5
...
...
@@ -31,7 +31,7 @@ try:
from
comicapi.comicarchive
import
ComicArchive
,
MetaDataStyle
use_comic_meta
=
True
except
ImportError
as
e
:
log
.
warnin
g
(
'cannot import comicapi, extracting comic metadata will not work:
%
s'
,
e
)
log
.
debu
g
(
'cannot import comicapi, extracting comic metadata will not work:
%
s'
,
e
)
import
zipfile
import
tarfile
use_comic_meta
=
False
...
...
cps/config_sql.py
View file @
38f3c2d5
...
...
@@ -84,11 +84,7 @@ class _Settings(_Base):
config_login_type
=
Column
(
Integer
,
default
=
0
)
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_oauth_provider = Column(Integer)
config_ldap_provider_url
=
Column
(
String
,
default
=
'localhost'
)
config_ldap_port
=
Column
(
SmallInteger
,
default
=
389
)
...
...
@@ -310,12 +306,3 @@ def load_configuration(session):
session
.
commit
()
return
_ConfigSQL
(
session
)
def
load_oauth
(
session
):
#_migrate_database(session)
if
not
session
.
query
(
OAuthProvider
)
.
count
():
session
.
add
(
_Settings
())
session
.
commit
()
return
_ConfigSQL
(
session
)
cps/constants.py
View file @
38f3c2d5
...
...
@@ -91,8 +91,8 @@ AUTO_UPDATE_NIGHTLY = 1 << 2
LOGIN_STANDARD
=
0
LOGIN_LDAP
=
1
LOGIN_OAUTH
_GITHUB
=
2
LOGIN_OAUTH_GOOGLE
=
3
LOGIN_OAUTH
=
2
#
LOGIN_OAUTH_GOOGLE = 3
DEFAULT_PASSWORD
=
"admin123"
...
...
cps/helper.py
View file @
38f3c2d5
...
...
@@ -71,15 +71,6 @@ from .worker import TASK_EMAIL, TASK_CONVERT, TASK_UPLOAD, TASK_CONVERT_ANY
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
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
()
...
...
cps/oauth.py
View file @
38f3c2d5
...
...
@@ -32,13 +32,14 @@ try:
.. _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
,
cache
=
None
):
self
.
provider_id
=
provider_id
super
(
OAuthBackend
,
self
)
.
__init__
(
model
,
session
,
user
,
user_id
,
user_required
,
anon_user
,
cache
)
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'
]
# check cache
cache_key
=
self
.
make_cache_key
(
blueprint
=
blueprint
,
user
=
user
,
user_id
=
user_id
)
...
...
@@ -49,15 +50,15 @@ try:
# if not cached, make database queries
query
=
(
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"
)])
u
=
first
(
_get_real_user
(
ref
,
self
.
anon_user
)
for
ref
in
(
user
,
self
.
user
,
blueprint
.
config
.
get
(
"user"
)))
use_provider_user_id
=
False
if
blueprint
.
name
+
'_oauth_user_id'
in
session
and
session
[
blueprint
.
name
+
'_oauth_user_id'
]
!=
''
:
query
=
query
.
filter_by
(
provider_user_id
=
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
[
self
.
provider_id
+
'_oauth_user_id'
])
use_provider_user_id
=
True
if
self
.
user_required
and
not
u
and
not
uid
and
not
use_provider_user_id
:
...
...
@@ -94,7 +95,7 @@ try:
# if there was an existing model, delete it
existing_query
=
(
self
.
session
.
query
(
self
.
model
)
.
filter_by
(
provider
=
blueprint
.
name
)
.
filter_by
(
provider
=
self
.
provider_id
)
)
# check for user ID
has_user_id
=
hasattr
(
self
.
model
,
"user_id"
)
...
...
@@ -108,7 +109,7 @@ try:
existing_query
.
delete
()
# create a new model for this token
kwargs
=
{
"provider"
:
blueprint
.
name
,
"provider"
:
self
.
provider_id
,
"token"
:
token
,
}
if
has_user_id
and
uid
:
...
...
@@ -126,7 +127,7 @@ try:
def
delete
(
self
,
blueprint
,
user
=
None
,
user_id
=
None
):
query
=
(
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"
)])
u
=
first
(
_get_real_user
(
ref
,
self
.
anon_user
)
...
...
cps/oauth_bb.py
View file @
38f3c2d5
This diff is collapsed.
Click to expand it.
cps/templates/config_edit.html
View file @
38f3c2d5
...
...
@@ -260,12 +260,12 @@
<a
href=
"{{prov['obtain_link']}}"
target=
"_blank"
>
{{_('Obtain %(provider)s OAuth Credential', provider=prov['provider_name'])}}
</a>
</div>
<div
class=
"form-group"
>
<label
for=
"config_{{ prov['
provider_name
'] }}_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"
>
<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['
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
class=
"form-group"
>
<label
for=
"config_{{ prov['
provider_name
'] }}_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"
>
<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['
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>
{% endfor %}
</div>
...
...
cps/templates/user_edit.html
View file @
38f3c2d5
...
...
@@ -47,13 +47,13 @@
</div>
{% if registered_oauth.keys()| length > 0 %}
{% for
oauth, name in registered_oauth.iter
items() %}
{% for
id, name in registered_oauth.
items() %}
<div
class=
"form-group"
>
<label>
{{ name }} {{_('OAuth Settings')}}
</label>
{% if
oauth
not in oauth_status %}
<div><a
href=
"{{ url_for(
oauth +'.login') }}"
id=
"config_{{ oauth
}}_oauth"
class=
"btn btn-primary"
>
{{_('Link')}}
</a></div>
{% if
id
not in oauth_status %}
<div><a
href=
"{{ url_for(
'oauth.'+ name +'_login') }}"
id=
"config_{{ id
}}_oauth"
class=
"btn btn-primary"
>
{{_('Link')}}
</a></div>
{% 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 %}
{% endfor %}
</div>
...
...
cps/ub.py
View file @
38f3c2d5
...
...
@@ -180,12 +180,14 @@ class User(UserBase, Base):
default_language
=
Column
(
String
(
3
),
default
=
"all"
)
mature_content
=
Column
(
Boolean
,
default
=
True
)
if
oauth_support
:
class
OAuth
(
OAuthConsumerMixin
,
Base
):
provider_user_id
=
Column
(
String
(
256
))
user_id
=
Column
(
Integer
,
ForeignKey
(
User
.
id
))
user
=
relationship
(
User
)
class
OAuthProvider
(
Base
):
__tablename__
=
'oauthProvider'
...
...
@@ -194,17 +196,6 @@ class OAuthProvider(Base):
oauth_client_id
=
Column
(
String
)
oauth_client_secret
=
Column
(
String
)
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
...
...
cps/uploader.py
View file @
38f3c2d5
...
...
@@ -42,7 +42,7 @@ try:
from
wand.exceptions
import
PolicyError
use_generic_pdf_cover
=
False
except
(
ImportError
,
RuntimeError
)
as
e
:
log
.
warnin
g
(
'cannot import Image, generating pdf covers for pdf uploads will not work:
%
s'
,
e
)
log
.
debu
g
(
'cannot import Image, generating pdf covers for pdf uploads will not work:
%
s'
,
e
)
use_generic_pdf_cover
=
True
try
:
...
...
@@ -50,21 +50,21 @@ try:
from
PyPDF2
import
__version__
as
PyPdfVersion
use_pdf_meta
=
True
except
ImportError
as
e
:
log
.
warnin
g
(
'cannot import PyPDF2, extracting pdf metadata will not work:
%
s'
,
e
)
log
.
debu
g
(
'cannot import PyPDF2, extracting pdf metadata will not work:
%
s'
,
e
)
use_pdf_meta
=
False
try
:
from
.
import
epub
use_epub_meta
=
True
except
ImportError
as
e
:
log
.
warnin
g
(
'cannot import epub, extracting epub metadata will not work:
%
s'
,
e
)
log
.
debu
g
(
'cannot import epub, extracting epub metadata will not work:
%
s'
,
e
)
use_epub_meta
=
False
try
:
from
.
import
fb2
use_fb2_meta
=
True
except
ImportError
as
e
:
log
.
warnin
g
(
'cannot import fb2, extracting fb2 metadata will not work:
%
s'
,
e
)
log
.
debu
g
(
'cannot import fb2, extracting fb2 metadata will not work:
%
s'
,
e
)
use_fb2_meta
=
False
try
:
...
...
@@ -72,7 +72,7 @@ try:
from
PIL
import
__version__
as
PILversion
use_PIL
=
True
except
ImportError
as
e
:
log
.
warnin
g
(
'cannot import Pillow, using png and webp images as cover will not work:
%
s'
,
e
)
log
.
debu
g
(
'cannot import Pillow, using png and webp images as cover will not work:
%
s'
,
e
)
use_generic_pdf_cover
=
True
use_PIL
=
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment