1use sea_orm::{EntityTrait, IntoActiveModel, QueryFilter, ColumnTrait, ActiveModelTrait};
2
3pub async fn reset(
4 ctx: upub::Context,
5 username: String,
6 password: String,
7) -> Result<(), sea_orm::DbErr> {
8
9 let mut user = upub::model::credential::Entity::find()
10 .filter(upub::model::credential::Column::Login.eq(&username))
11 .one(ctx.db())
12 .await?
13 .ok_or(sea_orm::DbErr::RecordNotFound("no such user".to_string()))?
14 .into_active_model();
15
16 user.password = sea_orm::Set(sha256::digest(password));
17
18 user.update(ctx.db()).await?;
19
20 tracing::info!("reset password of user: {username}");
21
22 Ok(())
23}