Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
da8646ca
Commit
da8646ca
authored
Apr 02, 2024
by
Timothy J. Baek
Browse files
refac
parent
ba0523cd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
19 deletions
+19
-19
backend/apps/web/models/auths.py
backend/apps/web/models/auths.py
+0
-16
backend/apps/web/models/users.py
backend/apps/web/models/users.py
+16
-0
backend/apps/web/routers/auths.py
backend/apps/web/routers/auths.py
+3
-3
No files found.
backend/apps/web/models/auths.py
View file @
da8646ca
...
...
@@ -167,22 +167,6 @@ class AuthsTable:
except
:
return
False
def
update_api_key_by_id
(
self
,
id
:
str
,
api_key
:
str
)
->
str
:
try
:
query
=
Auth
.
update
(
api_key
=
api_key
).
where
(
Auth
.
id
==
id
)
result
=
query
.
execute
()
return
True
if
result
==
1
else
False
except
:
return
False
def
get_api_key_by_id
(
self
,
id
:
str
)
->
Optional
[
str
]:
try
:
auth
=
Auth
.
get
(
Auth
.
id
==
id
)
return
auth
.
api_key
except
:
return
None
def
delete_auth_by_id
(
self
,
id
:
str
)
->
bool
:
try
:
# Delete User
...
...
backend/apps/web/models/users.py
View file @
da8646ca
...
...
@@ -158,5 +158,21 @@ class UsersTable:
except
:
return
False
def
update_user_api_key_by_id
(
self
,
id
:
str
,
api_key
:
str
)
->
str
:
try
:
query
=
User
.
update
(
api_key
=
api_key
).
where
(
User
.
id
==
id
)
result
=
query
.
execute
()
return
True
if
result
==
1
else
False
except
:
return
False
def
get_user_api_key_by_id
(
self
,
id
:
str
)
->
Optional
[
str
]:
try
:
user
=
User
.
get
(
User
.
id
==
id
)
return
user
.
api_key
except
:
return
None
Users
=
UsersTable
(
DB
)
backend/apps/web/routers/auths.py
View file @
da8646ca
...
...
@@ -277,7 +277,7 @@ async def update_token_expires_duration(
@
router
.
post
(
"/api_key"
,
response_model
=
ApiKey
)
async
def
create_api_key_
(
user
=
Depends
(
get_current_user
)):
api_key
=
create_api_key
()
success
=
Auth
s
.
update_api_key_by_id
(
user
.
id
,
api_key
)
success
=
User
s
.
update_
user_
api_key_by_id
(
user
.
id
,
api_key
)
if
success
:
return
{
"api_key"
:
api_key
,
...
...
@@ -289,14 +289,14 @@ async def create_api_key_(user=Depends(get_current_user)):
# delete api key
@
router
.
delete
(
"/api_key"
,
response_model
=
bool
)
async
def
delete_api_key
(
user
=
Depends
(
get_current_user
)):
success
=
Auth
s
.
update_api_key_by_id
(
user
.
id
,
None
)
success
=
User
s
.
update_
user_
api_key_by_id
(
user
.
id
,
None
)
return
success
# get api key
@
router
.
get
(
"/api_key"
,
response_model
=
ApiKey
)
async
def
get_api_key
(
user
=
Depends
(
get_current_user
)):
api_key
=
Auth
s
.
get_api_key_by_id
(
user
.
id
,
None
)
api_key
=
User
s
.
get_
user_
api_key_by_id
(
user
.
id
)
if
api_key
:
return
{
"api_key"
:
api_key
,
...
...
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