mirror of
https://github.com/kevachat/webapp.git
synced 2025-01-10 23:08:14 +00:00
draft users list
This commit is contained in:
parent
8b1cb0acdd
commit
bdfc6420ae
@ -35,6 +35,96 @@ class UserController extends AbstractController
|
||||
);
|
||||
}
|
||||
|
||||
#[Route(
|
||||
'/users',
|
||||
name: 'user_list',
|
||||
methods:
|
||||
[
|
||||
'GET'
|
||||
]
|
||||
)]
|
||||
public function list(
|
||||
?Request $request
|
||||
): Response
|
||||
{
|
||||
$list = [];
|
||||
|
||||
// Check client connection
|
||||
if ($client = $this->_client())
|
||||
{
|
||||
// Check users database accessible
|
||||
if ($namespace = $this->_namespace($client))
|
||||
{
|
||||
// Collect usernames
|
||||
foreach ((array) $client->kevaFilter($namespace) as $user)
|
||||
{
|
||||
// Check record valid
|
||||
if (empty($user['key']) || empty($user['height']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip values with meta keys
|
||||
if (str_starts_with($user['key'], '_'))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Validate username regex
|
||||
if (!preg_match($this->getParameter('app.add.user.name.regex'), $user['key']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[] =
|
||||
[
|
||||
'name' => $user['key'],
|
||||
'height' => $user['height'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by height
|
||||
array_multisort(
|
||||
array_column(
|
||||
$list,
|
||||
'height'
|
||||
),
|
||||
SORT_ASC,
|
||||
$list
|
||||
);
|
||||
|
||||
// RSS
|
||||
if ('rss' === $request->get('feed'))
|
||||
{
|
||||
$response = new Response();
|
||||
|
||||
$response->headers->set(
|
||||
'Content-Type',
|
||||
'text/xml'
|
||||
);
|
||||
|
||||
return $this->render(
|
||||
'default/user/list.rss.twig',
|
||||
[
|
||||
'list' => $list,
|
||||
'request' => $request
|
||||
],
|
||||
$response
|
||||
);
|
||||
}
|
||||
|
||||
// HTML
|
||||
return $this->render(
|
||||
'default/user/list.html.twig',
|
||||
[
|
||||
'list' => $list,
|
||||
'request' => $request
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[Route(
|
||||
'/join',
|
||||
name: 'user_join',
|
||||
|
28
templates/default/user/list.html.twig
Normal file
28
templates/default/user/list.html.twig
Normal file
@ -0,0 +1,28 @@
|
||||
{% extends 'default/layout.html.twig' %}
|
||||
{% block head_title_content %}{{ 'Users' | trans }} - {{ app.name }}{% endblock %}
|
||||
{% block main_content %}
|
||||
{% if list | length %}
|
||||
<ul>
|
||||
{% for user in list %}
|
||||
<li>
|
||||
<div>
|
||||
<strong>
|
||||
{{ user.name }}
|
||||
</strong>
|
||||
<i style="float:right">{# @TODO #}
|
||||
{#{{ 'at block' | trans }}#} {{ user.height }}
|
||||
</i>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<ul>
|
||||
<li>
|
||||
<div>
|
||||
{{ 'users not found or database locked by new transaction' | trans }}
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% endblock %}
|
16
templates/default/user/list.rss.twig
Normal file
16
templates/default/user/list.rss.twig
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<channel>
|
||||
<atom:link href="{{ url('user_list') }}" rel="self" type="application/rss+xml"></atom:link>
|
||||
<title>{{ 'Users' | trans }} - {{ app.name }}</title>
|
||||
<link>{{ url('user_list') }}</link>
|
||||
{% for user in list %}
|
||||
<item>
|
||||
<title>@{{ user.name }} {{ 'joined' | trans }} {{ app.name }}</title>
|
||||
<guid>{{ url('user_list', { _fragment : user.name }) }}</guid>
|
||||
<link>{{ url('user_list', { _fragment : user.name }) }}</link>
|
||||
<description>{{ "Let's welcome" | trans }} @{{ user.name }}!</description>
|
||||
</item>
|
||||
{% endfor %}
|
||||
</channel>
|
||||
</rss>
|
Loading…
Reference in New Issue
Block a user