Commit ccc55d9a authored by Stefan Busemann's avatar Stefan Busemann
Browse files

Merge branch '88-reactivate-user-process' into 'develop'

Resolve "Reactivate User process"

Closes #88

See merge request !57
parents ba779ef4 7b33f2fa
Pipeline #4945 passed with stages
in 10 minutes and 51 seconds
......@@ -16,3 +16,4 @@ html/typo3temp/
html/uploads/
/auth.json
/html/typo3conf/realurl_autoconf.php
.php_cs.cache
<?php
declare(strict_types = 1);
namespace T3o\T3omy\Domain\Model;
/**
* Class UserProfileRepository
*/
class OldUser extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* @var string
*/
public $username = '';
/**
* @var string
*/
public $email = '';
/**
* @return string
*/
public function getUsername(): string
{
return $this->username;
}
/**
* @param string $username
*/
public function setUsername(string $username)
{
$this->username = $username;
}
/**
* @return string
*/
public function getEmail(): string
{
return $this->email;
}
/**
* @param string $email
*/
public function setEmail(string $email)
{
$this->email = $email;
}
}
<?php
declare(strict_types = 1);
namespace T3o\T3omy\Domain\Repository;
use TYPO3\CMS\Extbase\Persistence\Repository;
/**
* Class UserProfileRepository
*
* @method findByUid(int $uid) \T3o\T3omy\Domain\Model\OldUser
*/
class OldUserRepository extends Repository
{
}
<?php
declare(strict_types = 1);
namespace T3o\T3omy\Hooks;
use In2code\Femanager\Domain\Model\User;
use In2code\Femanager\Domain\Repository\UserRepository;
use T3o\T3omy\Domain\Model\OldUser;
use T3o\T3omy\Domain\Repository\OldUserRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
/**
* Class ReactivateUserHook
*/
class ReactivateUserHook
{
/**
* @var \T3o\T3omy\Domain\Repository\OldUserRepository
*/
protected $oldUserRepository;
/**
* @var \In2code\Femanager\Domain\Repository\UserRepository
*/
protected $userRepository;
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
*/
protected $persistenceManager;
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
*/
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
* @return bool
*/
public function recoverUser(OldUser $oldUser): bool
{
$userRepository = $this->objectManager->get(UserRepository::class);
$random = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Crypto\Random::class);
/** @var User $frontendUser */
$frontendUser = $this->objectManager->get(User::class);
$frontendUser->setUsername($oldUser->getUsername());
$frontendUser->setEmail($oldUser->getEmail());
$frontendUser->setName($oldUser->getUsername());
$frontendUser->setPassword($random->generateRandomBytes(20));
$userRepository->add($frontendUser);
$this->persistenceManager->persistAll();
$ldapOperation = $this->objectManager->get(FeManagerHooks::class);
$ldapOperation->createUser($frontendUser);
return true;
}
}
<?php
namespace T3o\T3omy\Hooks;
/***************************************************************
* Copyright notice
*
* (c) 2018 in2code.de and the following authors:
* Stefan Busemann
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
use TYPO3\CMS\Recordlist\RecordList\RecordListHookInterface;
/**
* Class RecordListWorkflowButton
*/
class RecordListWorkflowOldUsers implements RecordListHookInterface
{
/**
* @var IconFactory
*/
protected $iconFactory;
/**
* RecordListWorkflowButton constructor.
*/
public function __construct()
{
$this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$this->signalSlotDispatcher = GeneralUtility::makeInstance(Dispatcher::class);
}
/**
* @param string $table
* @param array $row
* @param array $cells
* @param object $parentObject
*
* @return array
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function makeClip($table, $row, $cells, &$parentObject)
{
return $cells;
}
/**
* @param string $table
* @param array $row
* @param array $cells
* @param object $parentObject
*
* @return array
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function makeControl($table, $row, $cells, &$parentObject)
{
if ($table=='old_users') {
$buttons = [];
$buttons['workflow'] = $this->getWorkflowButton();
$cells['primary'] = $buttons + $cells['primary'];
}
return $cells;
}
/**
* @return string
*/
protected function getWorkflowButton()
{
$urlParameters = [
'tx_in2publish_web_in2publishm2' => [
'uid' => 1,
'table' => 'old_users',
'referringModule' => GeneralUtility::_GP('M'),
'referringPage' => GeneralUtility::_GP('id'),
'action' => 'record',
],
];
$href = BackendUtility::getModuleUrl('web_list', $urlParameters);
$class = 'btn btn-default';
return '<a class="' . $class . '" href="' . $href . '">'
. 'Reactivate'
. '</a>';
}
/**
* @param string $table
* @param array $currentIdList
* @param array $headerColumns
* @param object $parentObject
*
* @return array
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function renderListHeader($table, $currentIdList, $headerColumns, &$parentObject)
{
return $headerColumns;
}
/**
* @param string $table
* @param array $currentIdList
* @param array $cells
* @param object $parentObject
*
* @return array
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function renderListHeaderActions($table, $currentIdList, $cells, &$parentObject)
{
return $cells;
}
}
<?php
return [
'ctrl' => [
'title' => 'old fe user table',
'label' => 'username',
'default_sortby' => 'ORDER BY username ASC',
'searchFields' => 'title, uid, email',
'iconfile' => 'EXT:t3omy/Resources/Public/Icons/old_user.png',
'delete' => 'deleted',
'label' => 'username',
'default_sortby' => 'ORDER BY username',
'searchFields' => 'username, email'
],
'interface' => [
'showRecordFieldList' => 'uid, username, email',
],
'types' => [
'1' => [
'showitem' => 'uid, username, email, '
],
],
'palettes' => [
'1' => ['showitem' => ''],
],
'columns' => [
'username' => [
'exclude' => 0,
'label' => 'LLL:EXT:t3omy/Resources/Private/Language/locallang.xlf:' .
'old-users.username',
'config' => [
'type' => 'input',
'size' => 30,
'eval' => 'trim'
],
],
'email' => [
'exclude' => 0,
'label' => 'LLL:EXT:t3omy/Resources/Private/Language/locallang.xlf:' .
'old-users.email',
'config' => [
'type' => 'input',
'size' => 30,
'eval' => 'trim'
],
],
],
];
......@@ -9,6 +9,12 @@
<trans-unit id="backend_layout.default.column.collection">
<source>CE Collection (Not shown on FE) </source>
</trans-unit>
<trans-unit id="old-users.username">
<source>Username of old fe_user</source>
</trans-unit>
<trans-unit id="old-users.email">
<source>Email</source>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
</xliff>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" viewBox="0 0 64 64" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;">
<rect x="0" y="0" width="64" height="64" style="fill:rgb(200,60,60);fill-rule:nonzero;"/>
<path d="M46.6,41.2C43.785,40.432 41.626,39.375 39.624,38.522C39.582,39.065 39.381,39.635 38.842,40.186C37.222,41.912 34.742,44 32.034,44C29.314,44 26.746,41.885 25.154,40.183C24.596,39.61 24.411,39.006 24.392,38.445C22.385,39.341 20.222,40.33 17.399,41.1C17.399,41.1 14.299,43 13.999,50L49.999,50C49.799,42.9 46.599,41.2 46.599,41.2L46.6,41.2Z" style="fill:white;fill-rule:nonzero;"/>
<path d="M40,20.5C40,16.9 36.8,14 33,14L31,14C27.4,14 24,16.9 24,20.5L24,25.5C24,27.61 25.628,30.213 27.5,32.053C27.4,37.453 25.8,38 26.6,38.8C29.1,41.5 34.7,41.7 37.4,38.8C38.197,38.003 36.81,37.5 36.504,32.053C38.334,30.215 39.942,27.59 40,25.5L40,20.5Z" style="fill:white;fill-rule:nonzero;"/>
<g id="Reply--small-" serif:id="Reply (small)" transform="matrix(0.902781,3.33829e-32,0,0.902781,-393.884,-154.756)">
<path d="M450,208.5L450,202L438.5,213L450,224L450,217.5C455.5,217.5 460,222 460,227.5C460,230.3 458.9,232.8 457.1,234.6C461.2,232.2 464,227.7 464,222.5C464,214.7 457.7,208.5 450,208.5Z" style="fill-rule:nonzero;"/>
</g>
</svg>
......@@ -53,4 +53,12 @@ $dispatcher->connect(
'selfUpdateOfUser'
);
/**
* Register hooks
*/
// 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';
......@@ -25,6 +25,8 @@ $iconRegistry->registerIcon(
'Main settings for my Userprofile (additional fields)'
);
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'][1505827875] = T3o\T3omy\Hooks\RecordListWorkflowOldUsers::class;
/**
* Disable non needed fields in tt_content
*/
......
......@@ -9,7 +9,10 @@ CREATE TABLE fe_users (
);
CREATE TABLE old_users (
uid int(11) unsigned DEFAULT '0',
uid int(11) NOT NULL auto_increment,
pid int (11) unsigned DEFAULT '0',
deleted tinyint(4) unsigned DEFAULT '0' NOT NULL,
username varchar(255) DEFAULT '',
email varchar(255) DEFAULT ''
email varchar(255) DEFAULT '',
PRIMARY KEY (uid)
);
......@@ -22,6 +22,11 @@ config.tx_extbase {
tableName = fe_users
}
}
T3o\T3omy\Domain\Model\OldUser{
mapping {
tableName = old_users
}
}
}
}
}
......@@ -33,4 +38,4 @@ config.additionalHeaders {
30.header = X-Content-Security-Policy: default-src 'self' *.typo3.org; script-src 'unsafe-inline' *.typo3.org; font-src 'self' fonts.googleapis.com fonts.gstatic.com; style-src 'self' 'unsafe-inline' fonts.googleapis.com; img-src 'self' data: *.typo3.org www.gravatar.com
40.header = X-Webkit-CSP: default-src 'self' *.typo3.org; script-src 'unsafe-inline' *.typo3.org; font-src 'self' fonts.googleapis.com fonts.gstatic.com; style-src 'self' 'unsafe-inline' fonts.googleapis.com; img-src 'self' data: *.typo3.org www.gravatar.com
}
[end]
\ No newline at end of file
[end]
Supports Markdown
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