Add emails

This commit is contained in:
traxys 2023-08-16 22:12:14 +02:00
parent 85c559cfb1
commit f1089232c3
3 changed files with 27 additions and 3 deletions

View file

@ -0,0 +1,5 @@
-- Add migration script here
CREATE TABLE emails (
id uuid REFERENCES accounts(id) NOT NULL,
mail TEXT NOT NULL PRIMARY KEY
);

View file

@ -486,8 +486,21 @@ where
}
}
async fn home(_: State<Arc<AppState>>, User(_): User) -> Result<Html<String>, Error> {
Ok(Html(TEMPLATES.render("home.html", &global_context())?))
#[derive(Serialize, Deserialize)]
struct Mail {
mail: String,
}
async fn home(state: State<Arc<AppState>>, User(user): User) -> Result<Html<String>, 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]

View file

@ -12,7 +12,13 @@
<body>
<section class="section">
<div class="container">
<h1 class="title">Mail management</h1>
<h1 class="title is-1">Mail management</h1>
<h2 class="title is-2">Mails</h2>
<ul>
{% for mail in mails %}
<li>{{mail.mail}}</li>
{% endfor %}
</ul>
</div>
</section>
</body>