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
e6bcdba5
Commit
e6bcdba5
authored
May 01, 2024
by
Timothy J. Baek
Browse files
feat: add user from admin panel
parent
96af34f2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
8 deletions
+36
-8
backend/apps/web/models/auths.py
backend/apps/web/models/auths.py
+1
-1
backend/apps/web/routers/auths.py
backend/apps/web/routers/auths.py
+3
-2
src/lib/apis/auths/index.ts
src/lib/apis/auths/index.ts
+3
-2
src/lib/components/admin/AddUserModal.svelte
src/lib/components/admin/AddUserModal.svelte
+28
-2
src/lib/components/layout/Sidebar/ArchivedChatsModal.svelte
src/lib/components/layout/Sidebar/ArchivedChatsModal.svelte
+1
-1
No files found.
backend/apps/web/models/auths.py
View file @
e6bcdba5
...
@@ -90,7 +90,7 @@ class SignupForm(BaseModel):
...
@@ -90,7 +90,7 @@ class SignupForm(BaseModel):
class
AddUserForm
(
SignupForm
):
class
AddUserForm
(
SignupForm
):
role
:
str
=
"pending"
role
:
Optional
[
str
]
=
"pending"
class
AuthsTable
:
class
AuthsTable
:
...
...
backend/apps/web/routers/auths.py
View file @
e6bcdba5
...
@@ -223,14 +223,15 @@ async def signup(form_data: AddUserForm, user=Depends(get_admin_user)):
...
@@ -223,14 +223,15 @@ async def signup(form_data: AddUserForm, user=Depends(get_admin_user)):
raise
HTTPException
(
400
,
detail
=
ERROR_MESSAGES
.
EMAIL_TAKEN
)
raise
HTTPException
(
400
,
detail
=
ERROR_MESSAGES
.
EMAIL_TAKEN
)
try
:
try
:
role
=
form_data
.
role
print
(
form_data
)
hashed
=
get_password_hash
(
form_data
.
password
)
hashed
=
get_password_hash
(
form_data
.
password
)
user
=
Auths
.
insert_new_auth
(
user
=
Auths
.
insert_new_auth
(
form_data
.
email
.
lower
(),
form_data
.
email
.
lower
(),
hashed
,
hashed
,
form_data
.
name
,
form_data
.
name
,
form_data
.
profile_image_url
,
form_data
.
profile_image_url
,
role
,
form_data
.
role
,
)
)
if
user
:
if
user
:
...
...
src/lib/apis/auths/index.ts
View file @
e6bcdba5
...
@@ -100,14 +100,15 @@ export const addUser = async (
...
@@ -100,14 +100,15 @@ export const addUser = async (
name
:
string
,
name
:
string
,
email
:
string
,
email
:
string
,
password
:
string
,
password
:
string
,
role
:
string
role
:
string
=
'
pending
'
)
=>
{
)
=>
{
let
error
=
null
;
let
error
=
null
;
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/auths/add`
,
{
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/auths/add`
,
{
method
:
'
POST
'
,
method
:
'
POST
'
,
headers
:
{
headers
:
{
'
Content-Type
'
:
'
application/json
'
'
Content-Type
'
:
'
application/json
'
,
...(
token
&&
{
authorization
:
`Bearer
${
token
}
`
})
},
},
body
:
JSON
.
stringify
({
body
:
JSON
.
stringify
({
name
:
name
,
name
:
name
,
...
...
src/lib/components/admin/AddUserModal.svelte
View file @
e6bcdba5
...
@@ -15,9 +15,18 @@
...
@@ -15,9 +15,18 @@
name: '',
name: '',
email: '',
email: '',
password: '',
password: '',
role: ''
role: '
pending
'
};
};
$: if (show) {
_user = {
name: '',
email: '',
password: '',
role: 'pending'
};
}
const submitHandler = async () => {
const submitHandler = async () => {
const res = await addUser(
const res = await addUser(
localStorage.token,
localStorage.token,
...
@@ -38,7 +47,7 @@
...
@@ -38,7 +47,7 @@
<Modal size="sm" bind:show>
<Modal size="sm" bind:show>
<div>
<div>
<div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-
3
">
<div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-
2
">
<div class=" text-lg font-medium self-center">{$i18n.t('Add User')}</div>
<div class=" text-lg font-medium self-center">{$i18n.t('Add User')}</div>
<button
<button
class="self-center"
class="self-center"
...
@@ -69,6 +78,23 @@
...
@@ -69,6 +78,23 @@
>
>
<div class=" ">
<div class=" ">
<div class="flex flex-col w-full">
<div class="flex flex-col w-full">
<div class=" mb-1 text-xs text-gray-500">{$i18n.t('Role')}</div>
<div class="flex-1">
<select
class="w-full capitalize rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 disabled:text-gray-500 dark:disabled:text-gray-500 outline-none"
bind:value={_user.role}
placeholder={$i18n.t('Enter Your Role')}
required
>
<option value="pending"> pending </option>
<option value="user"> user </option>
<option value="admin"> admin </option>
</select>
</div>
</div>
<div class="flex flex-col w-full mt-2">
<div class=" mb-1 text-xs text-gray-500">{$i18n.t('Name')}</div>
<div class=" mb-1 text-xs text-gray-500">{$i18n.t('Name')}</div>
<div class="flex-1">
<div class="flex-1">
...
...
src/lib/components/layout/Sidebar/ArchivedChatsModal.svelte
View file @
e6bcdba5
...
@@ -63,7 +63,7 @@
...
@@ -63,7 +63,7 @@
</button>
</button>
</div>
</div>
<div class="flex flex-col md:flex-row w-full px-5 p
y
-4 md:space-x-4 dark:text-gray-200">
<div class="flex flex-col md:flex-row w-full px-5 p
b
-4 md:space-x-4 dark:text-gray-200">
<div class=" flex flex-col w-full sm:flex-row sm:justify-center sm:space-x-6">
<div class=" flex flex-col w-full sm:flex-row sm:justify-center sm:space-x-6">
{#if chats.length > 0}
{#if chats.length > 0}
<div class="text-left text-sm w-full mb-4 max-h-[22rem] overflow-y-scroll">
<div class="text-left text-sm w-full mb-4 max-h-[22rem] overflow-y-scroll">
...
...
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