mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-09-11 03:05:58 +03:00
Implemented proper error handling, now we can do user.save($conn)?;
and it works.
In the future, maybe we can do the same with the `find_by_id` methods that return an Option.
This commit is contained in:
@@ -36,7 +36,17 @@ fn invite_user(data: JsonUpcase<InviteData>, _token: AdminToken, conn: DbConn) -
|
||||
err!("User already exists")
|
||||
}
|
||||
|
||||
err!("Unimplemented")
|
||||
if !CONFIG.invitations_allowed {
|
||||
err!("Invitations are not allowed")
|
||||
}
|
||||
|
||||
let mut invitation = Invitation::new(data.Email.clone());
|
||||
let mut user = User::new(data.Email);
|
||||
|
||||
invitation.save(&conn)?;
|
||||
user.save(&conn)?;
|
||||
|
||||
Ok(Json(json!({})))
|
||||
}
|
||||
|
||||
#[post("/users/<uuid>/delete")]
|
||||
@@ -46,10 +56,8 @@ fn delete_user(uuid: String, _token: AdminToken, conn: DbConn) -> JsonResult {
|
||||
None => err!("User doesn't exist"),
|
||||
};
|
||||
|
||||
match user.delete(&conn) {
|
||||
Ok(_) => Ok(Json(json!({}))),
|
||||
Err(e) => err!("Error deleting user", e),
|
||||
}
|
||||
user.delete(&conn)?;
|
||||
Ok(Json(json!({})))
|
||||
}
|
||||
|
||||
pub struct AdminToken {}
|
||||
|
Reference in New Issue
Block a user