Basic dashboard for newsletter issue and password systems
This commit is contained in:
@@ -6,11 +6,10 @@ use crate::{
|
||||
use axum::{
|
||||
Extension, Form,
|
||||
extract::State,
|
||||
response::{Html, IntoResponse, Redirect, Response},
|
||||
response::{IntoResponse, Redirect, Response},
|
||||
};
|
||||
use axum_messages::Messages;
|
||||
use secrecy::{ExposeSecret, SecretString};
|
||||
use std::fmt::Write;
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct PasswordFormData {
|
||||
@@ -19,18 +18,6 @@ pub struct PasswordFormData {
|
||||
pub new_password_check: SecretString,
|
||||
}
|
||||
|
||||
pub async fn change_password_form(messages: Messages) -> Result<Response, AdminError> {
|
||||
let mut error_html = String::new();
|
||||
for message in messages {
|
||||
writeln!(error_html, "<p><i>{}</i></p>", message).unwrap();
|
||||
}
|
||||
Ok(Html(format!(
|
||||
include_str!("html/change_password_form.html"),
|
||||
error_html
|
||||
))
|
||||
.into_response())
|
||||
}
|
||||
|
||||
pub async fn change_password(
|
||||
Extension(AuthenticatedUser { user_id, username }): Extension<AuthenticatedUser>,
|
||||
State(AppState {
|
||||
|
||||
@@ -1,11 +1,25 @@
|
||||
use crate::authentication::AuthenticatedUser;
|
||||
use askama::Template;
|
||||
use axum::{
|
||||
Extension,
|
||||
response::{Html, IntoResponse, Response},
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "../templates/dashboard.html")]
|
||||
struct DashboardTemplate {
|
||||
username: String,
|
||||
idempotency_key: String,
|
||||
}
|
||||
|
||||
pub async fn admin_dashboard(
|
||||
Extension(AuthenticatedUser { username, .. }): Extension<AuthenticatedUser>,
|
||||
) -> Response {
|
||||
Html(format!(include_str!("html/dashboard.html"), username)).into_response()
|
||||
let idempotency_key = Uuid::new_v4().to_string();
|
||||
let template = DashboardTemplate {
|
||||
username,
|
||||
idempotency_key,
|
||||
};
|
||||
Html(template.render().unwrap()).into_response()
|
||||
}
|
||||
|
||||
@@ -8,11 +8,10 @@ use anyhow::Context;
|
||||
use axum::{
|
||||
Extension, Form,
|
||||
extract::State,
|
||||
response::{Html, IntoResponse, Redirect, Response},
|
||||
response::{IntoResponse, Redirect, Response},
|
||||
};
|
||||
use axum_messages::Messages;
|
||||
use sqlx::{Executor, Postgres, Transaction};
|
||||
use std::fmt::Write;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
@@ -23,19 +22,6 @@ pub struct BodyData {
|
||||
idempotency_key: String,
|
||||
}
|
||||
|
||||
pub async fn publish_newsletter_form(messages: Messages) -> Response {
|
||||
let mut error_html = String::new();
|
||||
for message in messages {
|
||||
writeln!(error_html, "<p><i>{}</i></p>", message).unwrap();
|
||||
}
|
||||
let idempotency_key = Uuid::new_v4();
|
||||
Html(format!(
|
||||
include_str!("html/send_newsletter_form.html"),
|
||||
idempotency_key, error_html
|
||||
))
|
||||
.into_response()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn insert_newsletter_issue(
|
||||
transaction: &mut Transaction<'static, Postgres>,
|
||||
|
||||
@@ -118,11 +118,8 @@ pub fn app(
|
||||
};
|
||||
let admin_routes = Router::new()
|
||||
.route("/dashboard", get(admin_dashboard))
|
||||
.route("/password", get(change_password_form).post(change_password))
|
||||
.route(
|
||||
"/newsletters",
|
||||
get(publish_newsletter_form).post(publish_newsletter),
|
||||
)
|
||||
.route("/password", post(change_password))
|
||||
.route("/newsletters", post(publish_newsletter))
|
||||
.route("/logout", post(logout))
|
||||
.layer(middleware::from_fn(require_auth));
|
||||
Router::new()
|
||||
|
||||
Reference in New Issue
Block a user