Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/AuthenticationModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ protected function registerUrlHandlers()
$className = $url->logoutLeafClassName;
return new $className($provider, $url->loginProviderClassName);
}),
$url->activateChildUrl => $activate = new LeafCollectionUrlHandler($url->activatePasswordLeafClassName,$url->activatePasswordLeafClassName),
$url->onboardingChildUrl => $activate = new GreedyUrlHandler(function ($parentHandler, $captured) use ($url, $provider) {
$className = $url->onboardingPasswordLeafClassName;
return new $className($provider, $captured);
})
]),
$url->urlToProtect => $protected =
new ValidateLoginUrlHandler($provider, $url->loginUrl),
Expand Down
52 changes: 52 additions & 0 deletions src/Emails/AccountOnboardingInvitationEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Rhubarb\Scaffolds\Authentication\Emails;

use Rhubarb\Crown\Settings\WebsiteSettings;
use Rhubarb\Scaffolds\Authentication\Settings\ProtectedUrl;

class AccountOnboardingInvitationEmail extends ResetPasswordInvitationEmail
{
public function getText()
{
$settings = WebsiteSettings::singleton();

return <<<Text
You have recently been invited to {$settings->absoluteWebsiteUrl}

Below you will find a link which will allow you to set your password.

Please note you must do this within 24 hours or you will need to request a new invitation.

{$settings->absoluteWebsiteUrl}/login/activate/{$this->user->PasswordResetHash}/
Text;
}

/**
* @return string
*/
public function getSubject()
{
return 'Create Your Account';
}

public function getHtmlHeading()
{
return "<h1>Create Your Account</h1>";
}

public function getHtmlBody()
{
$settings = WebsiteSettings::singleton();

return <<<HtmlBody
<p>You have recently been invited to {$settings->absoluteWebsiteUrl}</p>

<p>Below you will find a link which will allow you to set your password.</p>

<p>Please note you must do this within 24 hours or you will need to request a new invitation.</p>

<p><a href="{$settings->absoluteWebsiteUrl}/login/activate/{$this->user->PasswordResetHash}/">Click to activate your account</a></p>
HtmlBody;
}
}
46 changes: 2 additions & 44 deletions src/Emails/ActivateAccountInvitationEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,8 @@

namespace Rhubarb\Scaffolds\Authentication\Emails;

use Rhubarb\Crown\Settings\WebsiteSettings;

class ActivateAccountInvitationEmail extends ResetPasswordInvitationEmail
/** @deprecated use AccountOnboardingInvitationEmail */
class ActivateAccountInvitationEmail extends AccountOnboardingInvitationEmail
{
public function getText()
{
$settings = WebsiteSettings::singleton();

return <<<Text
You have recently been invited to {$settings->absoluteWebsiteUrl}

Below you will find a link which will allow you to set your password.

Please note you must do this within 24 hours or you will need to request a new invitation.

{$settings->absoluteWebsiteUrl}/login/activate/{$this->user->PasswordResetHash}/
Text;
}

/**
* @return string
*/
public function getSubject()
{
return 'Activate Your Account';
}

public function getHtmlHeading()
{
return "<h1>Activate Your Account</h1>";
}

public function getHtmlBody()
{
$settings = WebsiteSettings::singleton();

return <<<HtmlBody
<p>You have recently been invited to {$settings->absoluteWebsiteUrl}</p>

<p>Below you will find a link which will allow you to set your password.</p>

<p>Please note you must do this within 24 hours or you will need to request a new invitation.</p>

<p><a href="{$settings->absoluteWebsiteUrl}/login/activate/{$this->user->PasswordResetHash}/">Click to activate your account</a></p>
HtmlBody;
}
}
11 changes: 11 additions & 0 deletions src/Leaves/AccountOnboarding.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Rhubarb\Scaffolds\Authentication\Leaves;

class AccountOnboarding extends ConfirmResetPassword
{
protected function getViewClass()
{
return AccountOnboardingView::class;
}
}
87 changes: 87 additions & 0 deletions src/Leaves/AccountOnboardingView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace Rhubarb\Scaffolds\Authentication\Leaves;

use Rhubarb\Leaf\Controls\Common\Buttons\Button;

class AccountOnboardingView extends ConfirmResetPasswordView
{
protected function createSubLeaves()
{
parent::createSubLeaves();

$this->registerSubLeaf(
new Button("ActivateAccount", "Activate Account", function () {
$this->model->confirmPasswordResetEvent->raise();
})
);
}

protected function printViewContent()
{
$messages = $this->getMessages();

if (isset($messages[$this->model->message])) {
$closure = $messages[$this->model->message];

if (is_callable($closure)) {
print $closure();
} else {
print $closure;
}

return;
}

$this->layoutItemsWithContainer($this->getTitle(),
"<p class='c-form__help'>{$this->getTitleParagraph()}</p>",
[
"Create your password" => "newPassword",
"Confirm your password" => "confirmNewPassword",
"" => "ActivateAccount"
]
);
}

protected function getTitle()
{
return "Create your account";
}

protected function getTitleParagraph()
{
return "Create your account by setting your password.";
}

protected function getMessages()
{
$messages = [];

$messages['PasswordReset'] = <<<PasswordReset
<p class="c-alert">Thanks, your account has now been activated. If you still have difficulties logging in you
should contact us for assistance. We will never ask you for your password, but we should
be able to reset it for you.</p>
PasswordReset;

$messages["PasswordsDontMatch"] = <<<PasswordsDontMatch
<p class="c-alert c-alert--error">Sorry, the password entries you made do not match.
Please enter your password again</p>
PasswordsDontMatch;

$messages["PasswordEmpty"] = <<<PasswordEmpty
<p class="c-alert c-alert--error">Password and Confirm Password fields cannot be empty</p>
PasswordEmpty;

$messages["UserNotRecognised"] = <<<PasswordsDontMatch
<p class="c-alert c-alert--error">Sorry, the user account you are attempting to reset has not been recognised.
Please ask for a new invitation</p>
PasswordsDontMatch;

$messages['HashInvalid'] = <<<HashInvalid
<p class="c-alert c-alert--error">Sorry, your activation link has expired or is not recognised.
Please ask for a new invitation</p>
HashInvalid;

return $messages;
}
}
8 changes: 3 additions & 5 deletions src/Leaves/ActivateAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace Rhubarb\Scaffolds\Authentication\Leaves;

class ActivateAccount extends ConfirmResetPassword
/** @deprecated use AccountOnboarding */
class ActivateAccount extends AccountOnboarding
{
protected function getViewClass()
{
return ActivateAccountView::class;
}

}
82 changes: 2 additions & 80 deletions src/Leaves/ActivateAccountView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,8 @@

namespace Rhubarb\Scaffolds\Authentication\Leaves;

use Rhubarb\Leaf\Controls\Common\Buttons\Button;

class ActivateAccountView extends ConfirmResetPasswordView
/** @deprecated use AccountOnboardingView */
class ActivateAccountView extends AccountOnboardingView
{
protected function createSubLeaves()
{
parent::createSubLeaves();

$this->registerSubLeaf(
new Button("ActivateAccount", "Activate Account", function () {
$this->model->confirmPasswordResetEvent->raise();
})
);
}

protected function printViewContent()
{
$messages = $this->getMessages();

if (isset($messages[$this->model->message])) {
$closure = $messages[$this->model->message];

if (is_callable($closure)) {
print $closure();
} else {
print $closure;
}

return;
}

$this->layoutItemsWithContainer($this->getTitle(),
"<p class='c-form__help'>{$this->getTitleParagraph()}</p>",
[
"Enter new password" => "newPassword",
"Enter again to confirm" => "confirmNewPassword",
"" => "ActivateAccount"
]
);
}

protected function getTitle()
{
return "Activate your account";
}

protected function getTitleParagraph()
{
return "Activate your account by setting your password.";
}

protected function getMessages()
{
$messages = [];

$messages['PasswordReset'] = <<<PasswordReset
<p class="c-alert">Thanks, your account has now been activated. If you still have difficulties logging in you
should contact us for assistance. We will never ask you for your password, but we should
be able to reset it for you.</p>
PasswordReset;

$messages["PasswordsDontMatch"] = <<<PasswordsDontMatch
<p class="c-alert c-alert--error">Sorry, the password entries you made do not match.
Please enter your password again</p>
PasswordsDontMatch;

$messages["PasswordEmpty"] = <<<PasswordEmpty
<p class="c-alert c-alert--error">Password and Confirm Password fields cannot be empty</p>
PasswordEmpty;

$messages["UserNotRecognised"] = <<<PasswordsDontMatch
<p class="c-alert c-alert--error">Sorry, the user account you are attempting to reset has not been recognised.
Please ask for a new invitation</p>
PasswordsDontMatch;

$messages['HashInvalid'] = <<<HashInvalid
<p class="c-alert c-alert--error">Sorry, your activation link has expired or is not recognised.
Please ask for a new invitation</p>
HashInvalid;

return $messages;
}
}
6 changes: 3 additions & 3 deletions src/Settings/ProtectedUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rhubarb\Scaffolds\Authentication\Settings;

use Rhubarb\Scaffolds\Authentication\Leaves\ActivateAccount;
use Rhubarb\Scaffolds\Authentication\Leaves\AccountOnboarding;
use Rhubarb\Scaffolds\Authentication\Leaves\ConfirmResetPassword;
use Rhubarb\Scaffolds\Authentication\Leaves\Login;
use Rhubarb\Scaffolds\Authentication\Leaves\Logout;
Expand All @@ -23,8 +23,8 @@ class ProtectedUrl
public $resetPasswordLeafClassName = ResetPassword::class;
public $confirmResetPasswordLeafClassName = ConfirmResetPassword::class;

public $activateChildUrl = 'activate/';
public $activatePasswordLeafClassName = ActivateAccount::class;
public $onboardingChildUrl = 'activate/';
public $onboardingPasswordLeafClassName = AccountOnboarding::class;

public function __construct($urlToProtect, $loginProviderClassName, $loginUrl)
{
Expand Down
18 changes: 18 additions & 0 deletions src/UseCases/SendAccountOnboardingInvitationEmailUseCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Rhubarb\Scaffolds\Authentication\Leaves;

use Rhubarb\Crown\DependencyInjection\Container;
use Rhubarb\Crown\Sendables\Email\EmailProvider;
use Rhubarb\Scaffolds\Authentication\Emails\AccountOnboardingInvitationEmail;
use Rhubarb\Scaffolds\Authentication\User;

class SendAccountOnboardingInvitationEmailUseCase
{
public static function execute(User $user)
{
$user->generatePasswordResetHash();
$resetPasswordEmail = Container::instance(AccountOnboardingInvitationEmail::class, $user);
EmailProvider::selectProviderAndSend($resetPasswordEmail);
}
}
17 changes: 5 additions & 12 deletions src/UseCases/SendActivateAccountInvitationEmailUseCase.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
<?php

namespace Rhubarb\Scaffolds\Authentication\Leaves;
namespace Rhubarb\Scaffolds\Authentication\UseCases;

use Rhubarb\Crown\DependencyInjection\Container;
use Rhubarb\Crown\Sendables\Email\EmailProvider;
use Rhubarb\Scaffolds\Authentication\Emails\ActivateAccountInvitationEmail;
use Rhubarb\Scaffolds\Authentication\User;
use Rhubarb\Scaffolds\Authentication\Leaves\SendAccountOnboardingInvitationEmailUseCase;

class SendActivateAccountInvitationEmailUseCase
/** @deprecated use SendAccountOnboardingInvitiationEmailUseCase */
class SendActivateAccountInvitationEmailUseCase extends SendAccountOnboardingInvitationEmailUseCase
{
public static function execute(User $user)
{
$user->generatePasswordResetHash();
$resetPasswordEmail = Container::instance(ActivateAccountInvitationEmail::class, $user);
EmailProvider::selectProviderAndSend($resetPasswordEmail);
}

}