From 0adf5a093494bdb7f5d5c0f12913133e333ddfad Mon Sep 17 00:00:00 2001 From: Joris Date: Fri, 31 Jan 2025 22:28:53 +0100 Subject: Migrate to tokio_rusqlite --- src/controller/login.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/controller/login.rs') diff --git a/src/controller/login.rs b/src/controller/login.rs index 31370cc..d01f799 100644 --- a/src/controller/login.rs +++ b/src/controller/login.rs @@ -3,8 +3,8 @@ use http_body_util::Full; use hyper::body::Bytes; use hyper::header::SET_COOKIE; use hyper::Response; -use sqlx::sqlite::SqlitePool; use std::collections::HashMap; +use tokio_rusqlite::Connection; use crate::controller::utils::with_headers; use crate::controller::wallet::Wallet; @@ -35,18 +35,19 @@ pub async fn login( assets: &HashMap, templates: &minijinja::Environment<'_>, form: HashMap, - pool: SqlitePool, + db_conn: Connection, ) -> Response> { match validation::login::login(&form) { Some(login) => { - match db::users::get_password_hash(&pool, login.email.clone()).await + match db::users::get_password_hash(&db_conn, login.email.clone()) + .await { Some(hash) => match bcrypt::verify(login.password, &hash) { Ok(true) => { let login_token = cookie::generate_token(); if db::users::set_login_token( - &pool, + &db_conn, login.email, login_token.clone().to_string(), ) @@ -110,7 +111,7 @@ async fn not_authorized( } pub async fn logout(config: &Config, wallet: &Wallet) -> Response> { - if db::users::remove_login_token(&wallet.pool, wallet.user.id).await { + if db::users::remove_login_token(&wallet.db_conn, wallet.user.id).await { with_headers( utils::redirect("/"), vec![(SET_COOKIE, &cookie::logout(config))], -- cgit v1.2.3