MCPcopy Create free account
hub / github.com/AQ-MedAI/MedMemoryBench / create_user

Function create_user

methods/cognee/modules/users/methods/create_user.py:13–62  ·  view source on GitHub ↗
(
    email: str,
    password: str,
    tenant_id: Optional[str] = None,
    is_superuser: bool = False,
    is_active: bool = True,
    is_verified: bool = False,
    auto_login: bool = False,
)

Source from the content-addressed store, hash-verified

11
12
13async def create_user(
14 email: str,
15 password: str,
16 tenant_id: Optional[str] = None,
17 is_superuser: bool = False,
18 is_active: bool = True,
19 is_verified: bool = False,
20 auto_login: bool = False,
21):
22 try:
23 relational_engine = get_relational_engine()
24
25 async with relational_engine.get_async_session() as session:
26 async with get_user_db_context(session) as user_db:
27 async with get_user_manager_context(user_db) as user_manager:
28 if tenant_id:
29 # Check if the tenant already exists
30 result = await session.execute(select(Tenant).where(Tenant.id == tenant_id))
31 tenant = result.scalars().first()
32 if not tenant:
33 raise TenantNotFoundError
34
35 user = await user_manager.create(
36 UserCreate(
37 email=email,
38 password=password,
39 tenant_id=tenant.id,
40 is_superuser=is_superuser,
41 is_active=is_active,
42 is_verified=is_verified,
43 )
44 )
45 else:
46 user = await user_manager.create(
47 UserCreate(
48 email=email,
49 password=password,
50 is_superuser=is_superuser,
51 is_active=is_active,
52 is_verified=is_verified,
53 )
54 )
55
56 if auto_login:
57 await session.refresh(user)
58
59 return user
60 except UserAlreadyExists as error:
61 print(f"User {email} already exists")
62 raise error

Callers 1

create_default_userFunction · 0.90

Calls 7

get_relational_engineFunction · 0.90
UserCreateClass · 0.90
get_async_sessionMethod · 0.80
firstMethod · 0.80
scalarsMethod · 0.80
executeMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected