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
bea247c9
Commit
bea247c9
authored
Jul 20, 2017
by
Stefan Busemann
Browse files
[TASK] Add Slackbot support
parent
180b7006
Pipeline
#1722
failed with stages
in 23 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
html/typo3conf/ext/t3omy/Classes/Hooks/FeManagerHooks.php
View file @
bea247c9
...
...
@@ -31,7 +31,9 @@ namespace T3o\T3omy\Hooks;
use
In2code\Femanager\Domain\Model\User
;
use
T3o\T3oLdap\Connectors\Ldap
;
use
T3o\T3oLdap\Utility\UserCreateUpdateDelete
;
use
TYPO3\CMS\Core\TypoScript\TypoScriptService
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Extbase\Utility\DebuggerUtility
;
/**
* Hook Functions for \
...
...
@@ -43,20 +45,31 @@ class FeManagerHooks
*/
protected
$ldapUserCreateUpdateDelete
;
/**
* @var settings
*/
protected
$settings
;
/**
* DataHandlerHook constructor
*/
public
function
__construct
()
{
$this
->
ldapUserCreateUpdateDelete
=
new
UserCreateUpdateDelete
();
$this
->
settings
=
$this
->
getTSConifiguration
();
#$this->ldapUserCreateUpdateDelete = new UserCreateUpdateDelete();
}
public
function
newUserNotification
()
public
function
newUserNotification
(
User
$user
,
$plugin
)
{
// @todo add user location
$mapsLink
=
' - na - '
;
// this event happens, when a user registered himself and no autoapprovement got active
die
(
'newUserNotification'
);
// @todo slack message notification
$this
->
sendConfirmationMessage
(
$user
);
// @todo add second confirmation email
$this
->
sendConfirmationEmail
(
$user
);
$this
->
sendSlackBotMessage
(
'New User Registration'
,
sprintf
(
...
...
@@ -71,12 +84,14 @@ class FeManagerHooks
}
public
function
newUserAutoApprovement
()
public
function
newUserAutoApprovement
(
User
$user
,
$plugin
)
{
// @todo add user location
$mapsLink
=
' - na - '
;
// this event happens, when a user registered himself and an autoapprovement got active
die
(
'AutoApprovementDone'
);
// @todo slack message notification
$this
->
createUser
(
$user
);
$this
->
sendSlackBotMessage
(
'New user auto approvement'
,
sprintf
(
...
...
@@ -88,13 +103,11 @@ class FeManagerHooks
),
'info'
);
}
public
function
newUserAdminApprovement
()
public
function
newUserAdminApprovement
(
User
$user
)
{
#AutoApprovementRefused
die
(
'AdminApprovementDone'
);
$this
->
sendSlackBotMessage
(
'User approved'
,
sprintf
(
...
...
@@ -107,15 +120,14 @@ class FeManagerHooks
);
}
public
function
newUserAdminDecline
()
public
function
newUserAdminDecline
(
User
$user
)
{
#AutoApprovementRefused
die
(
'AdminApprovementRefused'
);
$this
->
sendSlackBotMessage
(
'User declined'
,
sprintf
(
'the user *%s* with email *%s* has been declined by *%s*'
,
$username
,
$user
->
getUser
name
()
,
$user
->
getEmail
(),
$GLOBALS
[
'BE_USER'
]
->
user
[
'username'
]
),
...
...
@@ -128,11 +140,11 @@ class FeManagerHooks
* in LDAP.
*
* @param \In2code\Femanager\Domain\Model\User $user
* @return
void
* @return
bool
*/
public
function
createUser
(
User
$user
)
{
$result
=
$this
->
ldapUserCreateUpdateDelete
->
updateUser
(
$user
->
getUid
(),
$user
->
toArray
());
#
$result = $this->ldapUserCreateUpdateDelete->updateUser($user->getUid(), $user->toArray());
// TODO: Create log entry if user has been successfully added or throw an exception otherwise
...
...
@@ -141,6 +153,8 @@ class FeManagerHooks
}
else
{
}
return
true
;
}
/**
...
...
@@ -211,9 +225,9 @@ class FeManagerHooks
*/
protected
function
sendSlackBotMessage
(
$title
,
$text
,
$color
=
'notice'
)
{
$url
=
$this
->
settings
[
'webhook'
][
'url'
];
$url
=
$this
->
settings
[
'
slackbot'
][
'
webhook'
][
'url'
];
$content
=
json_encode
(
array
(
'securityToken'
=>
$this
->
settings
[
'webhook'
][
'securityToken'
],
'securityToken'
=>
$this
->
settings
[
'
slackbot'
][
'
webhook'
][
'securityToken'
],
'color'
=>
$color
,
'title'
=>
$title
,
'text'
=>
$text
...
...
@@ -228,4 +242,26 @@ class FeManagerHooks
curl_exec
(
$curl
);
curl_close
(
$curl
);
}
protected
function
getTSConifiguration
()
{
// init ConfigurationManager
$configurationManager
=
GeneralUtility
::
makeInstance
(
'TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager'
);
// load complete ts
$tsSettings
=
$configurationManager
->
getConfiguration
(
\
TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
::
CONFIGURATION_TYPE_FULL_TYPOSCRIPT
);
// remove dots from configuration
$typoscriptService
=
GeneralUtility
::
makeInstance
(
TypoScriptService
::
class
);
$tsSettings
=
$typoscriptService
->
convertTypoScriptArrayToPlainArray
(
$tsSettings
);
return
$this
->
settings
=
$tsSettings
[
'plugin'
][
'tx_t3omy'
];
}
/**
* @return bool
*/
protected
function
sendConfirmationEmail
(
User
$user
){
return
true
;
}
}
Write
Preview
Supports
Markdown
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