LDAP fixes

This commit is contained in:
Taras Machyshyn
2020-01-17 14:30:21 +02:00
parent 30afaa56ab
commit c404d47473
2 changed files with 27 additions and 12 deletions
@@ -99,6 +99,22 @@ class LDAP extends Espo
return $this->utils;
}
protected function getContainer()
{
return $this->getInjection('container');
}
protected function useSystemUser()
{
$systemUser = $this->getEntityManager()->getEntity('User', 'system');
if (!$systemUser) {
throw new Error("System user is not found.");
}
$this->getContainer()->setUser($systemUser);
$this->getEntityManager()->setUser($systemUser);
}
protected function getLdapClient()
{
if (!isset($this->ldapClient)) {
@@ -183,7 +199,12 @@ class LDAP extends Espo
]
]);
if (!isset($user) && $this->getUtils()->getOption('createEspoUser')) {
if (!isset($user)) {
if (!$this->getUtils()->getOption('createEspoUser')) {
$this->useSystemUser();
throw new Error($this->getContainer()->get('language')->translate('ldapUserInEspoNotFound', 'messages', 'User'));
}
$userData = $ldapClient->getEntry($userDn);
$user = $this->createUser($userData, $isPortal);
}
@@ -283,18 +304,11 @@ class LDAP extends Espo
$data[$fieldName] = $fieldValue;
}
$entityManager = $this->getEntityManager();
$this->useSystemUser();
$systemUser = $entityManager->getEntity('User', 'system');
if (!$systemUser) {
throw new Error("System user is not found");
}
$this->getInjection('container')->setUser($systemUser);
$entityManager->setUser($systemUser);
$user = $entityManager->getEntity('User');
$user = $this->getEntityManager()->getEntity('User');
$user->set($data);
$entityManager->saveEntity($user);
$this->getEntityManager()->saveEntity($user);
return $this->getEntityManager()->getEntity('User', $user->id);
}
@@ -109,7 +109,8 @@
"enterTotpCode": "Enter a code from your authenticator app.",
"verifyTotpCode": "Scan the QR-code with your mobile authenticator app. If you have a trouble with scanning, you can enter the secret manually. After that you will see a 6-digit code in your application. Enter this code in the field below.",
"generateAndSendNewPassword": "A new password will be generated and sent to the user's email address.",
"security2FaResetConfimation": "Are you sure you want to reset the current 2FA settings?"
"security2FaResetConfimation": "Are you sure you want to reset the current 2FA settings?",
"ldapUserInEspoNotFound": "User is not found in EspoCRM. Contact your administrator to create the user."
},
"options": {
"gender": {