Download scripts\create_user_helper.py from aionaion/chatdoc: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/spaces/aionaion/chatdoc/resolve/main/scripts%5Ccreate_user_helper.py
- Command line
-
hf download 'hf://spaces/aionaion/chatdoc/scripts\create_user_helper.py'
-
curl -L -o 'scripts\create_user_helper.py' https://huggingface.co/spaces/aionaion/chatdoc/resolve/main/scripts%5Ccreate_user_helper.py
1.93 kB
| #!/usr/bin/env python3 | |
| import sys | |
| import os | |
| import argparse | |
| from pathlib import Path | |
| # Configura o caminho para importar módulos da app | |
| project_root = Path(__file__).resolve().parent.parent | |
| os.chdir(project_root) | |
| sys.path.append(str(project_root)) | |
| try: | |
| # Tenta importar a função de hash do próprio projeto | |
| from app.core.security import get_password_hash | |
| except ImportError: | |
| print("⚠️ Não foi possível importar 'get_password_hash' de app.core.security.") | |
| print(" Tentando usar passlib diretamente (fallback)...") | |
| try: | |
| from passlib.context import CryptContext | |
| pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") | |
| def get_password_hash(password): | |
| return pwd_context.hash(password) | |
| except ImportError: | |
| print("❌ Erro: passlib não encontrado. Instale com 'pip install passlib bcrypt'") | |
| sys.exit(1) | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Gera hash e JSON para novo usuário") | |
| parser.add_argument("username", help="Nome do usuário") | |
| parser.add_argument("password", help="Senha") | |
| parser.add_argument("scopes", help="Escopos separados por vírgula (ex: sistemas,farmaceutico)") | |
| args = parser.parse_args() | |
| hashed = get_password_hash(args.password) | |
| scopes_list = [s.strip() for s in args.scopes.split(',')] | |
| print("\n✅ Dados do Usuário Gerados:") | |
| print("=" * 50) | |
| print(f"Username: {args.username}") | |
| print(f"Scopes: {scopes_list}") | |
| print("-" * 50) | |
| print(f"Hashed: {hashed}") | |
| print("=" * 50) | |
| print("\n📋 Copie e cole o bloco abaixo no seu arquivo de usuários (ex: users.json ou auth.py):") | |
| print(f''' | |
| "{args.username}": {{ | |
| "username": "{args.username}", | |
| "hashed_password": "{hashed}", | |
| "scopes": {scopes_list}, | |
| "disabled": False | |
| }}, | |
| ''') | |
| if __name__ == "__main__": | |
| main() |