Skip to content

Commit

Permalink
refactor: inject the session class into the Token class (#3202)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Nov 4, 2024
1 parent 453ea03 commit 5347ef6
Show file tree
Hide file tree
Showing 78 changed files with 219 additions and 155 deletions.
2 changes: 1 addition & 1 deletion phpmyfaq/404.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
$faqConfig = $container->get('phpmyfaq.configuration');
$user = $container->get('phpmyfaq.user.current_user');

$faqSession = $container->get('phpmyfaq.session');
$faqSession = $container->get('phpmyfaq.user.session');
$faqSession->setCurrentUser($user);
$faqSession->userTracking(SessionActionType::NOT_FOUND->value, 0);

Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$faqConfig = $container->get('phpmyfaq.configuration');
$user = $container->get('phpmyfaq.user.current_user');

$faqSession = $container->get('phpmyfaq.session');
$faqSession = $container->get('phpmyfaq.user.session');
$faqSession->setCurrentUser($user);

// Check user permissions
Expand Down
4 changes: 2 additions & 2 deletions phpmyfaq/admin/attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
'adminMsgTransToolLanguage' => Translation::get('msgTransToolLanguage'),
'adminMsgAttachmentsFilesize' => Translation::get('msgAttachmentsFilesize'),
'adminMsgAttachmentsMimeType' => Translation::get('msgAttachmentsMimeType'),
'csrfTokenDeletion' => Token::getInstance()->getTokenString('delete-attachment'),
'csrfTokenRefresh' => Token::getInstance()->getTokenString('refresh-attachment'),
'csrfTokenDeletion' => Token::getInstance($container->get('session'))->getTokenString('delete-attachment'),
'csrfTokenRefresh' => Token::getInstance($container->get('session'))->getTokenString('refresh-attachment'),
'attachments' => $crumbs,
'adminMsgButtonDelete' => Translation::get('ad_gen_delete'),
'adminMsgFaqTitle' => Translation::get('ad_entry_faq_record'),
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/admin/backup.import.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

if (
$user->perm->hasPermission($user->getUserId(), PermissionType::RESTORE->value) &&
Token::getInstance()->verifyToken('restore', $csrfToken)
Token::getInstance($container->get('session'))->verifyToken('restore', $csrfToken)
) {
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$template = $twig->loadTemplate('./admin/backup/import.twig');
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/admin/backup.main.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
'adminBackupCardBody' => Translation::get('ad_csv_make'),
'adminBackupLinkData' => Translation::get('ad_csv_linkdat'),
'adminBackupLinkLogs' => Translation::get('ad_csv_linklog'),
'csrfToken' => Token::getInstance()->getTokenString('restore'),
'csrfToken' => Token::getInstance($container->get('session'))->getTokenString('restore'),
'adminRestoreCardHeader' => Translation::get('ad_csv_head2'),
'adminRestoreCardBody' => Translation::get('ad_csv_restore'),
'adminRestoreLabel' => Translation::get('ad_csv_file'),
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/admin/category.add.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
$parentId = Filter::filterInput(INPUT_GET, 'cat', FILTER_VALIDATE_INT, 0);

$templateVars = [
'csrfTokenInput' => Token::getInstance()->getTokenInput('save-category'),
'csrfTokenInput' => Token::getInstance($container->get('session'))->getTokenInput('save-category'),
'faqLangCode' => $faqLangCode,
'parentId' => $parentId,
'ad_categ_new' => Translation::get('ad_categ_new'),
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/admin/category.edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
'categoryId' => $categoryId,
'categoryLanguage' => $categoryData->getLang(),
'parentId' => $categoryData->getParentId(),
'csrfInputToken' => Token::getInstance()->getTokenInput('update-category'),
'csrfInputToken' => Token::getInstance($container->get('session'))->getTokenInput('update-category'),
'categoryImage' => $categoryData->getImage(),
'categoryNameLabel' => Translation::get('ad_categ_titel'),
'categoryName' => $categoryData->getName(),
Expand Down
13 changes: 9 additions & 4 deletions phpmyfaq/admin/category.main.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use phpMyFAQ\Category\Image;
use phpMyFAQ\Category\Order;
use phpMyFAQ\Category\Permission;
use phpMyFAQ\Configuration;
use phpMyFAQ\Database;
use phpMyFAQ\Entity\CategoryEntity;
use phpMyFAQ\Entity\SeoEntity;
Expand All @@ -38,7 +37,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$currentUser = CurrentUser::getCurrentUser($faqConfig);

$csrfToken = Filter::filterInput(INPUT_POST, 'csrf', FILTER_SANITIZE_SPECIAL_CHARS);
Expand All @@ -60,7 +59,10 @@
];

// Save a new category
if ($action === 'savecategory' && Token::getInstance()->verifyToken('save-category', $csrfToken)) {
if (
$action === 'savecategory' &&
Token::getInstance($container->get('session'))->verifyToken('save-category', $csrfToken)
) {
$category = new Category($faqConfig, [], false);
$category->setUser($currentAdminUser);
$category->setGroups($currentAdminGroups);
Expand Down Expand Up @@ -176,7 +178,10 @@
}

// Updates an existing category
if ($action === 'updatecategory' && Token::getInstance()->verifyToken('update-category', $csrfToken)) {
if (
$action === 'updatecategory' &&
Token::getInstance($container->get('session'))->verifyToken('update-category', $csrfToken)
) {
$category = new Category($faqConfig, [], false);
$category->setUser($currentAdminUser);
$category->setGroups($currentAdminGroups);
Expand Down
8 changes: 3 additions & 5 deletions phpmyfaq/admin/category.overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/

use phpMyFAQ\Category;
use phpMyFAQ\Category\Order;
use phpMyFAQ\Configuration;
use phpMyFAQ\Session\Token;
use phpMyFAQ\Template\TwigWrapper;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -28,13 +26,13 @@
}

$request = Request::createFromGlobals();
$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');

$category = new Category($faqConfig, [], false);
$category->buildCategoryTree();
$categoryInfo = $category->getAllCategories();

$categoryOrder = new Order($faqConfig);
$categoryOrder = $container->get('phpmyfaq.category.order');
$orderedCategories = $categoryOrder->getAllCategories();
$categoryTree = $categoryOrder->getCategoryTree($orderedCategories);

Expand All @@ -47,7 +45,7 @@
$template = $twig->loadTemplate('./admin/content/category.overview.twig');

$templateVars = [
'csrfTokenInput' => Token::getInstance()->getTokenInput('category'),
'csrfTokenInput' => Token::getInstance($container->get('session'))->getTokenInput('category'),
'categoryTree' => $categoryTree,
'categoryInfo' => $categoryInfo,
];
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/admin/category.translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
'permLevel' => $faqConfig->get('security.permLevel'),
'groupPermission' => $groupPermission[0],
'userPermission' => $userPermission[0],
'csrf' => Token::getInstance()->getTokenString('update-category'),
'csrf' => Token::getInstance($container->get('session'))->getTokenString('update-category'),
'ad_categ_title' => Translation::get('ad_categ_titel'),
'ad_categ_lang' => Translation::get('ad_categ_lang'),
'langToTranslate' => $category->getCategoryLanguagesToTranslate($id, $selectedLanguage),
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/admin/comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
'currentLocale' => $faqConfig->getLanguage()->getLanguage(),
'faqComments' => $faqComments,
'newsComments' => $newsComments,
'csrfToken' => Token::getInstance()->getTokenString('delete-comment'),
'csrfToken' => Token::getInstance($container->get('session'))->getTokenString('delete-comment'),
];

echo $template->render($templateVars);
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/admin/configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

$templateVars = [
'adminHeaderConfiguration' => Translation::get('ad_config_edit'),
'csrfToken' => Token::getInstance()->getTokenString('configuration'),
'csrfToken' => Token::getInstance($container->get('session'))->getTokenString('configuration'),
'language' => $faqLangCode,
'adminConfigurationButtonReset' => Translation::get('ad_config_reset'),
'adminConfigurationButtonSave' => Translation::get('ad_config_save'),
Expand Down
6 changes: 3 additions & 3 deletions phpmyfaq/admin/faqs.editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
'openQuestionId' => $questionId,
'notifyUser' => $notifyUser,
'notifyEmail' => $notifyEmail,
'csrfToken' => Token::getInstance()->getTokenString('edit-faq'),
'csrfToken' => Token::getInstance($container->get('session'))->getTokenString('edit-faq'),
'ad_entry_theme' => Translation::get('ad_entry_theme'),
'msgNoHashAllowed' => Translation::get('msgNoHashAllowed'),
'msgShowHelp' => Translation::get('msgShowHelp'),
Expand All @@ -351,7 +351,7 @@
PermissionType::ATTACHMENT_DELETE->value
),
'ad_menu_attachments' => Translation::get('ad_menu_attachments'),
'csrfTokenDeleteAttachment' => Token::getInstance()->getTokenString('delete-attachment'),
'csrfTokenDeleteAttachment' => Token::getInstance($container->get('session'))->getTokenString('delete-attachment'),
'attachments' => $attList,
'ad_att_add' => Translation::get('ad_att_add'),
'ad_entry_tags' => Translation::get('ad_entry_tags'),
Expand Down Expand Up @@ -410,7 +410,7 @@
'ad_att_addto_2' => Translation::get('ad_att_addto_2'),
'ad_att_att' => Translation::get('ad_att_att'),
'maxAttachmentSize' => $faqConfig->get('records.maxAttachmentSize'),
'csrfTokenUploadAttachment' => Token::getInstance()->getTokenString('upload-attachment'),
'csrfTokenUploadAttachment' => Token::getInstance($container->get('session'))->getTokenString('upload-attachment'),
'msgAttachmentsFilesize' => Translation::get('msgAttachmentsFilesize'),
'ad_att_butt' => Translation::get('ad_att_butt'),
];
Expand Down
4 changes: 2 additions & 2 deletions phpmyfaq/admin/faqs.overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
$template = $twig->loadTemplate('./admin/content/faq.overview.twig');

$templateVars = [
'csrfTokenSearch' => Token::getInstance()->getTokenInput('edit-faq'),
'csrfTokenOverview' => Token::getInstance()->getTokenString('faq-overview'),
'csrfTokenSearch' => Token::getInstance($container->get('session'))->getTokenInput('edit-faq'),
'csrfTokenOverview' => Token::getInstance($container->get('session'))->getTokenString('faq-overview'),
'categories' => $category->getCategoryTree(),
'numberOfRecords' => $categoryRelation->getNumberOfFaqsPerCategory(),
'numberOfComments' => $comments->getNumberOfCommentsByCategory(),
Expand Down
4 changes: 2 additions & 2 deletions phpmyfaq/admin/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
'formDataAddContent' => $forms->getFormData(FormIds::ADD_NEW_FAQ->value),
'msgQuestion' => Translation::get('msgQuestion'),
'msgAddContent' => Translation::get('msgAddContent'),
'csrfActivate' => Token::getInstance()->getTokenString('activate-input'),
'csrfRequired' => Token::getInstance()->getTokenString('require-input'),
'csrfActivate' => Token::getInstance($container->get('session'))->getTokenString('activate-input'),
'csrfRequired' => Token::getInstance($container->get('session'))->getTokenString('require-input'),
'ad_entry_id' => Translation::get('ad_entry_id'),
'msgInputLabel' => Translation::get('msgInputLabel'),
'msgInputType' => Translation::get('msgInputType'),
Expand Down
4 changes: 2 additions & 2 deletions phpmyfaq/admin/forms.translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
'msgInputLabel' => Translation::get('msgInputLabel'),
'ad_sess_pageviews' => Translation::get('ad_sess_pageviews'),
'msgFormsEditTranslations' => Translation::get('msgFormsEditTranslations'),
'csrfTokenEditTranslation' => Token::getInstance()->getTokenString('edit-translation'),
'csrfTokenDeleteTranslation' => Token::getInstance()->getTokenString('delete-translation'),
'csrfTokenEditTranslation' => Token::getInstance($container->get('session'))->getTokenString('edit-translation'),
'csrfTokenDeleteTranslation' => Token::getInstance($container->get('session'))->getTokenString('delete-translation'),
'languages' => $languages,
'msgSelectLanguage' => Translation::get('msgSelectLanguage'),
'msgTranslationText' => Translation::get('msgTranslationText'),
Expand Down
4 changes: 2 additions & 2 deletions phpmyfaq/admin/glossary.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
'msgGlossaryDefinition' => Translation::get('ad_glossary_definition'),
'glossaryItems' => $glossary->fetchAll(),
'buttonDelete' => Translation::get('msgDelete'),
'csrfTokenDelete' => Token::getInstance()->getTokenString('delete-glossary'),
'csrfTokenDelete' => Token::getInstance($container->get('session'))->getTokenString('delete-glossary'),
'currentLanguage' => $faqLangCode,
'addGlossaryTitle' => Translation::get('ad_glossary_add'),
'addGlossaryCsrfTokenInput' => Token::getInstance()->getTokenInput('add-glossary'),
'addGlossaryCsrfTokenInput' => Token::getInstance($container->get('session'))->getTokenInput('add-glossary'),
'closeModal' => Translation::get('ad_att_close'),
'saveModal' => Translation::get('ad_gen_save'),
'updateGlossaryTitle' => Translation::get('ad_glossary_edit'),
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/admin/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
'groupName' => Strings::htmlentities($groupData['name']),
'ad_group_deleteQuestion' => Translation::get('ad_group_deleteQuestion'),
'groupId' => $groupId,
'csrfDeleteGroup' => Token::getInstance()->getTokenString('delete-group'),
'csrfDeleteGroup' => Token::getInstance($container->get('session'))->getTokenString('delete-group'),
'ad_gen_no' => Translation::get('ad_gen_no'),
'ad_gen_yes' => Translation::get('ad_gen_yes'),
'showDeleteGroupForm' => $showDeleteGroupForm
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/admin/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
'hasGravatarSupport' => $faqConfig->get('main.enableGravatarSupport'),
'gravatarImage' => $gravatarImage ?? '',
'msgChangePassword' => Translation::get('ad_menu_passwd'),
'csrfTokenLogout' => Token::getInstance()->getTokenString('admin-logout'),
'csrfTokenLogout' => Token::getInstance($container->get('session'))->getTokenString('admin-logout'),
'msgLogout' => Translation::get('admin_mainmenu_logout'),
'secondLevelEntries' => $secLevelEntries,
'menuUsers' => Translation::get('admin_mainmenu_users'),
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/admin/import.csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
'seperateWithCommas' => Translation::get('msgSeperateWithCommas'),
'tags' => Translation::get('ad_entry_tags'),
'msgImportRecordsColumnStructure' => Translation::get('msgImportRecordsColumnStructure'),
'csrfToken' => Token::getInstance()->getTokenString('importfaqs'),
'csrfToken' => Token::getInstance($container->get('session'))->getTokenString('importfaqs'),
'is_active' => Translation::get('ad_entry_active'),
'is_sticky' => Translation::get('ad_entry_sticky'),
'trueFalse' => Translation::get('msgCSVImportTrueOrFalse')
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
$csrfToken = Filter::filterInput(INPUT_GET, 'csrf', FILTER_SANITIZE_SPECIAL_CHARS);
if (
$csrfToken &&
Token::getInstance()->verifyToken('admin-logout', $csrfToken) &&
Token::getInstance($container->get('session'))->verifyToken('admin-logout', $csrfToken) &&
$action === 'logout' &&
$user->isLoggedIn()
) {
Expand Down
4 changes: 2 additions & 2 deletions phpmyfaq/admin/instances.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
'multisiteFolderIsWritable' => is_writable(PMF_ROOT_DIR . DIRECTORY_SEPARATOR . 'multisite'),
'ad_instance_add' => Translation::get('ad_instance_add'),
'allInstances' => $instance->getAll(),
'csrfTokenDeleteInstance' => Token::getInstance()->getTokenString('delete-instance'),
'csrfTokenAddInstance' => Token::getInstance()->getTokenString('add-instance'),
'csrfTokenDeleteInstance' => Token::getInstance($container->get('session'))->getTokenString('delete-instance'),
'csrfTokenAddInstance' => Token::getInstance($container->get('session'))->getTokenString('add-instance'),
'mainConfig' => $mainConfig,
'requestHost' => Request::createFromGlobals()->getHost(),
'ad_instance_button' => Translation::get('ad_instance_button'),
Expand Down
8 changes: 4 additions & 4 deletions phpmyfaq/admin/news.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
'defaultUrl' => $faqConfig->getDefaultUrl(),
'enableWysiwyg' => $faqConfig->get('main.enableWysiwygEditor'),
'ad_news_add' => Translation::get('ad_news_add'),
'csrfToken_saveNews' => Token::getInstance()->getTokenString('save-news'),
'csrfToken_saveNews' => Token::getInstance($container->get('session'))->getTokenString('save-news'),
'ad_news_author_name' => Translation::get('ad_news_author_name'),
'ad_news_set_active' => Translation::get('ad_news_set_active'),
'ad_news_link_url' => Translation::get('ad_news_link_url'),
Expand Down Expand Up @@ -82,10 +82,10 @@
'ad_news_delsuc' => Translation::get('ad_news_delsuc'),
'ad_news_updatesuc' => Translation::get('ad_news_updatesuc'),
'msgDeleteNews' => Translation::get('msgDeleteNews'),
'csrfToken_deleteNews' => Token::getInstance()->getTokenString('delete-news'),
'csrfToken_updateNews' => Token::getInstance()->getTokenString('update-news'),
'csrfToken_deleteNews' => Token::getInstance($container->get('session'))->getTokenString('delete-news'),
'csrfToken_updateNews' => Token::getInstance($container->get('session'))->getTokenString('update-news'),
'ad_entry_active' => Translation::get('ad_entry_active'),
'csrfToken_activateNews' => Token::getInstance()->getTokenString('activate-news')
'csrfToken_activateNews' => Token::getInstance($container->get('session'))->getTokenString('activate-news')
];

if ('add-news' == $action && $user->perm->hasPermission($user->getUserId(), PermissionType::NEWS_ADD)) {
Expand Down
4 changes: 2 additions & 2 deletions phpmyfaq/admin/open-questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
$category->setGroups($currentAdminGroups);
$date = new Date($faqConfig);

$questionId = Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
$questionId= Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
$csrfToken = Filter::filterInput(INPUT_GET, 'csrf', FILTER_SANITIZE_SPECIAL_CHARS);

if ($csrfToken && Token::getInstance()->verifyToken('toggle-question-visibility', $csrfToken)) {
if (Token::getInstance($container->get('session'))->verifyToken('toggle-question-visibility', $csrfToken)) {
$csrfChecked = true;
} else {
$csrfChecked = false;
Expand Down
6 changes: 3 additions & 3 deletions phpmyfaq/admin/password.change.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$faqConfig = $container->get('phpmyfaq.configuration');
$user = CurrentUser::getCurrentUser($faqConfig);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
Expand All @@ -41,7 +41,7 @@
$csrfToken = Filter::filterInput(INPUT_POST, 'csrf', FILTER_SANITIZE_SPECIAL_CHARS);
$successMessage = $errorMessage = '';

if (!is_null($save) && Token::getInstance()->verifyToken('password', $csrfToken)) {
if (!is_null($save) && Token::getInstance($container->get('session'))->verifyToken('password', $csrfToken)) {
// Define the (Local/Current) Authentication Source
$auth = new Auth($faqConfig);
$authSource = $auth->selectAuth($user->getAuthSource('name'));
Expand Down Expand Up @@ -75,7 +75,7 @@
'adminHeaderPasswordChange' => Translation::get('ad_passwd_cop'),
'successMessage' => $successMessage,
'errorMessage' => $errorMessage,
'csrfToken' => Token::getInstance()->getTokenString('password'),
'csrfToken' => Token::getInstance($container->get('session'))->getTokenString('password'),
'adminMsgOldPassword' => Translation::get('ad_passwd_old'),
'adminMsgNewPassword' => Translation::get('ad_passwd_new'),
'adminMsgNewPasswordConfirm' => Translation::get('ad_passwd_con'),
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/admin/report.main.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
if ($user->perm->hasPermission($user->getUserId(), PermissionType::REPORTS->value)) {
$templateVars = [
'ad_menu_reports' => Translation::get('ad_menu_reports'),
'csrfTokenInput' => Token::getInstance()->getTokenInput('create-report'),
'csrfTokenInput' => Token::getInstance($container->get('session'))->getTokenInput('create-report'),
'ad_stat_report_make_report' => Translation::get('ad_stat_report_make_report'),
'ad_stat_report_fields' => Translation::get('ad_stat_report_fields'),
'ad_stat_report_category' => Translation::get('ad_stat_report_category'),
Expand Down
Loading

0 comments on commit 5347ef6

Please sign in to comment.