Skip to content

Commit

Permalink
Add return_url to email verification (#24)
Browse files Browse the repository at this point in the history
* Add return_url to email verification

* Set flag to run email verification event
  • Loading branch information
mako321 authored Feb 1, 2022
1 parent 4740f7b commit 6dd45fa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Auth/VerifyEmailVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ public static function getActionLink(EventWrapper $event): string
{
$notifiable = $event->getUser();

try {
$url = $event->getReturnUrl();
} catch (\Throwable $th) {
$url = null;
}

if (!empty($url)) {
return $url .
'?id=' . $notifiable->getKey() .
'&hash=' . sha1($notifiable->getEmailForVerification());
}

return URL::temporarySignedRoute(
'verification.verify',
Carbon::now()->addMinutes(config('auth.verification.expire', 60)),
Expand Down
12 changes: 12 additions & 0 deletions src/EscolaLmsTemplatesEmailServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace EscolaLms\TemplatesEmail;

use EscolaLms\Auth\EscolaLmsAuthServiceProvider;
use EscolaLms\Auth\Events\AccountRegistered;
use EscolaLms\Auth\Events\ForgotPassword;
use EscolaLms\Auth\Listeners\CreatePasswordResetToken;
use EscolaLms\Auth\Listeners\SendEmailVerificationNotification;
use EscolaLms\Settings\Facades\AdministrableConfig;
use EscolaLms\Templates\EscolaLmsTemplatesServiceProvider;
use EscolaLms\Templates\Repository\Contracts\TemplateRepositoryContract;
Expand Down Expand Up @@ -78,6 +80,16 @@ function () {
));
}
);

SendEmailVerificationNotification::setRunEventEmailVerification(
function () {
$templateRepository = app(TemplateRepositoryContract::class);
return empty($templateRepository->findTemplateDefault(
AccountRegistered::class,
EmailChannel::class
));
}
);
}

public function bootForConsole()
Expand Down
3 changes: 2 additions & 1 deletion tests/Api/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function testVerifyEmail()
'last_name' => 'tester',
'password' => 'testtest',
'password_confirmation' => 'testtest',
'return_url' => 'https://escolalms.com/email/verify',
]);

$this->assertApiSuccess();
Expand All @@ -62,7 +63,7 @@ public function testVerifyEmail()
Notification::assertNotSentTo($user, VerifyEmail::class);

$listener = app(TemplateEventListener::class);
$listener->handle(new AccountRegistered($user));
$listener->handle(new AccountRegistered($user, 'https://escolalms.com/email/verify'));

Mail::assertSent(EmailMailable::class, function (EmailMailable $mailable) use ($user) {
$this->assertEquals('Verify Email Address', $mailable->subject);
Expand Down

0 comments on commit 6dd45fa

Please sign in to comment.