31 lines
961 B
Rust
31 lines
961 B
Rust
use crate::controllers::HttpResult;
|
|
use crate::extractors::matrix_client_extractor::MatrixClientExtractor;
|
|
use crate::matrix_connection::matrix_client::FinishMatrixAuth;
|
|
use actix_web::HttpResponse;
|
|
|
|
#[derive(serde::Serialize)]
|
|
struct StartAuthResponse {
|
|
url: String,
|
|
}
|
|
|
|
/// Start user authentication on Matrix server
|
|
pub async fn start_auth(client: MatrixClientExtractor) -> HttpResult {
|
|
let url = client.client.initiate_login().await?.to_string();
|
|
Ok(HttpResponse::Ok().json(StartAuthResponse { url }))
|
|
}
|
|
|
|
/// Finish user authentication on Matrix server
|
|
pub async fn finish_auth(client: MatrixClientExtractor) -> HttpResult {
|
|
match client
|
|
.client
|
|
.finish_login(client.auth.decode_json_body::<FinishMatrixAuth>()?)
|
|
.await
|
|
{
|
|
Ok(_) => Ok(HttpResponse::Accepted().finish()),
|
|
Err(e) => {
|
|
log::error!("Failed to finish Matrix authentication: {e}");
|
|
Err(e.into())
|
|
}
|
|
}
|
|
}
|