keep sign method in cookies

This commit is contained in:
ghost 2023-12-18 06:42:46 +02:00
parent bc5307bc2c
commit ec8fe840ff
5 changed files with 42 additions and 4 deletions

4
.env
View File

@ -19,7 +19,7 @@ APP_ENV=dev
APP_SECRET=EDIT_ME
###< symfony/framework-bundle ###
APP_VERSION=1.7.0
APP_VERSION=1.8.0
APP_NAME=KevaChat
@ -71,7 +71,7 @@ APP_MODERATOR_REMOTE_IP=
APP_ADD_USER_NAME_REGEX=/^[0-9A-z-]{2,16}$/ui
# User name reserved (case insensitive) separated with |
APP_ADD_USER_NAME_BLACKLIST=KevaChat|admin|moderator|test
APP_ADD_USER_NAME_BLACKLIST=KevaChat|admin|moderator|anon|test
# Delay before have ability to create new username again
APP_ADD_USER_REMOTE_IP_DELAY=86400

View File

@ -179,13 +179,29 @@ class ModuleController extends AbstractController
$message = $request->get('message');
}
// Detect active sign version
if (in_array((string) $request->get('sign'), ['anon', 'username']))
{
$sign = $request->get('sign');
}
else if (in_array((string) $request->cookies->get('KEVACHAT_SIGN'), ['anon', 'username']))
{
$sign = $request->cookies->get('KEVACHAT_SIGN');
}
else
{
$sign = 'anon';
}
return $this->render(
'default/module/post.html.twig',
[
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'sign' => $request->get('sign'),
'error' => $request->get('error'),
'sign' => $sign,
'message' => $message,
'username' => $username,
'enabled' =>

View File

@ -320,6 +320,7 @@ class RoomController extends AbstractController
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'message' => $request->get('message'),
'sign' => $request->get('sign'),
'error' => $this->getParameter('app.maintenance'),
'_fragment' => 'latest'
]
@ -367,6 +368,7 @@ class RoomController extends AbstractController
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'message' => $request->get('message'),
'sign' => $request->get('sign'),
'error' => $translator->trans('Namespace not found on this node!'),
'_fragment' => 'latest'
]
@ -396,6 +398,7 @@ class RoomController extends AbstractController
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'message' => $request->get('message'),
'sign' => $request->get('sign'),
'error' => $translator->trans('Namespace for read only!'),
'_fragment' => 'latest'
]
@ -411,6 +414,7 @@ class RoomController extends AbstractController
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'message' => $request->get('message'),
'sign' => $request->get('sign'),
'error' => sprintf(
$translator->trans('Access denied for host %s!'),
$request->getClientIp()
@ -429,6 +433,7 @@ class RoomController extends AbstractController
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'message' => $request->get('message'),
'sign' => $request->get('sign'),
'error' => sprintf(
$translator->trans('Access restricted for host %s!'),
$request->getClientIp()
@ -447,6 +452,7 @@ class RoomController extends AbstractController
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'message' => $request->get('message'),
'sign' => $request->get('sign'),
'error' => $translator->trans('Message length out of KevaCoin protocol limits'),
'_fragment' => 'latest'
]
@ -462,6 +468,7 @@ class RoomController extends AbstractController
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'message' => $request->get('message'),
'sign' => $request->get('sign'),
'error' => sprintf(
$translator->trans('Message does not match node requirements: %s'),
$this->getParameter('app.add.post.value.regex')
@ -481,6 +488,7 @@ class RoomController extends AbstractController
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'message' => $request->get('message'),
'sign' => $request->get('sign'),
'error' => sprintf(
$translator->trans('Please wait %s seconds before post new message!'),
(int) $this->getParameter('app.add.post.remote.ip.delay') - (time() - $delay)
@ -499,6 +507,7 @@ class RoomController extends AbstractController
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'message' => $request->get('message'),
'sign' => $request->get('sign'),
'error' => sprintf(
$translator->trans('Insufficient funds, wallet: %s'),
$this->getParameter('app.kevacoin.boost.address')
@ -520,6 +529,16 @@ class RoomController extends AbstractController
}
}
// Save sign version to cookies
if (in_array((string) $request->get('sign'), ['anon', 'username']))
{
setcookie(
'KEVACHAT_SIGN',
$request->get('sign'),
time() + $this->getParameter('app.session.default.timeout')
);
}
// Send message to DHT
if (
$client->kevaPut(
@ -546,6 +565,7 @@ class RoomController extends AbstractController
[
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'sign' => $request->get('sign'),
'error' => null,
'message' => null,
'_fragment' => 'latest'
@ -560,6 +580,7 @@ class RoomController extends AbstractController
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'message' => $request->get('message'),
'sign' => $request->get('sign'),
'error' => $translator->trans('Internal error! Please feedback'),
'_fragment' => 'latest'
]

View File

@ -120,6 +120,7 @@ class UserController extends AbstractController
// Delete cookies
setcookie('KEVACHAT_SESSION', '', -1);
setcookie('KEVACHAT_SIGN', '', -1);
}
// Redirect to main page

View File

@ -4,7 +4,7 @@
<output name="error" for="form-post-message">{{ error }}</output>
{% endif %}
<textarea name="message" id="form-post-message" placeholder="{{ 'enter your message...' | trans }}">{{ message }}</textarea>
{% if sign == 'anon' or sign != 'username' %}
{% if sign == 'anon' or sign == '' %}
<input type="radio" name="sign" value="anon" id="form-post-sign-anon" checked="checked" />
{% else %}
<input type="radio" name="sign" value="anon" id="form-post-sign-anon" />