Commit 78e61438 authored by Stefan Busemann's avatar Stefan Busemann

[TASK] Remove ReactivateOldUser function at login error

parent 05228f86
Pipeline #6252 passed with stages
in 2 minutes and 27 seconds
......@@ -37,37 +37,6 @@ class ReactivateUserHook implements \TYPO3\CMS\Backend\RecordList\RecordListGetT
*/
protected $objectManager;
/**
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
*/
public function reactivateOldUser()
{
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
$this->oldUserRepository = $this->objectManager->get(OldUserRepository::class);
// check if there is a fitting user in old user table
/** @var /T3o/T3omy/Domain/Model/OldUser $oldUser */
$oldUser = $this->oldUserRepository->findOneByUsername(GeneralUtility::_POST('user'));
if ($oldUser) {
if ($this->recoverUser($oldUser)) {
$this->oldUserRepository->remove($oldUser);
$this->persistenceManager->persistAll();
$uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::class);
$uri = $uriBuilder->reset()
->setTargetPageUid(37)
->setCreateAbsoluteUri(true)
->buildFrontendUri();
\TYPO3\CMS\Core\Utility\HttpUtility::redirect(
$uri,
\TYPO3\CMS\Core\Utility\HttpUtility::HTTP_STATUS_303
);
}
}
}
/**
* @param \T3o\T3omy\Domain\Model\OldUser $oldUser
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
......@@ -107,30 +76,75 @@ class ReactivateUserHook implements \TYPO3\CMS\Backend\RecordList\RecordListGetT
*/
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(['confirm-t3o-account@typo3.org' => 'typo3.org administration']);
$mail->setTo([$oldUser->getEmail() => $oldUser->getUsername()]);
$mail->setBody('Dear ' . $oldUser->getUsername() . ', your account is now reactivated.
$recoverUser = (int)GeneralUtility::_GP('web_list');
if (($table === 'old_users') && $recoverUser['uid'] > 0 && $recoverUser['command'] === 'recoverOldUser') {
$this->oldUserRepository = $this->getUserRepository(OldUserRepository::class);
$oldUser = $this->oldUserRepository->findByUid($recoverUser['uid']);
if ($oldUser && $this->recoverUser($oldUser)) {
$this->oldUserRepository->remove($oldUser);
$this->persistenceManager->persistAll();
$this->addFlashMessage(
'The user is created in LDAP',
\TYPO3\CMS\Core\Messaging\FlashMessage::SUCCESS,
'Old User transfer'
);
$this->sendRecoveryMail($oldUser->getEmail(), $oldUser->getUsername());
}
}
// Transfer a fe_user into ldap
if ($table === 'fe_users') {
if ($recoverUser['command'] === 'LDAP' && $recoverUser['uid'] > 0) {
$this->userRepository = $this->getUserRepository(UserRepository::class);
$feUser = $this->userRepository->findByUid($recoverUser['uid']);
if ($feUser) {
if (GeneralUtility::validEmail($feUser->getEmail())) {
$ldapOperation = $this->objectManager->get(FeManagerHooks::class);
$ldapOperation->createUser($feUser);
$this->sendRecoveryMail($feUser->getEmail(), $feUser->getUsername());
$this->addFlashMessage(
'The user is created in LDAP',
\TYPO3\CMS\Core\Messaging\FlashMessage::SUCCESS,
'LDAP Transfer'
);
} else {
$this->addFlashMessage(
'This user has no valid mail',
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
'LDAP Transfer'
);
}
} else {
$this->addFlashMessage(
'This user can not be via repository',
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
'LDAP Transfer'
);
}
}
}
}
/**
* Send out the inforamation, that the user has to reset his password
*
* @param string $receiverMail
* @param string $userName
*/
public function sendRecoveryMail(string $receiverMail, String $userName)
{
$mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
$mail->setSubject('TYPO3 account recovery');
$mail->setFrom(['confirm-t3o-account@typo3.org' => 'typo3.org administration']);
$mail->setTo([$receiverMail => $userName]);
$mail->setBody('Dear ' . $userName . ', 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() . '
Your username is: ' . $userName . '
Welcome back in the TYPO3 community.
......@@ -141,10 +155,39 @@ typo3.org admin team
TYPO3 Association, Sihlbruggstrasse 105, CH-6340 Baar, Switzerland
');
$mail->send();
}
}
}
}
$mail->send();
}
/**
* @param string $repositoryClass
* @return object
*/
public function getUserRepository(String $repositoryClass)
{
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
return $this->objectManager->get($repositoryClass);
}
/**
* @param string $flashMessage
* @param $severity
* @param string $messageHeader
*/
public function addFlashMessage(string $flashMessage, $severity, string $messageHeader)
{
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$flashMessageService = $this->objectManager->get(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
$messageQueue = $flashMessageService->getMessageQueueByIdentifier();
$flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Messaging\FlashMessage::class,
$flashMessage,
$messageHeader, // [optional] the header
$severity,
// [optional] the severity defaults to \TYPO3\CMS\Core\Messaging\FlashMessage::OK
true // [optional] whether the message should be stored in the session or only in the \TYPO3\CMS\Core\Messaging\FlashMessageQueue object (default is false)
);
$messageQueue->addMessage($flashMessage);
}
}
......@@ -67,8 +67,5 @@ $dispatcher->connect(
// Hook to update Password in LDAP -> if password reset was fullfilled
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['password_changed'][] = \T3o\T3omy\Hooks\FeManagerHooks::class . '->writePassword';
// 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