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): | class AddUserForm(SignupForm): | ||||||
|     role: str = "pending" |     role: Optional[str] = "pending" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class AuthsTable: | 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) |         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: | ||||||
|  |  | ||||||
|  | @ -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, | ||||||
|  |  | ||||||
|  | @ -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 @@ | ||||||
| 
 | 
 | ||||||
| <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 @@ | ||||||
| 				> | 				> | ||||||
| 					<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"> | ||||||
|  |  | ||||||
|  | @ -63,7 +63,7 @@ | ||||||
| 			</button> | 			</button> | ||||||
| 		</div> | 		</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"> | 			<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"> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek