Browse Source

add user module

main
ghost 11 months ago
parent
commit
332f7416f0
  1. 32
      src/Controller/ModuleController.php
  2. 9
      templates/default/module/user.html.twig
  3. 12
      templates/default/user/list.html.twig

32
src/Controller/ModuleController.php

@ -228,4 +228,36 @@ class ModuleController extends AbstractController
] ]
); );
} }
public function user(
Request $request
): Response
{
// Check user session exist
$username = false;
if (!empty($request->cookies->get('KEVACHAT_SESSION')) && preg_match('/[A-z0-9]{32}/', $request->cookies->get('KEVACHAT_SESSION')))
{
// Connect memcached
$memcached = new \Memcached();
$memcached->addServer(
$this->getParameter('app.memcached.host'),
$this->getParameter('app.memcached.port')
);
// Check username exist for this session
if ($value = $memcached->get($request->cookies->get('KEVACHAT_SESSION')))
{
$username = $value;
}
}
return $this->render(
'default/module/user.html.twig',
[
'username' => $username,
'request' => $request
]
);
}
} }

9
templates/default/module/user.html.twig

@ -0,0 +1,9 @@
<form>
{% if username %}
@{{ username }}
|
<a href="{{ path('user_logout') }}">{{ 'logout' | trans }}</a>
{% else %}
<a href="{{ path('user_join') }}">{{ 'register' | trans }}</a>
{% endif %}
</form>

12
templates/default/user/list.html.twig

@ -33,4 +33,16 @@
</li> </li>
</ul> </ul>
{% endif %} {% endif %}
{% endblock %}
{% block footer_content %}
{{
render(
controller(
'App\\Controller\\ModuleController::user',
{
request: request
}
)
)
}}
{% endblock %} {% endblock %}
Loading…
Cancel
Save