Commit 54a9670d authored by Stefan Busemann's avatar Stefan Busemann

[FEATURE] reactivate old users via backend

parent 81934adf
Pipeline #5558 failed with stages
in 15 seconds
<?php
declare(strict_types = 1);
declare(strict_types=1);
namespace T3o\T3omy\Hooks;
......@@ -14,7 +14,7 @@ use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
/**
* Class ReactivateUserHook
*/
class ReactivateUserHook
class ReactivateUserHook implements \TYPO3\CMS\Backend\RecordList\RecordListGetTableHookInterface
{
/**
* @var \T3o\T3omy\Domain\Repository\OldUserRepository
......@@ -59,7 +59,8 @@ class ReactivateUserHook
->setCreateAbsoluteUri(true)
->buildFrontendUri();
\TYPO3\CMS\Core\Utility\HttpUtility::redirect($uri, \TYPO3\CMS\Core\Utility\HttpUtility::HTTP_STATUS_303);
\TYPO3\CMS\Core\Utility\HttpUtility::redirect($uri,
\TYPO3\CMS\Core\Utility\HttpUtility::HTTP_STATUS_303);
}
}
}
......@@ -90,4 +91,56 @@ class ReactivateUserHook
return true;
}
/**
* modifies the DB list query
*
* @param string $table The current database table
* @param int $pageId The record's page ID
* @param string $additionalWhereClause An additional WHERE clause
* @param string $selectedFieldsList Comma separated list of selected fields
* @param \TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList $parentObject Parent \TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList object
*/
public function getDBlistQuery($table, $pageId, &$additionalWhereClause, &$selectedFieldsList, &$parentObject)
{
if ($table === 'old_users') {
$recoverUser = GeneralUtility::_GP('web_list');
if ($recoverUser['uid'] > 0) {
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
$this->oldUserRepository = $this->objectManager->get(OldUserRepository::class);
$oldUser = $this->oldUserRepository->findByUid($recoverUser['uid']);
if ($oldUser) {
if ($this->recoverUser($oldUser)) {
$this->oldUserRepository->remove($oldUser);
$this->persistenceManager->persistAll();
// send mail
$mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
$mail->setSubject('TYPO3 account recovery');
$mail->setFrom(array('confirm-t3o-account@typo3.org' => 'typo3.org administration'));
$mail->setTo(array($oldUser->getEmail() => $oldUser->getUsername()));
$mail->setBody('Dear ' . $oldUser->getUsername() . ', your account is now reactivated.
Please set up a new password at https://my.typo3.org/index.php?id=12&tx_felogin_pi1[forgot]=1
Your username is: ' . $oldUser->getUsername(). '
Welcome back in the TYPO3 community.
Best regards
typo3.org admin team
TYPO3 Association, Sihlbruggstrasse 105, CH-6340 Baar, Switzerland
');
$mail->send();
}
}
}
}
}
}
......@@ -78,9 +78,9 @@ class RecordListWorkflowOldUsers implements RecordListHookInterface
*/
public function makeControl($table, $row, $cells, &$parentObject)
{
if ($table=='old_users') {
if ($table === 'old_users') {
$buttons = [];
$buttons['workflow'] = $this->getWorkflowButton();
$buttons['workflow'] = $this->getWorkflowButton($row);
$cells['primary'] = $buttons + $cells['primary'];
}
return $cells;
......@@ -89,15 +89,13 @@ class RecordListWorkflowOldUsers implements RecordListHookInterface
/**
* @return string
*/
protected function getWorkflowButton()
protected function getWorkflowButton($row)
{
$urlParameters = [
'tx_in2publish_web_in2publishm2' => [
'uid' => 1,
'web_list' => [
'uid' => $row['uid'],
'table' => 'old_users',
'referringModule' => GeneralUtility::_GP('M'),
'referringPage' => GeneralUtility::_GP('id'),
'action' => 'record',
'action' => 'reactivate',
],
];
......
......@@ -69,3 +69,6 @@ $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['password_changed'][] = \T3o\T
// Hook to look, if a user does exist in "old_users" table
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['login_error'][] = \T3o\T3omy\Hooks\ReactivateUserHook::class . '->reactivateOldUser';
// Hook to process reactivate process via BE
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['getTable'][] = \T3o\T3omy\Hooks\ReactivateUserHook::class ;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment