Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
t3o
my.typo3.org
Commits
1cb8ef59
Commit
1cb8ef59
authored
Mar 29, 2019
by
Stefan Busemann
Browse files
[REFACTOR] Add error handling
parent
e40b2da0
Pipeline
#6592
failed with stages
in 27 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
extensions/t3o_ldap/Classes/Connectors/Ldap.php
View file @
1cb8ef59
...
...
@@ -93,6 +93,7 @@ class Ldap
/**
* LDAP constructor.
* @throws \Exception
*/
public
function
__construct
()
{
...
...
@@ -109,8 +110,21 @@ 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 +263,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
))
{
...
...
extensions/t3o_ldap/Classes/Utility/UserCreateUpdateDelete.php
View file @
1cb8ef59
...
...
@@ -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
()))
{
...
...
extensions/t3omy/Classes/Hooks/FeManagerHooks.php
View file @
1cb8ef59
<?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'
;
}
}
extensions/t3omy/Classes/Hooks/ReactivateUserHook.php
View file @
1cb8ef59
...
...
@@ -59,8 +59,19 @@ class ReactivateUserHook implements \TYPO3\CMS\Backend\RecordList\RecordListGetT
$this
->
persistenceManager
->
persistAll
();
$ldapOperation
=
$this
->
objectManager
->
get
(
FeManagerHooks
::
class
);
try
{
$ldapOperation
->
createUser
(
$frontendUser
);
}
catch
(
\
Exception
$e
)
{
$this
->
addFlashMessage
(
$e
->
getMessage
(),
\
TYPO3\CMS\Core\Messaging\FlashMessage
::
ERROR
,
'Error '
.
$e
->
getCode
()
);
return
false
;
}
return
$ldapOperation
->
createUser
(
$frontendUser
)
;
return
true
;
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment