Commit e8c55ec1 authored by Thomas Löffler's avatar Thomas Löffler
Browse files

Merge branch '293-user-activation-process-fails' into 'develop'

Resolve "User activation process fails"

Closes #293

See merge request !143
parents e1403bca fd2e1e35
Pipeline #6666 passed with stages
in 2 minutes and 46 seconds
......@@ -93,6 +93,7 @@ class Ldap
/**
* LDAP constructor.
* @throws \Exception
*/
public function __construct()
{
......@@ -109,8 +110,18 @@ class Ldap
$this->ldapBaseDnForPasswordChanges = trim($this->extensionConfiguration['ldapBaseDnForPasswordChanges']);
// Connect and bind
$this->createLdapConnection();
$this->ldapBind($this->ldapConnection, $this->ldapBindDn, $this->ldapBindPassword);
try {
if ($this->createLdapConnection()) {
$this->ldapBind($this->ldapConnection, $this->ldapBindDn, $this->ldapBindPassword);
} else {
throw new \Exception(
'createLdapConnection connection failed',
1553856512
);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
......@@ -249,13 +260,21 @@ class Ldap
* Errors are logged to syslog.
*
* @return bool
* @throws \Exception
*/
private function createLdapConnection()
{
$ret = false;
$port = intval($this->ldapServerPort);
try {
$this->ldapConnection = @ldap_connect($this->ldapServer, ($port > 0 ? $port : null));
if (function_exists('ldap_connect')) {
$this->ldapConnection = @ldap_connect($this->ldapServer, ($port > 0 ? $port : null));
} else {
throw new \Exception(
'LDAP PHP Extension is not available',
1553856513
);
}
if ($this->ldapConnection) {
// Set protocol version
if (ldap_set_option($this->ldapConnection, LDAP_OPT_PROTOCOL_VERSION, $this->ldapProtocolVersion)) {
......
......@@ -32,13 +32,19 @@ class UserCreateUpdateDelete
* @param bool $createIfNotExists Create the user if it does not exist
* @param string $updatePassword
* @return bool
* @throws \Exception
*/
public function updateUser(\In2code\Femanager\Domain\Model\User $user, $createIfNotExists = true, $updatePassword = '')
{
$ret = false;
/** @var \T3o\T3oLdap\Connectors\Ldap $ldap */
$ldap = GeneralUtility::makeInstance(\T3o\T3oLdap\Connectors\Ldap::class);
try {
$ldap = new \T3o\T3oLdap\Connectors\Ldap();
} catch (\Exception $e) {
throw $e;
}
$feUserUid = $user->getUid();
if ($ldap->userExists($user->getUsername())) {
......
<?php
namespace T3o\T3omy\Hooks;
/***************************************************************
......@@ -183,13 +184,20 @@ class FeManagerHooks
*
* @param \In2code\Femanager\Domain\Model\User $user
* @return bool
* @throws \Exception
*/
public function createUser(User $user)
{
$this->persistenceManager->persistAll();
// TODO: Create log entry if user has been successfully added or throw an exception otherwise
return $this->ldapUserCreateUpdateDelete->updateUser($user, true);
try {
$this->ldapUserCreateUpdateDelete->updateUser($user, true);
} catch (\Exception $e) {
throw $e;
}
return true;
}
/**
......@@ -349,6 +357,7 @@ class FeManagerHooks
return $location;
}
return 'No Access key is set in typoscript constants - tx_t3omy.ipapi.access_key';
}
}
......@@ -52,15 +52,24 @@ class ReactivateUserHook implements \TYPO3\CMS\Backend\RecordList\RecordListGetT
$frontendUser->setUsername($oldUser->getUsername());
$frontendUser->setEmail($oldUser->getEmail());
$frontendUser->setName($oldUser->getUsername());
$frontendUser->setPassword($random->generateRandomBytes(20));
$frontendUser->setPassword($random->generateRandomHexString(20));
$frontendUser->addUsergroup($userGroupRepository->findByUid(1));
$frontendUser->setPid(5);
$userRepository->add($frontendUser);
$this->persistenceManager->persistAll();
$ldapOperation = $this->objectManager->get(FeManagerHooks::class);
$ldapOperation->createUser($frontendUser);
try {
$ldapOperation->createUser($frontendUser);
} catch (\Exception $e) {
$this->addFlashMessage(
$e->getMessage(),
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
'Error ' . $e->getCode()
);
return false;
}
return true;
}
......@@ -76,21 +85,29 @@ class ReactivateUserHook implements \TYPO3\CMS\Backend\RecordList\RecordListGetT
*/
public function getDBlistQuery($table, $pageId, &$additionalWhereClause, &$selectedFieldsList, &$parentObject)
{
$recoverUser = (int)GeneralUtility::_GP('web_list');
$recoverUser = 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());
if ($oldUser) {
if ($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());
} else {
$this->addFlashMessage(
'The user could not created in LDAP',
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
'Error in LDAP Transfer / old user transfer'
);
}
}
}
......@@ -102,14 +119,31 @@ class ReactivateUserHook implements \TYPO3\CMS\Backend\RecordList\RecordListGetT
$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'
);
try {
$ldapOperation = $this->objectManager->get(FeManagerHooks::class);
if ($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(
'The user could not created in LDAP',
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
'Error in LDAP Transfer'
);
}
} catch (\Exception $e) {
$this->addFlashMessage(
$e->getMessage(),
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
'Error ' . $e->getCode()
);
return false;
}
} else {
$this->addFlashMessage(
'This user has no valid mail',
......@@ -162,7 +196,7 @@ TYPO3 Association, Sihlbruggstrasse 105, CH-6340 Baar, Switzerland
* @param string $repositoryClass
* @return object
*/
public function getUserRepository(String $repositoryClass)
public function getUserRepository(string $repositoryClass)
{
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->persistenceManager = $this->objectManager->get(PersistenceManager::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