add bots
This commit is contained in:
		
							parent
							
								
									a014acd35d
								
							
						
					
					
						commit
						d4981b23de
					
				@ -157,6 +157,7 @@ def validate_username(value: str,
 | 
			
		||||
                      field_name: str = "login",
 | 
			
		||||
                      with_httpexception=False,
 | 
			
		||||
                      need_back=False,
 | 
			
		||||
                      is_bot=False,
 | 
			
		||||
                      min_length=3,
 | 
			
		||||
                      max_length=32,
 | 
			
		||||
                      error_status_code: int = status.HTTP_401_UNAUTHORIZED,
 | 
			
		||||
@ -169,7 +170,7 @@ def validate_username(value: str,
 | 
			
		||||
    - no consecutive underscores
 | 
			
		||||
    - only [A-Za-z0-9_]
 | 
			
		||||
    """
 | 
			
		||||
    valid, result = core_validate_username(value, field_name, need_back=True, min_length=min_length, max_length=max_length)
 | 
			
		||||
    valid, result = core_validate_username(value, field_name, need_back=True, is_bot=is_bot, min_length=min_length, max_length=max_length)
 | 
			
		||||
    if not valid:
 | 
			
		||||
        if with_httpexception:
 | 
			
		||||
            raise HTTPException(status_code=error_status_code, detail=error_detail)
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,7 @@ import re
 | 
			
		||||
def validate_username(value: str,
 | 
			
		||||
                      field_name: str = "login",
 | 
			
		||||
                      need_back=False,
 | 
			
		||||
                      is_bot=False,
 | 
			
		||||
                      min_length=3,
 | 
			
		||||
                      max_length=32) -> str:
 | 
			
		||||
    """
 | 
			
		||||
@ -38,7 +39,25 @@ def validate_username(value: str,
 | 
			
		||||
        msg = f"{field_name.capitalize()} must contain only English letters, digits, and underscores"
 | 
			
		||||
        return (False, msg) if need_back else False
 | 
			
		||||
 | 
			
		||||
    return (True, value.lower()) if need_back else value.lower()
 | 
			
		||||
    val_lower = value.lower()
 | 
			
		||||
 | 
			
		||||
    # Проверка окончания имени в зависимости от is_bot
 | 
			
		||||
    if is_bot and not val_lower.endswith("bot"):
 | 
			
		||||
        msg = f"{field_name.capitalize()} must end with 'bot' for bot accounts"
 | 
			
		||||
        return (False, msg) if need_back else False
 | 
			
		||||
 | 
			
		||||
    if not is_bot and val_lower.endswith("bot"):
 | 
			
		||||
        msg = f"{field_name.capitalize()} must not end with 'bot' for non-bot accounts"
 | 
			
		||||
        return (False, msg) if need_back else False
 | 
			
		||||
 | 
			
		||||
    # Если заканчивается на 'bot', то перед ним должно быть >=3 символов (кроме '_')
 | 
			
		||||
    if val_lower.endswith("bot"):
 | 
			
		||||
        prefix = re.sub(r'_+', '', val_lower[:-3])  # убираем все подчёркивания
 | 
			
		||||
        if len(prefix) < 3:
 | 
			
		||||
            msg = f"{field_name.capitalize()} must contain at least 3 non-underscore characters before 'bot'"
 | 
			
		||||
            return (False, msg) if need_back else False
 | 
			
		||||
 | 
			
		||||
    return (True, val_lower) if need_back else val_lower
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_password(value: str,
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
[project]
 | 
			
		||||
name = "common-lib"
 | 
			
		||||
version = "0.0.34"
 | 
			
		||||
version = "0.0.35"
 | 
			
		||||
description = "Библиотека общих компонентов для микросервисов yobble"
 | 
			
		||||
authors = [{ name = "cheykrym", email = "you@example.com" }]
 | 
			
		||||
license = "MIT"
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user