forked from open-webui/open-webui
feat: add user from admin panel
This commit is contained in:
parent
96af34f240
commit
e6bcdba5ad
5 changed files with 36 additions and 8 deletions
|
@ -90,7 +90,7 @@ class SignupForm(BaseModel):
|
|||
|
||||
|
||||
class AddUserForm(SignupForm):
|
||||
role: str = "pending"
|
||||
role: Optional[str] = "pending"
|
||||
|
||||
|
||||
class AuthsTable:
|
||||
|
|
|
@ -223,14 +223,15 @@ async def signup(form_data: AddUserForm, user=Depends(get_admin_user)):
|
|||
raise HTTPException(400, detail=ERROR_MESSAGES.EMAIL_TAKEN)
|
||||
|
||||
try:
|
||||
role = form_data.role
|
||||
|
||||
print(form_data)
|
||||
hashed = get_password_hash(form_data.password)
|
||||
user = Auths.insert_new_auth(
|
||||
form_data.email.lower(),
|
||||
hashed,
|
||||
form_data.name,
|
||||
form_data.profile_image_url,
|
||||
role,
|
||||
form_data.role,
|
||||
)
|
||||
|
||||
if user:
|
||||
|
|
|
@ -100,14 +100,15 @@ export const addUser = async (
|
|||
name: string,
|
||||
email: string,
|
||||
password: string,
|
||||
role: string
|
||||
role: string = 'pending'
|
||||
) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/auths/add`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
'Content-Type': 'application/json',
|
||||
...(token && { authorization: `Bearer ${token}` })
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: name,
|
||||
|
|
|
@ -15,9 +15,18 @@
|
|||
name: '',
|
||||
email: '',
|
||||
password: '',
|
||||
role: ''
|
||||
role: 'pending'
|
||||
};
|
||||
|
||||
$: if (show) {
|
||||
_user = {
|
||||
name: '',
|
||||
email: '',
|
||||
password: '',
|
||||
role: 'pending'
|
||||
};
|
||||
}
|
||||
|
||||
const submitHandler = async () => {
|
||||
const res = await addUser(
|
||||
localStorage.token,
|
||||
|
@ -38,7 +47,7 @@
|
|||
|
||||
<Modal size="sm" bind:show>
|
||||
<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>
|
||||
<button
|
||||
class="self-center"
|
||||
|
@ -69,6 +78,23 @@
|
|||
>
|
||||
<div class=" ">
|
||||
<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="flex-1">
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col md:flex-row w-full px-5 py-4 md:space-x-4 dark:text-gray-200">
|
||||
<div class="flex flex-col md:flex-row w-full px-5 pb-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">
|
||||
{#if chats.length > 0}
|
||||
<div class="text-left text-sm w-full mb-4 max-h-[22rem] overflow-y-scroll">
|
||||
|
|
Loading…
Reference in a new issue