Commit 0beb1250 authored by Stefan Busemann's avatar Stefan Busemann
Browse files

Merge branch '6-add-t3omy-extension' into 'develop'

Resolve "Add t3omy extension"

Closes #6

See merge request !7
parents ac84af22 7403f1a1
Pipeline #1786 passed with stages
in 4 minutes and 15 seconds
......@@ -53,7 +53,8 @@
},
"autoload": {
"psr-4": {
"t3o\\t3olayout\\": "html/typo3conf/ext/t3olayout/Classes"
"T3o\\T3olayout\\": "html/typo3conf/ext/t3olayout/Classes",
"T3o\\T3omy\\": "html/typo3conf/ext/t3omy/Classes"
}
}
}
<?php
namespace T3o\T3omy\Hooks;
/***************************************************************
* Copyright notice
*
* (c) 2017 Stefan Busemann (in2code GmbH)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
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;
/**
* Hook Functions for \
*/
class FeManagerHooks
{
/**
* @var UserCreateUpdateDelete
*/
protected $ldapUserCreateUpdateDelete;
/**
* @var array
*/
protected $settings;
/**
* DataHandlerHook constructor
*/
public function __construct()
{
$this->settings = $this->getTSConifiguration();
#$this->ldapUserCreateUpdateDelete = new UserCreateUpdateDelete();
}
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
// @todo add second confirmation email
$this->sendConfirmationEmail($user);
$this->sendSlackBotMessage(
'New User Registration',
sprintf(
'new user registered on typo3.org with username: *%s* email: *%s* name: *%s* and IP located in: %s',
$user->getUsername(),
$user->getEmail(),
$user->getName(),
$mapsLink
),
'notice'
);
}
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
$this->createUser($user);
$this->sendSlackBotMessage(
'New user auto approvement',
sprintf(
'new user registered on typo3.org with username: *%s* email: *%s* name: *%s* and IP located in: %s was auto approved',
$user->getUsername(),
$user->getEmail(),
$user->getName(),
$mapsLink
),
'info'
);
}
/**
* @param User $user
*/
public function newUserAdminApprovement(User $user)
{
#User was approved via backend
$this->sendSlackBotMessage(
'User approved',
sprintf(
'the user *%s* with email *%s* has been approved by *%s*',
$user->getUsername(),
$user->getEmail(),
$GLOBALS['BE_USER']->user['username']
),
'ok'
);
}
/**
* @param User $user
*/
public function newUserAdminDecline(User $user)
{
#User was approved via backend
$this->sendSlackBotMessage(
'User declined',
sprintf(
'the user *%s* with email *%s* has been declined by *%s*',
$user->getUsername(),
$user->getEmail(),
$GLOBALS['BE_USER']->user['username']
),
'danger'
);
}
/**
* Use DataHandler "afterAllOperations" hook to update or create FE Users
* in LDAP.
*
* @param \In2code\Femanager\Domain\Model\User $user
* @return bool
*/
public function createUser(User $user)
{
#$result = $this->ldapUserCreateUpdateDelete->updateUser($user->getUid(), $user->toArray());
// TODO: Create log entry if user has been successfully added or throw an exception otherwise
#if ($result === true) {
#} else {
#}
return true;
}
/**
* Use DataHandler "afterAllOperations" hook to update or create FE Users
* in LDAP.
*
* @param \In2code\Femanager\Domain\Model\User $user
* @return void
*/
public function updateUser(User $user)
{
$result = $this->ldapUserCreateUpdateDelete->updateUser($user->getUid(), $user->toArray());
// TODO: Create log entry if user has been successfully updated or throw an exception othwerwise
if ($result === true) {
} else {
}
}
/**
* Use DataHandler "afterAllOperations" hook to update or create FE Users
* in LDAP.
*
* @param \In2code\Femanager\Domain\Model\User $user
* @return void
*/
public function deleteUser(User $user)
{
$userData = $user->toArray();
$ldap = GeneralUtility::makeInstance(Ldap::class);
if ($ldap->userExists($userData['username'])) {
$ret = $ldap->deleteUser($userData['username']);
// TODO: Handle the resonse as needed
if ($ret === true) {
} else {
}
}
}
/**
* @param $_funcRef
* @param $_params
* @param bool
*/
public function writePassword($_funcRef, $_params, $felogin = false)
{
$feUserUid = $_funcRef['user']['uid'];
$userData = $_funcRef['user'];
// set new password
$userData['password'] = $_funcRef['newPasswordUnencrypted'];
$createIfNotExists = false;
// @todo add error handling
$result = $this->ldapUserCreateUpdateDelete->updateUser($feUserUid, $userData, $createIfNotExists);
}
/**
* @param string $title
* @param string $text
* @param string $color
*/
protected function sendSlackBotMessage($title, $text, $color = 'notice')
{
$url = $this->settings['slackbot']['webhook']['url'];
$content = json_encode(array(
'securityToken' => $this->settings['slackbot']['webhook']['securityToken'],
'color' => $color,
'title' => $title,
'text' => $text
));
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
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;
}
}
plugin.tx_femanager {
view {
templateRootPaths.3 = EXT:t3omy/Resources/Private/Templates/Femanager/
layoutRootPaths.3 = EXT:t3omy/Resources/Private/Templates/Femanager/
}
settings {
new {
validation {
terms.required = 1
name.required = 1
}
requestRedirect = TEXT
requestRedirect {
parameter = {$plugin.tx_t3omy.page.createMessage}
returnLast = url
view {
templateRootPaths.3 = EXT:t3omy/Resources/Private/Templates/Femanager/
layoutRootPaths.3 = EXT:t3omy/Resources/Private/Templates/Femanager/
}
settings {
new {
validation {
terms.required = 1
name.required = 1
}
requestRedirect = TEXT
requestRedirect {
typolink {
parameter = {$tx_t3omy.page.createMessage}
parameter.insertData = 1
returnLast = url
}
}
}
}
#
# redirect user after user clicks confirmation link in emailX
userConfirmationRedirect = TEXT
userConfirmationRedirect {
typolink {
parameter = 194
returnLast = url
}
}
autoApprovement = 1
autoApprovement {
enable = 1
whitelistDomains {
allowTopLevelDomains = .de
exceptions =
}
blacklistDomains =
}
confirmByAdmin = 1
}
}
}
page.includeJSFooter.femanagerValidation >
plugin.tx_t3omy {
slackbot {
webhook {
securityToken =
url =
}
}
}
<section class="container">
<div class="tx-femanager">
<f:render section="main" />
<f:render partial="Misc/AdditionalFields" arguments="{_all}" />
</div>
</section>
......@@ -11,8 +11,8 @@
],
"autoload": {
"psr-4": {
"T3o\\T3olayout\\": "Classes"
"T3o\\T3omy\\": "Classes"
}
},
"version": "0.0.1"
"version": "0.0.2"
}
......@@ -10,6 +10,7 @@ $EM_CONF[$_EXTKEY] = array(
'depends' => array(
'typo3' => '8.7.0-8.99.99',
't3olayout' => '0.1.0-',
't3o_slack' => '0.1.0-',
'fluid_styled_content' => '7.6.0-8.99.99'
),
'conflicts' => array(
......@@ -27,5 +28,5 @@ $EM_CONF[$_EXTKEY] = array(
'author' => 'Stefan Busemann',
'author_email' => 'stefan.busemann@typo3.org',
'author_company' => 'typo3',
'version' => '0.0.2',
'version' => '0.0.3',
);
......@@ -3,3 +3,39 @@ if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
#######################################
###
#######################################
/**
* Register signal slots
* TODO: add the signal names
*/
$dispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
$dispatcher->connect(
\In2code\Femanager\Controller\NewController::class,
'isAdminConfirmationMissingAutoApprovementDone',
\T3o\T3omy\Hooks\FeManagerHooks::class,
'newUserAutoApprovement'
);
$dispatcher->connect(
\In2code\Femanager\Controller\NewController::class,
'isAdminConfirmationMissingAutoApprovementRefused',
\T3o\T3omy\Hooks\FeManagerHooks::class,
'newUserNotification'
);
$dispatcher->connect(
\In2code\Femanager\Controller\UserBackendController::class,
'',
\T3o\T3omy\Hooks\FeManagerHooks::class,
'newUserAdminApprovement'
);
$dispatcher->connect(
\In2code\Femanager\Controller\UserBackendController::class,
'deleteAction',
\T3o\T3omy\Hooks\FeManagerHooks::class,
'deleteUser'
);
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['password_changed'][] = \T3o\T3omy\Hooks\FeManagerHooks::class . '->writePassword';
Supports Markdown
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