Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
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
ai-tech
dify
Commits
3d194787
Unverified
Commit
3d194787
authored
Aug 08, 2023
by
crazywoola
Committed by
GitHub
Aug 08, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix/disable site when change code (#775)
parent
a8d5ef98
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
4 deletions
+9
-4
passport.py
api/controllers/web/passport.py
+4
-3
wraps.py
api/controllers/web/wraps.py
+5
-1
No files found.
api/controllers/web/passport.py
View file @
3d194787
...
...
@@ -11,13 +11,13 @@ from libs.passport import PassportService
class
PassportResource
(
Resource
):
"""Base resource for passport."""
def
get
(
self
):
app_
id
=
request
.
headers
.
get
(
'X-App-Code'
)
if
app_
id
is
None
:
app_
code
=
request
.
headers
.
get
(
'X-App-Code'
)
if
app_
code
is
None
:
raise
Unauthorized
(
'X-App-Code header is missing.'
)
# get site from db and check if it is normal
site
=
db
.
session
.
query
(
Site
)
.
filter
(
Site
.
code
==
app_
id
,
Site
.
code
==
app_
code
,
Site
.
status
==
'normal'
)
.
first
()
if
not
site
:
...
...
@@ -41,6 +41,7 @@ class PassportResource(Resource):
"iss"
:
site
.
app_id
,
'sub'
:
'Web API Passport'
,
'app_id'
:
site
.
app_id
,
'app_code'
:
app_code
,
'end_user_id'
:
end_user
.
id
,
}
...
...
api/controllers/web/wraps.py
View file @
3d194787
...
...
@@ -6,7 +6,7 @@ from flask_restful import Resource
from
werkzeug.exceptions
import
NotFound
,
Unauthorized
from
extensions.ext_database
import
db
from
models.model
import
App
,
EndUser
from
models.model
import
App
,
EndUser
,
Site
from
libs.passport
import
PassportService
def
validate_jwt_token
(
view
=
None
):
...
...
@@ -35,9 +35,13 @@ def decode_jwt_token():
if
auth_scheme
!=
'bearer'
:
raise
Unauthorized
(
'Invalid Authorization header format. Expected
\'
Bearer <api-key>
\'
format.'
)
decoded
=
PassportService
()
.
verify
(
tk
)
app_model
=
db
.
session
.
query
(
App
)
.
filter
(
App
.
id
==
decoded
[
'app_id'
])
.
first
()
site
=
db
.
session
.
query
(
Site
)
.
filter
(
Site
.
code
==
decoded
[
'app_code'
])
.
first
()
if
not
app_model
:
raise
NotFound
()
if
not
site
:
raise
Unauthorized
(
'Site URL is no longer valid.'
)
if
app_model
.
enable_site
is
False
:
raise
Unauthorized
(
'Site is disabled.'
)
end_user
=
db
.
session
.
query
(
EndUser
)
.
filter
(
EndUser
.
id
==
decoded
[
'end_user_id'
])
.
first
()
...
...
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