feat(api): added an account verification check before authentication

This commit is contained in:
antifallobst 2023-08-17 01:29:00 +02:00
parent eadfdca689
commit 3049b68ef4
Signed by: antifallobst
GPG Key ID: 2B4F402172791BAF
5 changed files with 12 additions and 1 deletions

3
API.md
View File

@ -93,6 +93,9 @@ The provided password was wrong.
Blocked for security reasons.
##### 404 - Error: Not Found
The provided username was not found.
##### 424 - Error: Failed Dependency
The account isn't verified yet.
### `/account/delete` - DELETE
Deletes the account.

View File

@ -5,6 +5,7 @@ use pbkdf2::{
};
use sqlx::{mysql::MySqlPool, types::chrono as sqlx_chrono};
#[derive(Debug)]
pub struct Account {
pub id: u64,
pub username: String,

View File

@ -48,6 +48,7 @@ async fn authenticate(
data::AuthenticateResponse::Success(b) => HttpResponse::Ok().json(web::Json(b)),
data::AuthenticateResponse::WrongPassword => HttpResponse::Unauthorized().finish(),
data::AuthenticateResponse::UserNotFound => HttpResponse::NotFound().finish(),
data::AuthenticateResponse::NotVerified => HttpResponse::new(actix_web::http::StatusCode::FAILED_DEPENDENCY),
data::AuthenticateResponse::Blocked => HttpResponse::Forbidden().finish(),
},
Err(e) => {

View File

@ -50,6 +50,7 @@ pub enum AuthenticateResponse {
Success(AuthenticateSuccess),
WrongPassword,
UserNotFound,
NotVerified,
Blocked,
}

View File

@ -117,6 +117,10 @@ pub async fn authenticate(
return Ok(data::AuthenticateResponse::WrongPassword);
}
if !account.verified {
return Ok(data::AuthenticateResponse::NotVerified);
}
let token = AuthToken::new(pool, account.id, chrono::Duration::days(7)).await?;
Ok(data::AuthenticateResponse::Success(
@ -129,6 +133,7 @@ pub async fn delete(pool: &MySqlPool, token: String) -> Result<data::DeleteRespo
return Ok(data::DeleteResponse::Blocked);
}
info!("Token: {}", token);
Ok(data::DeleteResponse::Success)
}