forked from open-webui/open-webui
		
	feat: set first user to admin by default
This commit is contained in:
		
							parent
							
								
									07d2c9871f
								
							
						
					
					
						commit
						83ff1d77ea
					
				
					 8 changed files with 28 additions and 25 deletions
				
			
		|  | @ -9,7 +9,7 @@ import json | |||
| from apps.web.models.users import Users | ||||
| from constants import ERROR_MESSAGES | ||||
| from utils.utils import extract_token_from_auth_header | ||||
| from config import OLLAMA_API_BASE_URL, OLLAMA_WEBUI_AUTH | ||||
| from config import OLLAMA_API_BASE_URL, WEBUI_AUTH | ||||
| 
 | ||||
| app = Flask(__name__) | ||||
| CORS( | ||||
|  | @ -32,7 +32,7 @@ def proxy(path): | |||
|     headers = dict(request.headers) | ||||
| 
 | ||||
|     # Basic RBAC support | ||||
|     if OLLAMA_WEBUI_AUTH: | ||||
|     if WEBUI_AUTH: | ||||
|         if "Authorization" in headers: | ||||
|             token = extract_token_from_auth_header(headers["Authorization"]) | ||||
|             user = Users.get_user_by_token(token) | ||||
|  |  | |||
|  | @ -2,7 +2,7 @@ from fastapi import FastAPI, Request, Depends, HTTPException | |||
| from fastapi.middleware.cors import CORSMiddleware | ||||
| 
 | ||||
| from apps.web.routers import auths, users | ||||
| from config import OLLAMA_WEBUI_VERSION, OLLAMA_WEBUI_AUTH | ||||
| from config import WEBUI_VERSION, WEBUI_AUTH | ||||
| 
 | ||||
| app = FastAPI() | ||||
| 
 | ||||
|  | @ -23,4 +23,4 @@ app.include_router(users.router, prefix="/users", tags=["users"]) | |||
| 
 | ||||
| @app.get("/") | ||||
| async def get_status(): | ||||
|     return {"status": True, "version": OLLAMA_WEBUI_VERSION, "auth": OLLAMA_WEBUI_AUTH} | ||||
|     return {"status": True, "version": WEBUI_VERSION, "auth": WEBUI_AUTH} | ||||
|  |  | |||
|  | @ -81,6 +81,9 @@ class UsersTable: | |||
|             ) | ||||
|         ] | ||||
| 
 | ||||
|     def get_num_users(self) -> Optional[int]: | ||||
|         return self.table.count_documents({}) | ||||
| 
 | ||||
|     def update_user_by_id(self, id: str, updated: dict) -> Optional[UserModel]: | ||||
|         user = self.table.find_one_and_update( | ||||
|             {"id": id}, {"$set": updated}, return_document=ReturnDocument.AFTER | ||||
|  |  | |||
|  | @ -86,8 +86,9 @@ async def signin(form_data: SigninForm): | |||
| async def signup(form_data: SignupForm): | ||||
|     if not Users.get_user_by_email(form_data.email.lower()): | ||||
|         try: | ||||
|             role = "admin" if Users.get_num_users() == 0 else "pending" | ||||
|             hashed = get_password_hash(form_data.password) | ||||
|             user = Auths.insert_new_auth(form_data.email, hashed, form_data.name) | ||||
|             user = Auths.insert_new_auth(form_data.email, hashed, form_data.name, role) | ||||
| 
 | ||||
|             if user: | ||||
|                 token = create_token(data={"email": user.email}) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek