Implementing PUT and PATCH user
To update the user, we need a page such as new_user()
, but we want the form pre-populated with existing data. We also want to add another field for the user to confirm the old password. Let's look at the steps:
- Change the
edit_user()
function signature to the following:#[get("/users/edit/<uuid>", format = "text/html")] pub async fn edit_user(mut db: Connection<DBConnection>, uuid: &str, flash: Option<FlashMessage<'_>>) -> HtmlResponse {}
- To get the existing user, append the following lines inside the function body block:
let connection = db .acquire() .await .map_err(|_| Status::InternalServerError)?; let user = User::find(connection, uuid) .await .map_err(|_| Status::NotFound)?;
- After that, we can append the HTML, such as
new_user()
,...