Can set recovery key of user
This commit is contained in:
@@ -43,3 +43,17 @@ pub async fn logout(
|
|||||||
|
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct SetRecoveryKeyRequest {
|
||||||
|
key: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set recovery key of user
|
||||||
|
pub async fn set_recovery_key(client: MatrixClientExtractor) -> HttpResult {
|
||||||
|
let key = client.auth.decode_json_body::<SetRecoveryKeyRequest>()?.key;
|
||||||
|
|
||||||
|
client.client.set_recovery_key(&key).await?;
|
||||||
|
|
||||||
|
Ok(HttpResponse::Accepted().finish())
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ impl AuthExtractor {
|
|||||||
.payload
|
.payload
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.context("Failed to decode request as json: missing payload!")?;
|
.context("Failed to decode request as json: missing payload!")?;
|
||||||
serde_json::from_slice(payload).context("Failed to decode request json!")
|
Ok(serde_json::from_slice(payload)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,10 @@ async fn main() -> std::io::Result<()> {
|
|||||||
"/api/matrix_link/logout",
|
"/api/matrix_link/logout",
|
||||||
web::post().to(matrix_link_controller::logout),
|
web::post().to(matrix_link_controller::logout),
|
||||||
)
|
)
|
||||||
|
.route(
|
||||||
|
"/api/matrix_link/set_recovery_key",
|
||||||
|
web::post().to(matrix_link_controller::set_recovery_key),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.workers(4)
|
.workers(4)
|
||||||
.bind(&AppConfig::get().listen_address)?
|
.bind(&AppConfig::get().listen_address)?
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ enum MatrixClientError {
|
|||||||
WriteSessionFile(std::io::Error),
|
WriteSessionFile(std::io::Error),
|
||||||
#[error("Failed to rename device! {0}")]
|
#[error("Failed to rename device! {0}")]
|
||||||
RenameDevice(matrix_sdk::HttpError),
|
RenameDevice(matrix_sdk::HttpError),
|
||||||
|
#[error("Failed to set recovery key! {0}")]
|
||||||
|
SetRecoveryKey(matrix_sdk::encryption::recovery::RecoveryError),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
@@ -338,4 +340,15 @@ impl MatrixClient {
|
|||||||
RecoveryState::Incomplete => EncryptionRecoveryState::Incomplete,
|
RecoveryState::Incomplete => EncryptionRecoveryState::Incomplete,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set new encryption key recovery key
|
||||||
|
pub async fn set_recovery_key(&self, key: &str) -> anyhow::Result<()> {
|
||||||
|
Ok(self
|
||||||
|
.client
|
||||||
|
.encryption()
|
||||||
|
.recovery()
|
||||||
|
.recover(key)
|
||||||
|
.await
|
||||||
|
.map_err(MatrixClientError::SetRecoveryKey)?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user