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

Prevent user to register a username which was taken and not in LDAP

parent 079bcb4c
Pipeline #4142 passed with stages
in 4 minutes and 20 seconds
......@@ -69,6 +69,10 @@ class ServersideValidator extends \In2code\Femanager\Domain\Validator\Serverside
$this->checkUniqueInLdapValidation($user, $value, $validationSetting, $fieldName);
break;
case 'notInOldUserTable':
$this->notInOldUserTableValidation($user, $value, $validationSetting, $fieldName);
break;
case 'mustInclude':
$this->checkMustIncludeValidation($value, $validationSetting, $fieldName);
break;
......@@ -114,9 +118,35 @@ class ServersideValidator extends \In2code\Femanager\Domain\Validator\Serverside
{
$ldap = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\T3o\T3oLdap\Connectors\Ldap::class);
if ($ldap->userExists($value)) {
$this->addError(ucfirst($fieldName) . ' is already in use (LDAP)', $fieldName);
$this->addError(ucfirst($fieldName) . ' is not available.', $fieldName);
$this->isValid = false;
}
}
/**
* @param \In2code\Femanager\Domain\Model\User $user
* @param $value
* @param $validationSettings
* @param $fieldName
* @return void
*/
protected function notInOldUserTableValidation($user, $value, $validationSettings, $fieldName)
{
$queryBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)->getQueryBuilderForTable('old_users');
$usernameExists = (bool)$queryBuilder
->count('*')
->from('old_users')
->where(
$queryBuilder->expr()->eq(
'username',
$queryBuilder->createNamedParameter($value, \PDO::PARAM_STR)
)
)->execute()
->fetchColumn(0);
if ($usernameExists) {
$this->addError(ucfirst($fieldName) . ' is not available.', $fieldName);
$this->isValid = false;
}
}
}
......@@ -13,6 +13,7 @@ plugin.tx_femanager {
username {
uniqueInDb = 0
uniqueInLdap = 1
notInOldUserTable = 1
}
password {
min = 12
......
......@@ -7,3 +7,9 @@ CREATE TABLE fe_users (
facebook VARCHAR (255),
terms_version VARCHAR (255)
);
CREATE TABLE old_users (
uid int(11) unsigned DEFAULT '0',
username varchar(255) DEFAULT '',
email varchar(255) DEFAULT ''
);
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