Friendlier logged-out notice with session duration and login link
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -24,7 +24,14 @@
|
||||
{% endif %}
|
||||
|
||||
{% if loginRequired %}
|
||||
<div class="survey-alert warning">{{ 'survey.edit.login_required'|trans }}</div>
|
||||
<div class="survey-card survey-grid">
|
||||
<div class="survey-alert warning">{{ 'survey.edit.login_required'|trans({'%minutes%': sessionMinutes|default(24)}) }}</div>
|
||||
{% if loginUrl|default(null) %}
|
||||
<div class="survey-button-row">
|
||||
<a class="survey-button primary" href="{{ loginUrl }}">{{ 'survey.list.login_link'|trans }}</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% elseif entryNotAllowed|default(false) %}
|
||||
<div class="survey-card survey-grid">
|
||||
<div class="survey-alert warning">{{ 'survey.edit.entry_not_allowed'|trans }}</div>
|
||||
|
||||
@@ -24,7 +24,14 @@
|
||||
{% endif %}
|
||||
|
||||
{% if loginRequired %}
|
||||
<div class="survey-alert warning">{{ 'survey.list.login_required'|trans }}</div>
|
||||
<div class="survey-card survey-grid">
|
||||
<div class="survey-alert warning">{{ 'survey.list.login_required'|trans({'%minutes%': sessionMinutes|default(24)}) }}</div>
|
||||
{% if loginUrl|default(null) %}
|
||||
<div class="survey-button-row">
|
||||
<a class="survey-button primary" href="{{ loginUrl }}">{{ 'survey.list.login_link'|trans }}</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="survey-button-row">
|
||||
{% if createUrl %}
|
||||
|
||||
@@ -21,6 +21,7 @@ use Mummert\SurveyBundle\Repository\SurveyEditorRepository;
|
||||
use Mummert\SurveyBundle\Repository\SurveyQuestionRepository;
|
||||
use Mummert\SurveyBundle\Repository\SurveyRepository;
|
||||
use Mummert\SurveyBundle\Service\SurveyEditorService;
|
||||
use Mummert\SurveyBundle\Service\SurveyLoginInfoService;
|
||||
use Mummert\SurveyBundle\Service\SurveyStructureService;
|
||||
use Mummert\SurveyBundle\Service\SurveySubmissionService;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
@@ -41,6 +42,7 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController
|
||||
private readonly SurveyEditorService $surveyEditorService,
|
||||
private readonly SurveySubmissionService $surveySubmissionService,
|
||||
private readonly SurveyStructureService $surveyStructureService,
|
||||
private readonly SurveyLoginInfoService $surveyLoginInfoService,
|
||||
private readonly FormFactoryInterface $formFactory,
|
||||
#[Autowire('%kernel.debug%')]
|
||||
private readonly bool $kernelDebug = false,
|
||||
@@ -53,6 +55,8 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController
|
||||
|
||||
if ($memberId <= 0) {
|
||||
$template->set('loginRequired', true);
|
||||
$template->set('loginUrl', $this->resolveLoginUrl());
|
||||
$template->set('sessionMinutes', $this->surveyLoginInfoService->getSessionLifetimeMinutes());
|
||||
$template->set('entryNotAllowed', false);
|
||||
$template->set('backUrl', $this->resolveListUrl($model));
|
||||
$template->set('createQuestionMode', false);
|
||||
@@ -579,4 +583,11 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController
|
||||
|
||||
return $page instanceof PageModel ? $page : null;
|
||||
}
|
||||
|
||||
private function resolveLoginUrl(): ?string
|
||||
{
|
||||
$page = $this->surveyLoginInfoService->findLoginPage();
|
||||
|
||||
return $page instanceof PageModel ? $this->generateContentUrl($page) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ use Mummert\SurveyBundle\Model\SurveyModel;
|
||||
use Mummert\SurveyBundle\Repository\SurveyEditorRepository;
|
||||
use Mummert\SurveyBundle\Repository\SurveyRepository;
|
||||
use Mummert\SurveyBundle\Service\SurveyEditorService;
|
||||
use Mummert\SurveyBundle\Service\SurveyLoginInfoService;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -28,6 +29,7 @@ final class MemberSurveyListController extends AbstractFrontendModuleController
|
||||
private readonly SurveyRepository $surveyRepository,
|
||||
private readonly SurveyEditorRepository $surveyEditorRepository,
|
||||
private readonly SurveyEditorService $surveyEditorService,
|
||||
private readonly SurveyLoginInfoService $surveyLoginInfoService,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -38,6 +40,8 @@ final class MemberSurveyListController extends AbstractFrontendModuleController
|
||||
|
||||
if (!$user instanceof FrontendUser) {
|
||||
$template->set('loginRequired', true);
|
||||
$template->set('loginUrl', $this->resolveLoginUrl());
|
||||
$template->set('sessionMinutes', $this->surveyLoginInfoService->getSessionLifetimeMinutes());
|
||||
$template->set('surveys', []);
|
||||
$template->set('createUrl', null);
|
||||
$template->set('templatesOnly', $templatesOnly);
|
||||
@@ -157,4 +161,11 @@ final class MemberSurveyListController extends AbstractFrontendModuleController
|
||||
|
||||
return $page instanceof PageModel ? $page : null;
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveLoginUrl(): ?string
|
||||
{
|
||||
$page = $this->surveyLoginInfoService->findLoginPage();
|
||||
|
||||
return $page instanceof PageModel ? $this->generateContentUrl($page) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mummert\SurveyBundle\Service;
|
||||
|
||||
use Contao\CoreBundle\Framework\ContaoFramework;
|
||||
use Contao\PageModel;
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
/**
|
||||
* Informationen für den "nicht eingeloggt"-Hinweis der Mitglieder-Module:
|
||||
* die Seite mit dem Login-Modul und die Sitzungsdauer (PHP session.gc_maxlifetime).
|
||||
*/
|
||||
final class SurveyLoginInfoService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Connection $connection,
|
||||
private readonly ContaoFramework $framework,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Erste veröffentlichte Seite, auf der ein Contao-Login-Modul eingebunden ist.
|
||||
*/
|
||||
public function findLoginPage(): ?PageModel
|
||||
{
|
||||
$pageId = $this->connection->fetchOne(
|
||||
<<<'SQL'
|
||||
SELECT a.pid
|
||||
FROM tl_content c
|
||||
INNER JOIN tl_article a ON a.id = c.pid
|
||||
INNER JOIN tl_module m ON m.id = c.module
|
||||
INNER JOIN tl_page p ON p.id = a.pid
|
||||
WHERE c.type = 'module' AND m.type = 'login' AND c.invisible = '' AND a.published = '1' AND p.published = '1'
|
||||
ORDER BY p.sorting ASC, a.sorting ASC, c.sorting ASC
|
||||
LIMIT 1
|
||||
SQL,
|
||||
);
|
||||
|
||||
if (false === $pageId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$page = $this->framework->getAdapter(PageModel::class)->findById((int) $pageId);
|
||||
|
||||
return $page instanceof PageModel ? $page : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maximale Inaktivitätsdauer einer Sitzung in Minuten (aufgerundet).
|
||||
*/
|
||||
public function getSessionLifetimeMinutes(): int
|
||||
{
|
||||
$seconds = (int) ini_get('session.gc_maxlifetime');
|
||||
|
||||
return max(1, (int) ceil(($seconds > 0 ? $seconds : 1440) / 60));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
survey:
|
||||
list:
|
||||
login_required: "Dieser Bereich verwendet den normalen Contao-Mitgliederlogin. Bitte binden Sie das Modul auf einer geschützten Seite oder mit einer separaten Login-Seite ein."
|
||||
login_required: "Sie sind nicht oder nicht mehr im Umfragetool des Kinderschutzbund Sachsen e. V. eingeloggt. Für diesen Bereich benötigen Sie ein gültiges Login. Vielleicht haben Sie die maximal zulässige Sitzungsdauer von %minutes% Minuten überschritten."
|
||||
login_link: "Zur Anmeldung"
|
||||
create: "Neue Umfrage anlegen"
|
||||
duplicate: "Duplizieren"
|
||||
duplicate_confirm: "Sind Sie sicher, dass Sie die Umfrage \"%title%\" mit allen Fragen duplizieren wollen?"
|
||||
@@ -45,7 +46,7 @@ survey:
|
||||
section_hint: "Ein Themenbereich ist keine Frage, sondern eine Überschrift: Alle folgenden Fragen bis zum nächsten Themenbereich gehören dazu. Teilnehmende sehen den Bereich oberhalb jeder Frage."
|
||||
insert_into_section: "Die neue Frage wird am Ende des Themenbereichs „%section%“ eingefügt."
|
||||
insert_before_first_section: "Die neue Frage wird vor dem ersten Themenbereich eingefügt."
|
||||
login_required: "Dieses Frontendmodul ist für eingeloggte Mitglieder gedacht. Nutzen Sie den normalen Contao-Mitgliederlogin auf einer geschützten Seite."
|
||||
login_required: "Sie sind nicht oder nicht mehr im Umfragetool des Kinderschutzbund Sachsen e. V. eingeloggt. Für diesen Bereich benötigen Sie ein gültiges Login. Vielleicht haben Sie die maximal zulässige Sitzungsdauer von %minutes% Minuten überschritten."
|
||||
entry_not_allowed: "Diese Seite kann nicht direkt geöffnet werden. Bitte wechseln Sie über die Umfragen-Liste in den Bearbeitungsmodus."
|
||||
create_title: "Neue Umfrage erstellen"
|
||||
label_title: "Titel"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
survey:
|
||||
list:
|
||||
login_required: "This area uses the regular Contao member login. Please place the module on a protected page or provide a separate login page."
|
||||
login_required: "You are not (or no longer) logged in to the survey tool of Kinderschutzbund Sachsen e. V. A valid login is required for this area. You may have exceeded the maximum session duration of %minutes% minutes."
|
||||
login_link: "Go to login"
|
||||
create: "Create new survey"
|
||||
duplicate: "Duplicate"
|
||||
duplicate_confirm: "Are you sure you want to duplicate the survey \"%title%\" with all questions?"
|
||||
@@ -45,7 +46,7 @@ survey:
|
||||
section_hint: "A topic section is not a question but a heading: all following questions up to the next section belong to it. Participants see the section above every question."
|
||||
insert_into_section: "The new question will be added at the end of the topic section “%section%”."
|
||||
insert_before_first_section: "The new question will be inserted before the first topic section."
|
||||
login_required: "This frontend module is intended for logged-in members. Please use the regular Contao member login on a protected page."
|
||||
login_required: "You are not (or no longer) logged in to the survey tool of Kinderschutzbund Sachsen e. V. A valid login is required for this area. You may have exceeded the maximum session duration of %minutes% minutes."
|
||||
entry_not_allowed: "This page cannot be opened directly. Please switch to edit mode via the survey list."
|
||||
create_title: "Create new survey"
|
||||
label_title: "Title"
|
||||
|
||||
Reference in New Issue
Block a user