Basic dashboard for newsletter issue and password systems

This commit is contained in:
Alphonse Paix
2025-09-17 01:47:03 +02:00
parent 1d027b5460
commit 88dad022ce
6 changed files with 272 additions and 36 deletions

View File

@@ -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 {

View File

@@ -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()
}

View File

@@ -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>,