From 43f443c7a85e5172b5c1a6a69db775659214196d Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 3 Jun 2022 14:00:19 +0200 Subject: WIP login --- src/server.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/server.rs') diff --git a/src/server.rs b/src/server.rs index ba89111..432f597 100644 --- a/src/server.rs +++ b/src/server.rs @@ -26,8 +26,8 @@ impl Connection { } impl Service for Connection { type Response = Response; - type Error = anyhow::Error; - type Future = BoxFuture<'static, Result>; + type Error = boitalettres::errors::Error; + type Future = BoxFuture<'static, Result>; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) @@ -35,6 +35,7 @@ impl Service for Connection { fn call(&mut self, req: Request) -> Self::Future { tracing::debug!("Got request: {:#?}", req); + let mailstore = self.mailstore.clone(); Box::pin(async move { use imap_codec::types::{ command::CommandBody, @@ -51,9 +52,22 @@ impl Service for Connection { .with_body(body) } CommandBody::Login { - username: _, - password: _, - } => Response::ok("Logged in")?, + username, + password, + } => { + let (u, p) = match (String::try_from(username), String::try_from(password)) { + (Ok(u), Ok(p)) => (u, p), + _ => { return Response::bad("Invalid characters") } + }; + + tracing::debug!(user = %u, "command.login"); + let creds = match mailstore.login_provider.login(&u, &p).await { + Err(_) => { return Response::no("[AUTHENTICATIONFAILED] Authentication failed.") } + Ok(c) => c, + }; + + Response::ok("Logged in")? + } _ => Response::bad("Error in IMAP command received by server.")?, }; -- cgit v1.2.3