From 64223b8812ac6ec94b472f620d3030fbdc748df3 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Mon, 6 Apr 2020 17:37:13 +0200 Subject: [PATCH] register login flow --- src/main.rs | 17 ++++++++++++++++- src/ruma_wrapper.rs | 19 +++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 72f3ce7c..2d879434 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,6 +44,21 @@ fn register_route( data: State, body: Ruma, ) -> MatrixResult { + if body.auth.is_none() { + return MatrixResult(Err(Error { + kind: ErrorKind::InvalidUsername, + message: serde_json::to_string(&json!({ + "flows": [ + { "stages": [ "m.login.dummy" ] }, + ], + "params": {}, + "session": "TODO:randomsessionid", + })) + .unwrap(), + status_code: http::StatusCode::UNAUTHORIZED, + })); + } + // Validate user id let user_id: UserId = match (*format!( "@{}:{}", @@ -353,7 +368,7 @@ fn options_route(_segments: PathBuf) -> MatrixResult(_req: &'r Request, data: Data) -> TransformFuture<'r, Self::Owned, Self::Error> { + fn transform<'r>( + _req: &'r Request, + data: Data, + ) -> TransformFuture<'r, Self::Owned, Self::Error> { Box::pin(async move { Transform::Owned(Success(data)) }) } @@ -123,8 +126,7 @@ impl Deref for Ruma { /// This struct converts ruma responses into rocket http responses. pub struct MatrixResult(pub std::result::Result); -impl>>> TryInto>> for MatrixResult -{ +impl>>> TryInto>> for MatrixResult { type Error = T::Error; fn try_into(self) -> Result>, T::Error> { @@ -136,13 +138,18 @@ impl>>> TryInto>> for M } #[rocket::async_trait] -impl<'r, T: Send + TryInto>>> Responder<'r> for MatrixResult where T::Error: Send{ +impl<'r, T: Send + TryInto>>> Responder<'r> for MatrixResult +where + T::Error: Send, +{ async fn respond_to(self, _: &'r Request<'_>) -> response::Result<'r> { let http_response: Result, _> = self.try_into(); match http_response { Ok(http_response) => { let mut response = rocket::response::Response::build(); - response.sized_body(Cursor::new(http_response.body().clone())).await; + response + .sized_body(Cursor::new(http_response.body().clone())) + .await; for header in http_response.headers() { response