diff options
Diffstat (limited to '')
-rw-r--r-- | src/routes/login.rs | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/routes/login.rs b/src/routes/login.rs index 33f7f69..c6cf077 100644 --- a/src/routes/login.rs +++ b/src/routes/login.rs @@ -1,9 +1,9 @@ use actix_session::Session; use actix_web::http::header::LOCATION; use actix_web::{get, post, web, HttpResponse}; -use bcrypt::verify; use serde::Deserialize; +use crate::error::PinussyError; use crate::notification::{Kind, Notification}; use crate::templates; use crate::Pinussy; @@ -27,17 +27,11 @@ async fn post( session: Session, form: web::Form<LoginForm>, ) -> Result<HttpResponse> { - match sqlx::query!( - "select id, password from users where username = $1", - &form.username - ) - .fetch_one(&state.db) - .await - { + match state.db.users().read_username(&form.username).await { Ok(user) => { - let password_hash: String = user.password; - if verify(&form.password, &password_hash)? { - session.insert("user_id", user.id)?; + if user.verify_password(&form.password)? { + let user_id = state.db.users().get_id(&form.username).await?; + session.insert("user_id", user_id)?; return Ok(HttpResponse::SeeOther() .insert_header((LOCATION, "/")) .finish()); @@ -54,7 +48,7 @@ async fn post( )); } } - Err(sqlx::Error::RowNotFound) => { + Err(PinussyError::Database(sqlx::Error::RowNotFound)) => { return Ok(HttpResponse::NotFound().body( render!( templates::login_html, |