Error handling refactor and 500 page/message templates
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
authentication::{self, AuthenticatedUser, Credentials, validate_credentials},
|
||||
authentication::{self, AuthError, AuthenticatedUser, Credentials, validate_credentials},
|
||||
routes::{AdminError, AppError},
|
||||
startup::AppState,
|
||||
templates::MessageTemplate,
|
||||
@@ -35,11 +35,14 @@ pub async fn change_password(
|
||||
"You entered two different passwords - the field values must match.".to_string(),
|
||||
)
|
||||
.into())
|
||||
} else if validate_credentials(credentials, &connection_pool)
|
||||
.await
|
||||
.is_err()
|
||||
{
|
||||
Err(AdminError::ChangePassword("The current password is incorrect.".to_string()).into())
|
||||
} else if let Err(e) = validate_credentials(credentials, &connection_pool).await {
|
||||
match e {
|
||||
AuthError::UnexpectedError(error) => Err(AdminError::UnexpectedError(error).into()),
|
||||
AuthError::InvalidCredentials(_) => Err(AdminError::ChangePassword(
|
||||
"The current password is incorrect.".to_string(),
|
||||
)
|
||||
.into()),
|
||||
}
|
||||
} else if let Err(e) = verify_password(form.new_password.expose_secret()) {
|
||||
Err(AdminError::ChangePassword(e).into())
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user