diff --git a/src/main.rs b/src/main.rs index c7f33e3..f82b62c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -130,7 +130,8 @@ async fn main() -> std::io::Result<()> { .service( web::scope("/profile") .route("/{user_id}", web::get().to(views::view_profile)), - ), + ) + .route("/users/", web::get().to(views::index_users)), ) .service( web::scope("/edit") diff --git a/src/views.rs b/src/views.rs index fc1af5b..5f84102 100644 --- a/src/views.rs +++ b/src/views.rs @@ -67,6 +67,27 @@ pub(crate) async fn index( } } +/// Show the list of all available links if a user is authenticated +pub(crate) async fn index_users( + tera: web::Data, + id: Identity, +) -> Result { + use super::schema::users::dsl::users; + if let Some(id) = id.identity() { + let connection = establish_connection()?; + let all_users: Vec = users.load(&connection)?; + + let mut data = Context::new(); + data.insert("name", &id); + data.insert("title", "Benutzer der Freien Hochschule Stuttgart"); + data.insert("users", &all_users); + + let rendered = tera.render("index_users.html", &data)?; + Ok(HttpResponse::Ok().body(rendered)) + } else { + Ok(redirect_builder("/admin/login/")) + } +} pub(crate) async fn view_link( tera: web::Data, id: Identity, diff --git a/templates/admin.html b/templates/admin.html index 36124c4..1cdf997 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -14,6 +14,7 @@
  • Liste
  • Hinzufügen
  • Einladen
  • +
  • Benutzer
  • Abmelden
  • Herzlich willkommen {{ name }}
    diff --git a/templates/index_users.html b/templates/index_users.html new file mode 100644 index 0000000..bbf454e --- /dev/null +++ b/templates/index_users.html @@ -0,0 +1,40 @@ +{% extends "admin.html" %} + + +{% block head2 %} + +{% endblock %} + +{% block admin %} + + + + + + + + {% for user in users %} + + + + + + {% endfor %} +
    + Kürzel + + Ziellink + + Benutzername +
    + {{user.id}} + + + {{ user.email }} + + + + {{ user.username }} + +
    +{% endblock %} \ No newline at end of file