feat(api): added an account verification check before authentication
This commit is contained in:
parent
eadfdca689
commit
3049b68ef4
3
API.md
3
API.md
|
@ -93,6 +93,9 @@ The provided password was wrong.
|
||||||
Blocked for security reasons.
|
Blocked for security reasons.
|
||||||
##### 404 - Error: Not Found
|
##### 404 - Error: Not Found
|
||||||
The provided username was not found.
|
The provided username was not found.
|
||||||
|
##### 424 - Error: Failed Dependency
|
||||||
|
The account isn't verified yet.
|
||||||
|
|
||||||
|
|
||||||
### `/account/delete` - DELETE
|
### `/account/delete` - DELETE
|
||||||
Deletes the account.
|
Deletes the account.
|
||||||
|
|
|
@ -5,6 +5,7 @@ use pbkdf2::{
|
||||||
};
|
};
|
||||||
use sqlx::{mysql::MySqlPool, types::chrono as sqlx_chrono};
|
use sqlx::{mysql::MySqlPool, types::chrono as sqlx_chrono};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Account {
|
pub struct Account {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
|
|
|
@ -48,6 +48,7 @@ async fn authenticate(
|
||||||
data::AuthenticateResponse::Success(b) => HttpResponse::Ok().json(web::Json(b)),
|
data::AuthenticateResponse::Success(b) => HttpResponse::Ok().json(web::Json(b)),
|
||||||
data::AuthenticateResponse::WrongPassword => HttpResponse::Unauthorized().finish(),
|
data::AuthenticateResponse::WrongPassword => HttpResponse::Unauthorized().finish(),
|
||||||
data::AuthenticateResponse::UserNotFound => HttpResponse::NotFound().finish(),
|
data::AuthenticateResponse::UserNotFound => HttpResponse::NotFound().finish(),
|
||||||
|
data::AuthenticateResponse::NotVerified => HttpResponse::new(actix_web::http::StatusCode::FAILED_DEPENDENCY),
|
||||||
data::AuthenticateResponse::Blocked => HttpResponse::Forbidden().finish(),
|
data::AuthenticateResponse::Blocked => HttpResponse::Forbidden().finish(),
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
|
@ -50,6 +50,7 @@ pub enum AuthenticateResponse {
|
||||||
Success(AuthenticateSuccess),
|
Success(AuthenticateSuccess),
|
||||||
WrongPassword,
|
WrongPassword,
|
||||||
UserNotFound,
|
UserNotFound,
|
||||||
|
NotVerified,
|
||||||
Blocked,
|
Blocked,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,10 @@ pub async fn authenticate(
|
||||||
return Ok(data::AuthenticateResponse::WrongPassword);
|
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?;
|
let token = AuthToken::new(pool, account.id, chrono::Duration::days(7)).await?;
|
||||||
|
|
||||||
Ok(data::AuthenticateResponse::Success(
|
Ok(data::AuthenticateResponse::Success(
|
||||||
|
@ -129,6 +133,7 @@ pub async fn delete(pool: &MySqlPool, token: String) -> Result<data::DeleteRespo
|
||||||
return Ok(data::DeleteResponse::Blocked);
|
return Ok(data::DeleteResponse::Blocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Token: {}", token);
|
|
||||||
|
|
||||||
Ok(data::DeleteResponse::Success)
|
Ok(data::DeleteResponse::Success)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue