mirror of
https://github.com/kevachat/webapp.git
synced 2025-02-02 01:44:27 +00:00
add user module
This commit is contained in:
parent
aaad5a6e4b
commit
332f7416f0
@ -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
Normal file
9
templates/default/module/user.html.twig
Normal file
@ -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>
|
@ -33,4 +33,16 @@
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block footer_content %}
|
||||
{{
|
||||
render(
|
||||
controller(
|
||||
'App\\Controller\\ModuleController::user',
|
||||
{
|
||||
request: request
|
||||
}
|
||||
)
|
||||
)
|
||||
}}
|
||||
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user