|
@@ -2,17 +2,10 @@ use actix_web::{HttpResponse, web, post};
|
|
|
use serde::Deserialize;
|
|
use serde::Deserialize;
|
|
|
use serde_json::json;
|
|
use serde_json::json;
|
|
|
use sqlx::PgPool;
|
|
use sqlx::PgPool;
|
|
|
-use argon2::{
|
|
|
|
|
- Argon2,
|
|
|
|
|
- password_hash::{
|
|
|
|
|
- PasswordHash,
|
|
|
|
|
- PasswordVerifier
|
|
|
|
|
- }
|
|
|
|
|
-};
|
|
|
|
|
use crate::{
|
|
use crate::{
|
|
|
app_error::AppError,
|
|
app_error::AppError,
|
|
|
models::user::User,
|
|
models::user::User,
|
|
|
- logic::create_cookie
|
|
|
|
|
|
|
+ logic::{create_cookie, compare_password}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
#[derive(Deserialize)]
|
|
@@ -32,12 +25,3 @@ pub async fn route(
|
|
|
let cookie = create_cookie("user".to_string(), user.id.to_string());
|
|
let cookie = create_cookie("user".to_string(), user.id.to_string());
|
|
|
Ok(HttpResponse::Ok().cookie(cookie).json(json!({"success": true})))
|
|
Ok(HttpResponse::Ok().cookie(cookie).json(json!({"success": true})))
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-fn compare_password(pass: &String, hash: &String) -> Result<(), AppError> {
|
|
|
|
|
- let parsed_hash = PasswordHash::new(hash)
|
|
|
|
|
- .map_err(|e| AppError::InternalError(e.to_string()))?;
|
|
|
|
|
-
|
|
|
|
|
- Argon2::default()
|
|
|
|
|
- .verify_password(pass.as_bytes(), &parsed_hash)
|
|
|
|
|
- .map_err(|_| AppError::Auth)
|
|
|
|
|
-}
|
|
|