Commit cf898242 authored by Sorin Loghin's avatar Sorin Loghin

[WIP][TASK] Add proof of concept for the Femanager hooks

parent 742d33f2
Pipeline #1454 passed with stages
in 5 minutes and 19 seconds
<?php
namespace T3o\T3omy\Hooks;
/***************************************************************
* Copyright notice
*
......@@ -25,79 +25,118 @@ namespace T3o\T3omy\Hooks;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
use T3o\T3oLdap\Utility;
use In2code\Femanager\Domain\Model\User;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Hook Functions for \
*/
class FeManagerHooks {
class Tx_T3omy_Hooks_FeUsers
{
/**
*/
protected $ldapOperation;
protected $ldap;
/**
* DataHandlerHook constructor
*/
public function __construct() {
$this->ldapOperation = new UserCreateUpdateDelete();
public function __construct()
{
$this->ldap = new Tx_T3oLdap_Utility_UserCreateUpdateDelete();
}
/**
* Use DataHandler "afterAllOperations" hook to update or create FE Users
* in LDAP.
*
* @param $user $user
* @return void
*/
public function createUser() {
# $this->ldap->
public function createUser(User $user)
{
$result = $this->ldap->updateUser($user->getUid(), $this->userObjectToArray($user));
// TODO: Create log entry if user has been successfully added or throw an exception othwerwise
if ($result === true) {
} else {
}
}
/**
* Use DataHandler "afterAllOperations" hook to update or create FE Users
* in LDAP.
*
* @param $user $user
* @return void
*/
public function updateUser() {
# $this->signalSlotDispatcher->dispatch(__CLASS__, __FUNCTION__ . 'BeforePersist', [$user, $this]);
public function updateUser(User $user)
{
$result = $this->ldap->updateUser($user->getUid(), $this->userObjectToArray($user));
// TODO: Create log entry if user has been successfully updated or throw an exception othwerwise
if ($result === true) {
} else {
}
}
/**
* Use DataHandler "afterAllOperations" hook to update or create FE Users
* in LDAP.
*
* @param $user $user
* @return void
*/
public function deleteUser() {
public function deleteUser(User $user)
{
// TODO: Add this function in Tx_T3oLdap_Utility_UserCreateUpdateDelete
$userData = $this->userObjectToArray($user);
/** @var Tx_T3oLdap_Connectors_Ldap $ldap */
$ldap = GeneralUtility::makeInstance(Tx_T3oLdap_Connectors_Ldap::class);
#$this->signalSlotDispatcher->dispatch(__CLASS__, __FUNCTION__, [$user, $this]);
if ($ldap->userExists($userData['username'])) {
$ret = $ldap->deleteUser($userData['username']);
// TODO: Handle the resonse as needed
if ($ret === true) {
} else {
}
}
}
/**
* // TODO: Options: Leave this here, move it into a service or move it to t3o_ldap
*
* @param User $user
* @return array
*/
protected function userObjectToArray(User $user)
{
$userArray = [];
$userArray['username'] = $user->getUsername();
// TODO: Add all needed fields for LDAP
return $userArray;
}
/**
* @param $_funcRef
* @param $_params
* @param $this
* @param bool
*/
public function writePassword($_funcRef, $_params, $felogin) {
DebuggerUtility::var_dump($_funcRef,'$_funcRef');
DebuggerUtility::var_dump($_params,'$_params');
DebuggerUtility::var_dump($felogin,'$felogin');
public function writePassword($_funcRef, $_params, $felogin)
{
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($_funcRef, '$_funcRef');
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($_params, '$_params');
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($felogin, '$felogin');
die('halt');
$feUserUid=0;
$feUserUid = 0;
$userData = array();
$createIfNotExists = false;
$result = $this->ldapOperation->updateUser($feUserUid, $userData, $createIfNotExists);
$result = $this->ldap->updateUser($feUserUid, $userData, $createIfNotExists);
}
}
......@@ -6,6 +6,29 @@ if (!defined('TYPO3_MODE')) {
#######################################
###
#######################################
/**
* Register signal slots
* TODO: add the signal names
*/
$dispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
$dispatcher->connect(
\In2code\Femanager\Controller\UserBackendController::class,
'',
Tx_T3omy_Hooks_FeUsers::class,
'createUser'
);
$dispatcher->connect(
\In2code\Femanager\Controller\UserBackendController::class,
'',
Tx_T3omy_Hooks_FeUsers::class,
'updateUser'
);
$dispatcher->connect(
\In2code\Femanager\Controller\UserBackendController::class,
'',
Tx_T3omy_Hooks_FeUsers::class,
'deleteUser'
);
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['password_changed'][] = \T3o\T3omy\Hooks\FeManagerHooks::class . '->writePassword';
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