diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 342dfc6..3dfc206 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -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', diff --git a/templates/default/user/list.html.twig b/templates/default/user/list.html.twig new file mode 100644 index 0000000..3872205 --- /dev/null +++ b/templates/default/user/list.html.twig @@ -0,0 +1,28 @@ +{% extends 'default/layout.html.twig' %} +{% block head_title_content %}{{ 'Users' | trans }} - {{ app.name }}{% endblock %} +{% block main_content %} + {% if list | length %} + + {% else %} + + {% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/default/user/list.rss.twig b/templates/default/user/list.rss.twig new file mode 100644 index 0000000..eb38d83 --- /dev/null +++ b/templates/default/user/list.rss.twig @@ -0,0 +1,16 @@ + + + + + {{ 'Users' | trans }} - {{ app.name }} + {{ url('user_list') }} + {% for user in list %} + + @{{ user.name }} {{ 'joined' | trans }} {{ app.name }} + {{ url('user_list', { _fragment : user.name }) }} + {{ url('user_list', { _fragment : user.name }) }} + {{ "Let's welcome" | trans }} @{{ user.name }}! + + {% endfor %} + + \ No newline at end of file