Refactor admin routes to use new AppError struct in responses
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
authentication::{self, AuthenticatedUser, Credentials, validate_credentials},
|
||||
routes::AdminError,
|
||||
routes::{AdminError, AppError},
|
||||
startup::AppState,
|
||||
templates::MessageTemplate,
|
||||
};
|
||||
@@ -25,7 +25,7 @@ pub async fn change_password(
|
||||
connection_pool, ..
|
||||
}): State<AppState>,
|
||||
Form(form): Form<PasswordFormData>,
|
||||
) -> Result<Response, AdminError> {
|
||||
) -> Result<Response, AppError> {
|
||||
let credentials = Credentials {
|
||||
username,
|
||||
password: form.current_password,
|
||||
@@ -33,16 +33,15 @@ pub async fn change_password(
|
||||
if form.new_password.expose_secret() != form.new_password_check.expose_secret() {
|
||||
Err(AdminError::ChangePassword(
|
||||
"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(),
|
||||
))
|
||||
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))
|
||||
Err(AdminError::ChangePassword(e).into())
|
||||
} else {
|
||||
authentication::change_password(user_id, form.new_password, &connection_pool)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user