From 56b71230e9d5458135d95bd8493544acde70c33f Mon Sep 17 00:00:00 2001 From: traxys Date: Sun, 8 Oct 2023 11:37:52 +0200 Subject: [PATCH] Remove name as it maps to emails in stalwart --- migrations/20231008091205_no_name.sql | 2 ++ src/main.rs | 44 ------------------------ templates/home.html | 48 +++++++-------------------- 3 files changed, 14 insertions(+), 80 deletions(-) create mode 100644 migrations/20231008091205_no_name.sql diff --git a/migrations/20231008091205_no_name.sql b/migrations/20231008091205_no_name.sql new file mode 100644 index 0000000..90ec567 --- /dev/null +++ b/migrations/20231008091205_no_name.sql @@ -0,0 +1,2 @@ +-- Add migration script here +ALTER TABLE accounts DROP COLUMN name; diff --git a/src/main.rs b/src/main.rs index dc8d886..6c37065 100644 --- a/src/main.rs +++ b/src/main.rs @@ -567,11 +567,6 @@ async fn home( ) .fetch(&state.db); - let name = sqlx::query!("SELECT name FROM accounts WHERE id = $1", user) - .fetch_optional(&state.db) - .await? - .and_then(|r| r.name); - let mut aliases: HashMap<_, _> = aliases.into_iter().map(|a| (a.mail, Vec::new())).collect(); while let Some(alias) = alias_stream.try_next().await? { aliases.get_mut(&alias.alias).unwrap().push(alias.recipient); @@ -587,7 +582,6 @@ async fn home( context.insert("mails", &mails); context.insert("mail_domain", &state.mail_domain); context.insert("aliases", &aliases); - context.insert("name", &name); if let Some(err) = query.user_error { tracing::info!("User error: {err:?}"); context.insert("user_error", &err.to_string()); @@ -844,43 +838,6 @@ async fn set_password( Ok(Redirect::to("/")) } -#[derive(Deserialize, Debug)] -struct Name { - name: String, -} - -#[tracing::instrument(skip(state))] -async fn set_name( - state: State>, - User(user): User, - Form(name): Form, -) -> Result { - let taken = sqlx::query!( - "SELECT COUNT(*) FROM accounts WHERE name = $1 AND id != $2", - name.name, - user - ) - .fetch_one(&state.db) - .await? - .count - .expect("count returned null") - != 0; - - if taken { - Ok(UserError::NameAlreadyExists(name.name).into()) - } else { - sqlx::query!( - "UPDATE accounts SET name = $1 WHERE id = $2", - name.name, - user - ) - .execute(&state.db) - .await?; - - Ok(Redirect::to("/")) - } -} - #[tokio::main] async fn main() -> color_eyre::Result<()> { color_eyre::install()?; @@ -918,7 +875,6 @@ async fn main() -> color_eyre::Result<()> { .route("/alias/recipient/delete", post(delete_recipient)) .route("/alias/delete", post(delete_alias)) .route("/password", post(set_password)) - .route("/name", post(set_name)) .fallback(page_not_found) .with_state(Arc::new(AppState { db, diff --git a/templates/home.html b/templates/home.html index 7554050..402a636 100644 --- a/templates/home.html +++ b/templates/home.html @@ -99,43 +99,19 @@ {% if user_error %}
{{ user_error }}
{% endif %} -

- Account - {% if name %} - ({{ name }}) - {% else %} - (no name, disabled) - {% endif %} -

-
-
-
-
-
- - -
- -
+

Account

+
+
+
+ +
-
- -
- - -
- - -
-
+ +

Mails