summaryrefslogtreecommitdiffstats
path: root/src/routes/login.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2023-12-12 18:20:56 +0000
committerLibravatar cel 🌸 <cel@blos.sm>2023-12-12 18:20:56 +0000
commita587459a1817c0fc57b46df3f9c69567e1e775b7 (patch)
treeab99c6aaa7c2b3245c83db6332e4ca54006831b3 /src/routes/login.rs
parent370a25e5a0cbb95e2aa1cec55305b22aeaf99aa0 (diff)
downloadpinussy-a587459a1817c0fc57b46df3f9c69567e1e775b7.tar.gz
pinussy-a587459a1817c0fc57b46df3f9c69567e1e775b7.tar.bz2
pinussy-a587459a1817c0fc57b46df3f9c69567e1e775b7.zip
refactor: separate model and controller
Diffstat (limited to '')
-rw-r--r--src/routes/login.rs18
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,