forked from open-webui/open-webui
		
	Merge branch 'dev' into feature/support_auth_by_api_key
This commit is contained in:
		
						commit
						56369fea3a
					
				
					 35 changed files with 1231 additions and 325 deletions
				
			
		| 
						 | 
				
			
			@ -27,6 +27,7 @@ from utils.utils import (
 | 
			
		|||
from utils.misc import parse_duration, validate_email_format
 | 
			
		||||
from utils.webhook import post_webhook
 | 
			
		||||
from constants import ERROR_MESSAGES, WEBHOOK_MESSAGES
 | 
			
		||||
from config import WEBUI_AUTH_TRUSTED_EMAIL_HEADER
 | 
			
		||||
 | 
			
		||||
router = APIRouter()
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -77,6 +78,8 @@ async def update_profile(
 | 
			
		|||
async def update_password(
 | 
			
		||||
    form_data: UpdatePasswordForm, session_user=Depends(get_current_user)
 | 
			
		||||
):
 | 
			
		||||
    if WEBUI_AUTH_TRUSTED_EMAIL_HEADER:
 | 
			
		||||
        raise HTTPException(400, detail=ERROR_MESSAGES.ACTION_PROHIBITED)
 | 
			
		||||
    if session_user:
 | 
			
		||||
        user = Auths.authenticate_user(session_user.email, form_data.password)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -96,7 +99,22 @@ async def update_password(
 | 
			
		|||
 | 
			
		||||
@router.post("/signin", response_model=SigninResponse)
 | 
			
		||||
async def signin(request: Request, form_data: SigninForm):
 | 
			
		||||
    user = Auths.authenticate_user(form_data.email.lower(), form_data.password)
 | 
			
		||||
    if WEBUI_AUTH_TRUSTED_EMAIL_HEADER:
 | 
			
		||||
        if WEBUI_AUTH_TRUSTED_EMAIL_HEADER not in request.headers:
 | 
			
		||||
            raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_TRUSTED_HEADER)
 | 
			
		||||
 | 
			
		||||
        trusted_email = request.headers[WEBUI_AUTH_TRUSTED_EMAIL_HEADER].lower()
 | 
			
		||||
        if not Users.get_user_by_email(trusted_email.lower()):
 | 
			
		||||
            await signup(
 | 
			
		||||
                request,
 | 
			
		||||
                SignupForm(
 | 
			
		||||
                    email=trusted_email, password=str(uuid.uuid4()), name=trusted_email
 | 
			
		||||
                ),
 | 
			
		||||
            )
 | 
			
		||||
        user = Auths.authenticate_user_by_trusted_header(trusted_email)
 | 
			
		||||
    else:
 | 
			
		||||
        user = Auths.authenticate_user(form_data.email.lower(), form_data.password)
 | 
			
		||||
 | 
			
		||||
    if user:
 | 
			
		||||
        token = create_token(
 | 
			
		||||
            data={"id": user.id},
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue