diff --git a/API.md b/API.md index b026b98..4d75c26 100644 --- a/API.md +++ b/API.md @@ -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. diff --git a/src/accounts.rs b/src/accounts.rs index cb22ffc..772ebfa 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -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, diff --git a/src/api/account/calls.rs b/src/api/account/calls.rs index 9023b82..ceeef56 100644 --- a/src/api/account/calls.rs +++ b/src/api/account/calls.rs @@ -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) => { diff --git a/src/api/account/data.rs b/src/api/account/data.rs index dc0a873..ed5826c 100644 --- a/src/api/account/data.rs +++ b/src/api/account/data.rs @@ -50,6 +50,7 @@ pub enum AuthenticateResponse { Success(AuthenticateSuccess), WrongPassword, UserNotFound, + NotVerified, Blocked, } diff --git a/src/api/account/handlers.rs b/src/api/account/handlers.rs index c4c8dcc..018b61b 100644 --- a/src/api/account/handlers.rs +++ b/src/api/account/handlers.rs @@ -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