Skip to content

Commit

Permalink
Extension update for TYPO3 10.4 and PHP 7.4
Browse files Browse the repository at this point in the history
* Updated the sources to use more of the PHP 7.4 language features
* Also formatted the code to be more PSR-12 compliant
* Updated composer dependencies for TYPO3 10.4
* Added ext-openssl to composer dependencies because of a function used
in the HashGenerator::generateRandomHash() method
* Added travis ci and style ci config
* Updated the readme
* Added a .gitkeep file to the unit test folder
* Removed unused and empty ext_tables.php

Issues
REHAUTHEXT-1, REHAUTHEXT-2
  • Loading branch information
Hauke Schulz committed Nov 10, 2021
1 parent c01553c commit 81d9be7
Show file tree
Hide file tree
Showing 25 changed files with 3,739 additions and 2,834 deletions.
27 changes: 27 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
risky: true

preset: psr12

enabled:
- alpha_ordered_imports
- combine_consecutive_issets
- combine_consecutive_unsets
- const_separation
- dir_constant
- hash_to_slash_comment
- native_function_casing
- no_alias_functions
- no_blank_lines_after_phpdoc
- no_empty_statement
- no_extra_consecutive_blank_lines
- no_short_bool_cast
- no_singleline_whitespace_before_semicolons
- no_trailing_comma_in_singleline_array
- no_unneeded_control_parentheses
- no_unused_imports
- phpdoc_no_package
- phpdoc_scalar
- self_accessor
- short_array_syntax
- single_quote
- whitespace_after_comma_in_array
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
language: php

os: linux
dist: xenial

php:
- 7.4

env:
global:
- XDEBUG_MODE=coverage


notifications:
email:
on_success: never

webhooks:
- https://outlook.office.com/webhook/5fc0971d-1679-464f-a6bf-7a764b449d7e@bc56f797-60e9-407b-bc2c-e79f2058cd21/TravisCI/ff0950008ce34f25a712223cd3d95d0e/baa29ec6-e36b-4136-8ceb-9adbb3949188

before_script:
- composer self-update --no-progress --quiet --no-interaction
- composer install --no-progress --quiet --no-interaction

script:
- composer run test

after_success: bash <(curl -s https://codecov.io/bash)
102 changes: 67 additions & 35 deletions Classes/Controller/LoginController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Remind\RmndHybridauth\Controller;

use Exception;
Expand All @@ -23,7 +25,7 @@
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
* @author Marco Wegner <[email protected]>
* LoginController
*/
class LoginController extends ActionController
{
Expand All @@ -36,55 +38,59 @@ class LoginController extends ActionController
* Action argument with selected provider
* @var string
*/
const ARGUMENT_PROVIDER = 'provider';
public const ARGUMENT_PROVIDER = 'provider';

/**
* Login token argument for fe_login
* @var string
*/
const ARGUMENT_LOGIN_TOKEN = 'token';
public const ARGUMENT_LOGIN_TOKEN = 'token';

/**
* connection uid argument for fe_login
* @var string
*/
const ARGUMENT_CONNECTION_UID = 'connection';
public const ARGUMENT_CONNECTION_UID = 'connection';

/**
* TypoScript object with provider settings
* @var string
*/
const SETTINGS_PROVIDERS = 'providers';
public const SETTINGS_PROVIDERS = 'providers';

/**
* TypoScript setting for error page (only used when no provider selected)
* @var string
*/
const SETTINGS_ERROR_PID = 'errorPid';
public const SETTINGS_ERROR_PID = 'errorPid';

/**
* Class which maps provider information to fe_users
* @var string
*/
const SETTINGS_USER_MAPPER_CLASS = 'userMapperClass';
public const SETTINGS_USER_MAPPER_CLASS = 'userMapperClass';

/**
* @var string
*/
const TRANSLATION_FILE = 'LLL:EXT:rmnd_hybridauth/Resources/Private/Language/locallang.xlf:';
public const TRANSLATION_FILE = 'LLL:EXT:rmnd_hybridauth/Resources/Private/Language/locallang.xlf:';

/**
* Authenticate with given provider
*
* @return void
*/
public function authAction(): void
{
$providerSettings = $this->getProviderSettings();
$errorPid = (int)$this->settings[self::SETTINGS_ERROR_PID];
$errorPid = (int) $this->settings[self::SETTINGS_ERROR_PID];

if($providerSettings === null) {
if ($providerSettings === null) {
$this->addFlashMessage(
LocalizationUtility::translate(self::TRANSLATION_FILE . 'error.provider_not_configured', 'rmnd_hybridauth'),
LocalizationUtility::translate(
self::TRANSLATION_FILE . 'error.provider_not_configured',
'rmnd_hybridauth'
),
'',
AbstractMessage::ERROR
);
Expand All @@ -94,12 +100,20 @@ public function authAction(): void

$loggedIn = $this->login($providerSettings);

if(!$loggedIn) {
if (!$loggedIn) {
$errorPidRedirect = $providerSettings->getRedirectPidAfterError() ?? $errorPid;
$this->redirect('authError', null, null, $this->getAfterLoginArguments(), $errorPidRedirect, 0, 303);
}

$this->redirect('loginComplete', null, null, $this->getAfterLoginArguments(), $providerSettings->getRedirectPidAfterLogin(), 0, 303);
$this->redirect(
'loginComplete',
null,
null,
$this->getAfterLoginArguments(),
$providerSettings->getRedirectPidAfterLogin(),
0,
303
);
}

/**
Expand All @@ -120,9 +134,12 @@ protected function login(ProviderSettings $providerSettings): bool
/* Try connecting by redirecting when not already connected */
$connection = $hybridauthConnector->connect($providerSettings, $callbackUrl);

if(empty($connection)) {
if (empty($connection)) {
$this->addFlashMessage(
LocalizationUtility::translate(self::TRANSLATION_FILE . 'error.user_not_created', 'rmnd_hybridauth'),
LocalizationUtility::translate(
self::TRANSLATION_FILE . 'error.user_not_created',
'rmnd_hybridauth'
),
'',
AbstractMessage::ERROR
);
Expand All @@ -137,15 +154,14 @@ protected function login(ProviderSettings $providerSettings): bool
/* Use loginService or directly login in controller */
$isUseLoginService = ExtensionSettingsUtility::isUseAfterAuthLoginService();

if($isUseLoginService) {
if ($isUseLoginService) {
/* Create auth token and redirect to current page but with another action */
$this->redirectToAfterAuthUri($connection, $providerSettings);
return true;
}

/* Login service is not activated, so directly login user here (dirty method) */
$isLoggedIn = $this->loginUser($connection->getFeUser());

} catch (Exception $ex) {
$this->addFlashMessage(
LocalizationUtility::translate(self::TRANSLATION_FILE . 'error.login_exception', 'rmnd_hybridauth'),
Expand All @@ -156,7 +172,7 @@ protected function login(ProviderSettings $providerSettings): bool
return false;
}

if(!$isLoggedIn) {
if (!$isLoggedIn) {
$this->addFlashMessage(
LocalizationUtility::translate(self::TRANSLATION_FILE . 'error.typo3_login_failed', 'rmnd_hybridauth'),
'',
Expand All @@ -173,7 +189,7 @@ protected function login(ProviderSettings $providerSettings): bool
*/
protected function getUserMapper(): UserMapperInterface
{
if(empty($this->settings[self::SETTINGS_USER_MAPPER_CLASS])) {
if (empty($this->settings[self::SETTINGS_USER_MAPPER_CLASS])) {
return new BaseUserMapper($this->objectManager);
}

Expand Down Expand Up @@ -209,7 +225,8 @@ protected function redirectToAfterAuthUri(Connection $connection, ProviderSettin

/* Redirect, so the auth service kicks in and logs in user */
HttpUtility::redirect(
$redirectUri, HttpUtility::HTTP_STATUS_303
$redirectUri,
HttpUtility::HTTP_STATUS_303
);
}

Expand All @@ -232,7 +249,7 @@ protected function loginUser(FrontendUser $user): bool

$userData = $tsfe->fe_user->fetchUserRecord($info['db_user'], $user->getUsername(), $extraWhere);

if(empty($userData)) {
if (empty($userData)) {
return false;
}

Expand Down Expand Up @@ -306,15 +323,16 @@ protected function isUserLoggedIn(): bool
{
/* @var $tsfe TypoScriptFrontendController */
$tsfe = $GLOBALS['TSFE'];
if(empty($tsfe)) {

if (empty($tsfe)) {
return false;
}

if(empty($tsfe->fe_user)) {
if (empty($tsfe->fe_user)) {
return false;
}

if(empty($tsfe->fe_user->user)) {
if (empty($tsfe->fe_user->user)) {
return false;
}

Expand All @@ -331,18 +349,20 @@ public function afterAuthAction(): void
$providerSettings = $this->getProviderSettings();
$errorPid = (int)$this->settings[self::SETTINGS_ERROR_PID];

if($providerSettings === null) {
if ($providerSettings === null) {
$this->addFlashMessage(
LocalizationUtility::translate(self::TRANSLATION_FILE . 'error.provider_not_configured', 'rmnd_hybridauth'),
LocalizationUtility::translate(
self::TRANSLATION_FILE . 'error.provider_not_configured',
'rmnd_hybridauth'
),
'',
AbstractMessage::ERROR
);

$this->redirect('authError', null, null, $this->getAfterLoginArguments(), $errorPid, 0, 303);
}

if(!$loggedIn) {

if (!$loggedIn) {
$this->addFlashMessage(
LocalizationUtility::translate(self::TRANSLATION_FILE . 'error.typo3_login_failed', 'rmnd_hybridauth'),
'',
Expand All @@ -353,7 +373,15 @@ public function afterAuthAction(): void
$this->redirect('authError', null, null, $this->getAfterLoginArguments(), $errorPidRedirect, 0, 303);
}

$this->redirect('loginComplete', null, null, $this->getAfterLoginArguments(), $providerSettings->getRedirectPidAfterLogin(), 0, 303);
$this->redirect(
'loginComplete',
null,
null,
$this->getAfterLoginArguments(),
$providerSettings->getRedirectPidAfterLogin(),
0,
303
);
}

/**
Expand Down Expand Up @@ -381,20 +409,24 @@ public function authErrorAction(): void
protected function getProviderSettings(): ?ProviderSettings
{

if(!$this->request->hasArgument(self::ARGUMENT_PROVIDER)) {
if (!$this->request->hasArgument(self::ARGUMENT_PROVIDER)) {
return null;
}

$argumentProvider = $this->request->getArgument(self::ARGUMENT_PROVIDER);

if(!\is_string($argumentProvider) || empty($argumentProvider)) {
if (!is_string($argumentProvider) || empty($argumentProvider)) {
return null;
}

$provider = ProviderSettingsLoader::getSingleProviderSettings($argumentProvider, $this->settings, self::SETTINGS_PROVIDERS);
$provider = ProviderSettingsLoader::getSingleProviderSettings(
$argumentProvider,
$this->settings,
self::SETTINGS_PROVIDERS
);

/* Return null if provider is not active */
if(!$provider->getIsActive()) {
if (!$provider->getIsActive()) {
return null;
}

Expand All @@ -409,11 +441,11 @@ protected function getAfterLoginArguments(): array
{
$arguments = [];

if($this->request->hasArgument(self::ARGUMENT_PROVIDER)) {
if ($this->request->hasArgument(self::ARGUMENT_PROVIDER)) {
$arguments[self::ARGUMENT_PROVIDER] = $this->request->getArgument(self::ARGUMENT_PROVIDER);
}

if($this->request->hasArgument(self::ARGUMENT_CONNECTION_UID)) {
if ($this->request->hasArgument(self::ARGUMENT_CONNECTION_UID)) {
$arguments[self::ARGUMENT_CONNECTION_UID] = $this->request->getArgument(self::ARGUMENT_CONNECTION_UID);
}

Expand Down
3 changes: 3 additions & 0 deletions Classes/Domain/Model/Connection.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Remind\RmndHybridauth\Domain\Model;

/***
Expand Down
16 changes: 4 additions & 12 deletions Classes/Domain/Repository/ConnectionRepository.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
<?php

declare(strict_types=1);

namespace Remind\RmndHybridauth\Domain\Repository;

use Remind\RmndHybridauth\Domain\Model\Connection;
use TYPO3\CMS\Extbase\Persistence\Repository;

/***
*
* This file is part of the "REMIND - Hybridauth" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2020 Marco Wegner <[email protected]>
*
***/

/**
* The repository for Hybridauth connections
*/
Expand All @@ -38,7 +30,7 @@ public function findConnection(string $provider, string $identifier, int $pid =
$query->equals('identifier', $identifier),
];

if($pid > 0) {
if ($pid > 0) {
// @todo test
$constraints[] = $query->equals('feUser.pid', $pid);
}
Expand Down
Loading

0 comments on commit 81d9be7

Please sign in to comment.