MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / create_with_password

Method create_with_password

examples/loco_seaography/src/models/users.rs:158–187  ·  view source on GitHub ↗

Asynchronously creates a user with a password and saves it to the database. # Errors When could not save the user into the DB

(
        db: &DatabaseConnection,
        params: &RegisterParams,
    )

Source from the content-addressed store, hash-verified

156 ///
157 /// When could not save the user into the DB
158 pub async fn create_with_password(
159 db: &DatabaseConnection,
160 params: &RegisterParams,
161 ) -> ModelResult<Self> {
162 let txn = db.begin().await?;
163
164 if users::Entity::find()
165 .filter(users::Column::Email.eq(&params.email))
166 .one(&txn)
167 .await?
168 .is_some()
169 {
170 return Err(ModelError::EntityAlreadyExists {});
171 }
172
173 let password_hash =
174 hash::hash_password(&params.password).map_err(|e| ModelError::Any(e.into()))?;
175 let user = users::ActiveModel {
176 email: ActiveValue::set(params.email.to_string()),
177 password: ActiveValue::set(password_hash),
178 name: ActiveValue::set(params.name.to_string()),
179 ..Default::default()
180 }
181 .insert(&txn)
182 .await?;
183
184 txn.commit().await?;
185
186 Ok(user)
187 }
188
189 /// Creates a JWT
190 ///

Callers

nothing calls this directly

Calls 6

filterMethod · 0.80
beginMethod · 0.45
oneMethod · 0.45
eqMethod · 0.45
insertMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected