Adding user view

closes #7
This commit is contained in:
Dietrich 2021-02-09 14:06:34 +01:00
parent 5d28707e18
commit 10933dd48b
Signed by: dietrich
GPG Key ID: 9F3C20C0F85DF67C
4 changed files with 64 additions and 1 deletions

View File

@ -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")

View File

@ -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<Tera>,
id: Identity,
) -> Result<HttpResponse, ServerError> {
use super::schema::users::dsl::users;
if let Some(id) = id.identity() {
let connection = establish_connection()?;
let all_users: Vec<User> = 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<Tera>,
id: Identity,

View File

@ -14,6 +14,7 @@
<li><a href="/admin/index/">Liste</a></li>
<li><a href="/admin/submit/">Hinzufügen</a></li>
<li><a href="/admin/signup/">Einladen</a></li>
<li><a href="/admin/view/users/">Benutzer</a></li>
<li style="float:right"><a href="/admin/logout/">Abmelden</a></li>
<li style="float:right">
<div class="willkommen">Herzlich willkommen {{ name }}</div>

View File

@ -0,0 +1,40 @@
{% extends "admin.html" %}
{% block head2 %}
<script src="/static/sorttable.js"></script>
{% endblock %}
{% block admin %}
<table class="sortable">
<tr>
<th>
Kürzel
</th>
<th>
Ziellink
</th>
<th>
Benutzername
</th>
</tr>
{% for user in users %}
<tr>
<td>
<a href="/admin/view/profile/{{user.id}}"><span>{{user.id}}</span>
</a>
</td>
<td>
<a href="/admin/view/profile/{{user.id}}">{{ user.email }}
</a>
</td>
<td>
<a href="/admin/view/profile/{{user.id}}"><small>{{ user.username }}</small>
</a>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}