aboutsummaryrefslogtreecommitdiff
path: root/src/server.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2022-06-03 14:00:19 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2022-06-03 14:00:19 +0200
commit43f443c7a85e5172b5c1a6a69db775659214196d (patch)
tree6b6fd650094606f57cc05b1e10ac99fd3a772207 /src/server.rs
parent8f3a34da33bf386c048790615ec1f63e89d22f6b (diff)
downloadaerogramme-43f443c7a85e5172b5c1a6a69db775659214196d.tar.gz
aerogramme-43f443c7a85e5172b5c1a6a69db775659214196d.zip
WIP login
Diffstat (limited to 'src/server.rs')
-rw-r--r--src/server.rs24
1 files changed, 19 insertions, 5 deletions
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<Request> for Connection {
type Response = Response;
- type Error = anyhow::Error;
- type Future = BoxFuture<'static, Result<Self::Response>>;
+ type Error = boitalettres::errors::Error;
+ type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
@@ -35,6 +35,7 @@ impl Service<Request> 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<Request> 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.")?,
};