diff --git a/migrations/20230816195409_email.sql b/migrations/20230816195409_email.sql new file mode 100644 index 0000000..0e21b6e --- /dev/null +++ b/migrations/20230816195409_email.sql @@ -0,0 +1,5 @@ +-- Add migration script here +CREATE TABLE emails ( + id uuid REFERENCES accounts(id) NOT NULL, + mail TEXT NOT NULL PRIMARY KEY +); diff --git a/src/main.rs b/src/main.rs index 6a96d58..5300b3b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -486,8 +486,21 @@ where } } -async fn home(_: State>, User(_): User) -> Result, Error> { - Ok(Html(TEMPLATES.render("home.html", &global_context())?)) +#[derive(Serialize, Deserialize)] +struct Mail { + mail: String, +} + +async fn home(state: State>, User(user): User) -> Result, Error> { + let mails = sqlx::query_as!(Mail, "SELECT mail FROM emails WHERE id = $1", user) + .fetch_all(&state.db) + .await?; + + let mut context = tera::Context::new(); + context.insert("mails", &mails); + context.extend(global_context()); + + Ok(Html(TEMPLATES.render("home.html", &context)?)) } #[tokio::main] diff --git a/templates/home.html b/templates/home.html index a3f7e5d..f6dd9c1 100644 --- a/templates/home.html +++ b/templates/home.html @@ -12,7 +12,13 @@
-

Mail management

+

Mail management

+

Mails

+
    + {% for mail in mails %} +
  • {{mail.mail}}
  • + {% endfor %} +