aboutsummaryrefslogtreecommitdiff
path: root/src/controller/login.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/controller/login.rs')
-rw-r--r--src/controller/login.rs11
1 files changed, 6 insertions, 5 deletions
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<String, String>,
templates: &minijinja::Environment<'_>,
form: HashMap<String, String>,
- pool: SqlitePool,
+ db_conn: Connection,
) -> Response<Full<Bytes>> {
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<Full<Bytes>> {
- 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))],