Templates and TLS requests
Refactored HTML templates and added TLS back to issue HTTP requests
This commit is contained in:
@@ -49,9 +49,7 @@ pub async fn change_password(
|
||||
authentication::change_password(user_id, form.new_password, &connection_pool)
|
||||
.await
|
||||
.map_err(AdminError::ChangePassword)?;
|
||||
let template = MessageTemplate::Success {
|
||||
message: "Your password has been changed.".to_string(),
|
||||
};
|
||||
let template = MessageTemplate::success("Your password has been changed.".to_string());
|
||||
Ok(Html(template.render().unwrap()).into_response())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ pub async fn publish_newsletter(
|
||||
.context("Failed to enqueue delivery tasks.")?;
|
||||
|
||||
let message = String::from("Your email has been queued for delivery.");
|
||||
let template = MessageTemplate::Success { message };
|
||||
let template = MessageTemplate::success(message);
|
||||
let response = Html(template.render().unwrap()).into_response();
|
||||
let response = save_response(transaction, &idempotency_key, user_id, response)
|
||||
.await
|
||||
|
||||
@@ -73,9 +73,7 @@ pub async fn create_post(
|
||||
.await
|
||||
.context("Failed to enqueue delivery tasks.")?;
|
||||
|
||||
let template = MessageTemplate::Success {
|
||||
message: "Your new post has been published!".into(),
|
||||
};
|
||||
let template = MessageTemplate::success("Your new post has been published!".into());
|
||||
let response = Html(template.render().unwrap()).into_response();
|
||||
let response = save_response(transaction, &idempotency_key, user_id, response)
|
||||
.await
|
||||
@@ -138,9 +136,7 @@ pub async fn delete_post(
|
||||
"We could not find the post in the database."
|
||||
)))
|
||||
} else {
|
||||
let template = MessageTemplate::Success {
|
||||
message: "The subscriber has been deleted.".into(),
|
||||
};
|
||||
let template = MessageTemplate::success("The subscriber has been deleted.".into());
|
||||
Ok(template.render().unwrap().into_response())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,12 +63,10 @@ pub async fn delete_subscriber(
|
||||
.map_err(AppError::unexpected_message)?;
|
||||
if let Some(record) = res {
|
||||
tracing::Span::current().record("email", tracing::field::display(&record.email));
|
||||
let template = MessageTemplate::Success {
|
||||
message: format!(
|
||||
"The subscriber with email '{}' has been deleted.",
|
||||
record.email
|
||||
),
|
||||
};
|
||||
let template = MessageTemplate::success(format!(
|
||||
"The subscriber with email '{}' has been deleted.",
|
||||
record.email
|
||||
));
|
||||
Ok(template.render().unwrap().into_response())
|
||||
} else {
|
||||
Err(AppError::unexpected_message(anyhow::anyhow!(
|
||||
|
||||
@@ -66,9 +66,8 @@ pub async fn subscribe(
|
||||
.context("Failed to commit the database transaction to store a new subscriber.")?;
|
||||
}
|
||||
|
||||
let template = MessageTemplate::Success {
|
||||
message: "You'll receive a confirmation email shortly.".to_string(),
|
||||
};
|
||||
let template =
|
||||
MessageTemplate::success("You'll receive a confirmation email shortly.".to_string());
|
||||
Ok(Html(template.render().unwrap()).into_response())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
use crate::{
|
||||
domain::SubscriberEmail,
|
||||
email_client::EmailClient,
|
||||
routes::AppError,
|
||||
routes::{AppError, not_found_html},
|
||||
startup::AppState,
|
||||
templates::{
|
||||
MessageTemplate, NotFoundTemplate, UnsubscribeConfirmTemplate, UnsubscribeTemplate,
|
||||
},
|
||||
templates::{MessageTemplate, UnsubscribeConfirmTemplate, UnsubscribeTemplate},
|
||||
};
|
||||
use anyhow::Context;
|
||||
use askama::Template;
|
||||
@@ -14,7 +12,6 @@ use axum::{
|
||||
extract::{Query, State},
|
||||
response::{Html, IntoResponse, Response},
|
||||
};
|
||||
use reqwest::StatusCode;
|
||||
use sqlx::{Executor, PgPool};
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
@@ -52,9 +49,9 @@ pub async fn post_unsubscribe(
|
||||
.await
|
||||
.context("Failed to send a confirmation email.")?;
|
||||
}
|
||||
let template = MessageTemplate::Success {
|
||||
message: "If you are a subscriber, you'll receive a confirmation link shortly.".into(),
|
||||
};
|
||||
let template = MessageTemplate::success(
|
||||
"If you are a subscriber, you'll receive a confirmation link shortly.".into(),
|
||||
);
|
||||
Ok(Html(template.render().unwrap()).into_response())
|
||||
}
|
||||
|
||||
@@ -124,11 +121,7 @@ pub async fn unsubscribe_confirm(
|
||||
|
||||
if result.rows_affected() == 0 {
|
||||
tracing::info!("Unsubscribe token is not tied to any confirmed user");
|
||||
Ok((
|
||||
StatusCode::NOT_FOUND,
|
||||
Html(NotFoundTemplate.render().unwrap()),
|
||||
)
|
||||
.into_response())
|
||||
Ok(not_found_html())
|
||||
} else {
|
||||
tracing::info!("User successfully removed");
|
||||
Ok(Html(UnsubscribeConfirmTemplate.render().unwrap()).into_response())
|
||||
|
||||
Reference in New Issue
Block a user