Skip to content

Commit

Permalink
Merge pull request #44 from MarcoPNS/master
Browse files Browse the repository at this point in the history
TASK: Add Neos 5.x Compatibility
  • Loading branch information
skurfuerst authored Jan 10, 2020
2 parents cdc7c12 + c84077b commit b2b03da
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
18 changes: 5 additions & 13 deletions Classes/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
namespace Sandstorm\UserManagement\Controller;

use Neos\Error\Messages\Error;
use Neos\Error\Messages\Message;
use Neos\Flow\Mvc\Controller\ControllerContext;
use Neos\Flow\Security\Exception\AuthenticationRequiredException;
use Sandstorm\UserManagement\Domain\Service\RedirectTargetServiceInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Exception;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Security\Authentication\Controller\AbstractAuthenticationController;

use Neos\Flow\Core\Bootstrap;
use Psr\Http\Message\UriFactoryInterface;


class LoginController extends AbstractAuthenticationController
{
Expand Down Expand Up @@ -93,9 +95,7 @@ protected function onAuthenticationSuccess(ActionRequest $originalRequest = null
protected function onAuthenticationFailure(AuthenticationRequiredException $exception = null)
{
$this->emitAuthenticationFailure($this->controllerContext, $exception);

$this->flashMessageContainer->addMessage(new Error($this->loginFailedBody,
($exception === null ? 1347016771 : $exception->getCode()), [], $this->loginFailedTitle));
$this->addFlashMessage($this->loginFailedBody, $this->loginFailedTitle,Message::SEVERITY_ERROR, [], ($exception === null ? 1347016771 : $exception->getCode()));
}

/**
Expand Down Expand Up @@ -164,15 +164,7 @@ protected function emitLogout(ControllerContext $controllerContext)
protected function redirectToUriAndShutdown(string $result)
{
$escapedUri = htmlentities($result, ENT_QUOTES, 'utf-8');

$response = $this->bootstrap->getActiveRequestHandler()->getHttpResponse(); /** @var \Neos\Flow\Http\Response $response*/

$response->setHeader('Location', $escapedUri);
$response->setHeader('Status', '303');

$response->setContent('<html><head><meta http-equiv="refresh" content="0;url=' . $escapedUri . '"/></head></html>');
$response->send();

$this->redirectToUri($this->uriFactory->createUri((string)$escapedUri));
$this->bootstrap->shutdown(Bootstrap::RUNLEVEL_RUNTIME);
exit();
}
Expand Down
16 changes: 9 additions & 7 deletions Classes/Domain/Validator/CustomPasswordDtoValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,48 @@ class CustomPasswordDtoValidator extends AbstractValidator
*/
protected function isValid($value)
{
$result = $this->getResult();

// Matching PW and PW confirmation
if (!$value->arePasswordsEqual()) {
$message = $this->translator->translateById('validations.password.matching', [], null, null, 'Main', 'Sandstorm.UserManagement');
$this->result->forProperty('password')->addError(new Error($message, 1464086581));
$result->forProperty('password')->addError(new Error($message, 1464086581));
}

// Min length
if (!$value->isPasswordMinLength($this->passwordConstraints['minLength'])) {
$message = $this->translator->translateById('validations.password.minlength', [$this->passwordConstraints['minLength']], null, null, 'Main', 'Sandstorm.UserManagement');
$this->result->forProperty('password')->addError(new Error($message, 1542220177));
$result->forProperty('password')->addError(new Error($message, 1542220177));
}

// Max length
if (!$value->isPasswordMaxLength($this->passwordConstraints['maxLength'])) {
$message = $this->translator->translateById('validations.password.maxlength', [$this->passwordConstraints['maxLength']], null, null, 'Main', 'Sandstorm.UserManagement');
$this->result->forProperty('password')->addError(new Error($message, 1542220177));
$result->forProperty('password')->addError(new Error($message, 1542220177));
}

// minNumberOfLowercaseLetters
if (!$value->doesPasswordContainLowercaseLetters($this->passwordConstraints['minNumberOfLowercaseLetters'])) {
$message = $this->translator->translateById('validations.password.lowercase', [$this->passwordConstraints['minNumberOfLowercaseLetters']], $this->passwordConstraints['minNumberOfLowercaseLetters'], null, 'Main', 'Sandstorm.UserManagement');
$this->result->forProperty('password')->addError(new Error($message, 1542220177));
$result->forProperty('password')->addError(new Error($message, 1542220177));
}

// minNumberOfUppercaseLetters
if (!$value->doesPasswordContainUppercaseLetters($this->passwordConstraints['minNumberOfUppercaseLetters'])) {
$message = $this->translator->translateById('validations.password.uppercase', [$this->passwordConstraints['minNumberOfUppercaseLetters']], $this->passwordConstraints['minNumberOfUppercaseLetters'], null, 'Main', 'Sandstorm.UserManagement');
$this->result->forProperty('password')->addError(new Error($message, 1542220177));
$result->forProperty('password')->addError(new Error($message, 1542220177));
}

// minNumberOfNumbers
if (!$value->doesPasswordContainNumbers($this->passwordConstraints['minNumberOfNumbers'])) {
$message = $this->translator->translateById('validations.password.numbers', [$this->passwordConstraints['minNumberOfNumbers']], $this->passwordConstraints['minNumberOfNumbers'], null, 'Main', 'Sandstorm.UserManagement');
$this->result->forProperty('password')->addError(new Error($message, 1542220177));
$result->forProperty('password')->addError(new Error($message, 1542220177));
}

// minNumberOfSpecialCharacters
if (!$value->doesPasswordContainSpecialCharacters($this->passwordConstraints['minNumberOfSpecialCharacters'])) {
$message = $this->translator->translateById('validations.password.special', [$this->passwordConstraints['minNumberOfSpecialCharacters']], $this->passwordConstraints['minNumberOfSpecialCharacters'], null, 'Main', 'Sandstorm.UserManagement');
$this->result->forProperty('password')->addError(new Error($message, 1542220177));
$result->forProperty('password')->addError(new Error($message, 1542220177));
}
}
}
14 changes: 13 additions & 1 deletion Classes/ViewHelpers/IfAuthenticatedViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@
class IfAuthenticatedViewHelper extends AbstractConditionViewHelper
{

/**
* Initialize arguments
*
* @return void
* @api
*/
public function initializeArguments()
{
$this->registerArgument('authenticationProviderName', 'string', 'Use a different Authentication Provider than the default one', false,'Sandstorm.UserManagement:Login');
}

/**
* Renders <f:then> child if any account is currently authenticated, otherwise renders <f:else> child.
*
* @param string $authenticationProviderName
* @return string the rendered string
* @api
*/
public function render($authenticationProviderName = 'Sandstorm.UserManagement:Login')
public function render()
{
$authenticationProviderName = $this->arguments['authenticationProviderName'];
if (static::evaluateCondition($this->arguments, $this->renderingContext)) {
return $this->renderThenChild();
}
Expand Down
8 changes: 4 additions & 4 deletions Resources/Private/Templates/Registration/Index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
<fieldset>
<label>
E-Mail-Adresse
<f:form.textfield property="email" placeholder="[email protected]" name="__authentication[Neos][Flow][Security][Authentication][Token][UsernamePassword][username]" type="email"/>
<f:form.textfield property="email" placeholder="[email protected]" name="__authentication[Neos][Flow][Security][Authentication][Token][UsernamePassword][username]" type="email" required="true"/>
<f:render partial="FormErrors" section="ValidationResults" arguments="{for: 'registrationFlow.email'}"/>
</label>

<label>
Passwort
<f:form.password placeholder="Ihr Passwort" property="passwordDto.password"/>
<f:form.password placeholder="Ihr Passwort" property="passwordDto.password" required="true"/>
<f:render partial="FormErrors" section="ValidationResults" arguments="{for: 'registrationFlow.passwordDto.password'}"/>
</label>

<label>
Passwortbestätigung
<f:form.password placeholder="Passwort wiederholen" property="passwordDto.passwordConfirmation"/>
<f:form.password placeholder="Passwort wiederholen" property="passwordDto.passwordConfirmation" required="true"/>
</label>

<label>
Expand All @@ -40,7 +40,7 @@

<label>
Vorname
<f:form.textfield placeholder="Manfred" property="attributes.firstName"/>
<f:form.textfield placeholder="Manfred" property="attributes.firstName" required="true"/>
<f:render partial="FormErrors" section="ValidationResults" arguments="{for: 'registrationFlow.attributes.firstName'}"/>
</label>

Expand Down

1 comment on commit b2b03da

@cpits
Copy link

@cpits cpits commented on b2b03da Jan 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a basic Flow distribution (6.x), redirection in the LoginController still fails on Line 167:

$this->redirectToUri($this->uriFactory->createUri((string)$escapedUri));

As there is the excapedUri available, use instead:

$this->redirectToUri($escapedUri);

Tested with Flow 6.0.5.

Please sign in to comment.