MCPcopy Index your code
hub / github.com/fastapi-users/fastapi-users / create

Method create

fastapi_users/manager.py:110–147  ·  view source on GitHub ↗

Create a user in database. Triggers the on_after_register handler on success. :param user_create: The UserCreate model to create. :param safe: If True, sensitive values like is_superuser or is_verified will be ignored during the creation, defaults to False.

(
        self,
        user_create: schemas.UC,
        safe: bool = False,
        request: Request | None = None,
    )

Source from the content-addressed store, hash-verified

108 return user
109
110 async def create(
111 self,
112 user_create: schemas.UC,
113 safe: bool = False,
114 request: Request | None = None,
115 ) -> models.UP:
116 """
117 Create a user in database.
118
119 Triggers the on_after_register handler on success.
120
121 :param user_create: The UserCreate model to create.
122 :param safe: If True, sensitive values like is_superuser or is_verified
123 will be ignored during the creation, defaults to False.
124 :param request: Optional FastAPI request that
125 triggered the operation, defaults to None.
126 :raises UserAlreadyExists: A user already exists with the same e-mail.
127 :return: A new user of type models.UP.
128 """
129 await self.validate_password(user_create.password, user_create)
130
131 existing_user = await self.user_db.get_by_email(user_create.email)
132 if existing_user is not None:
133 raise exceptions.UserAlreadyExists()
134
135 user_dict = (
136 user_create.create_update_dict()
137 if safe
138 else user_create.create_update_dict_superuser()
139 )
140 password = user_dict.pop("password")
141 user_dict["hashed_password"] = self.password_helper.hash(password)
142
143 created_user = await self.user_db.create(user_dict)
144
145 await self.on_after_register(created_user, request)
146
147 return created_user
148
149 async def oauth_callback(
150 self: "BaseUserManager[models.UOAP, models.ID]",

Callers 1

oauth_callbackMethod · 0.45

Calls 6

validate_passwordMethod · 0.95
on_after_registerMethod · 0.95
create_update_dictMethod · 0.80
get_by_emailMethod · 0.45
hashMethod · 0.45

Tested by

no test coverage detected