-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored to use new Templates package functionality (#5)
* Refactored to use new Templates package functionality * Update github actions * Fix tests * Test for config api
- Loading branch information
Showing
42 changed files
with
1,127 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace EscolaLms\TemplatesEmail\Database\Seeders; | ||
|
||
use EscolaLms\Templates\Facades\Template; | ||
use EscolaLms\TemplatesEmail\Core\EmailChannel; | ||
use Illuminate\Database\Seeder; | ||
|
||
class TemplatesEmailSeeder extends Seeder | ||
{ | ||
public function run() | ||
{ | ||
Template::createDefaultTemplatesForChannel(EmailChannel::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 21 additions & 21 deletions
42
...nums/Email/AbstractAuthEmailVariables.php → src/Auth/CommonAuthVariables.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,63 @@ | ||
<?php | ||
|
||
namespace EscolaLms\TemplatesEmail\Enums\Email; | ||
namespace EscolaLms\TemplatesEmail\Auth; | ||
|
||
use EscolaLms\Auth\Models\User; | ||
use EscolaLms\Core\Enums\BasicEnum; | ||
use EscolaLms\Notifications\Core\NotificationVariableContract; | ||
use Illuminate\Support\Str; | ||
use EscolaLms\Templates\Events\EventWrapper; | ||
use EscolaLms\TemplatesEmail\Core\EmailVariables; | ||
|
||
abstract class AbstractAuthEmailVariables extends BasicEnum implements NotificationVariableContract | ||
abstract class CommonAuthVariables extends EmailVariables | ||
{ | ||
// | ||
const VAR_USER_EMAIL = "@VarUserEmail"; | ||
const VAR_USER_FIRST_NAME = "@VarStudentFirstName"; | ||
const VAR_USER_LAST_NAME = "@VarStudentLastName"; | ||
const VAR_USER_FULL_NAME = "@VarStudentFullName"; | ||
const VAR_ACTION_LINK = "@VarActionLink"; | ||
|
||
public static function getMockVariables(): array | ||
public static function mockedVariables(): array | ||
{ | ||
$faker = \Faker\Factory::create(); | ||
return [ | ||
return array_merge(parent::mockedVariables(), [ | ||
self::VAR_USER_EMAIL => $faker->email, | ||
self::VAR_USER_FIRST_NAME => $faker->firstName, | ||
self::VAR_USER_LAST_NAME => $faker->lastName, | ||
self::VAR_USER_FULL_NAME => $faker->name, | ||
self::VAR_ACTION_LINK => url('/'), | ||
]; | ||
]); | ||
} | ||
|
||
public static function getVariablesFromContent(?User $user = null, ?string $action_link = null): array | ||
public static function variablesFromEvent(EventWrapper $event): array | ||
{ | ||
$user = $event->getUser(); | ||
return [ | ||
self::VAR_USER_EMAIL => $user->email, | ||
self::VAR_USER_FIRST_NAME => $user->firstName, | ||
self::VAR_USER_LAST_NAME => $user->lastName, | ||
self::VAR_USER_FULL_NAME => $user->name, | ||
self::VAR_ACTION_LINK => $action_link, | ||
self::VAR_ACTION_LINK => static::getActionLink($event), | ||
]; | ||
} | ||
|
||
public static function getRequiredVariables(): array | ||
abstract static function getActionLink(EventWrapper $event): string; | ||
|
||
public static function requiredVariables(): array | ||
{ | ||
return [ | ||
self::VAR_ACTION_LINK, | ||
]; | ||
} | ||
|
||
public static function isValid(string $content): bool | ||
{ | ||
return Str::containsAll($content, self::getRequiredVariables()); | ||
} | ||
|
||
public static function getRequiredTitleVariables(): array | ||
public static function requiredVariablesInSection(string $sectionKey): array | ||
{ | ||
if ($sectionKey === 'content') { | ||
return [ | ||
self::VAR_ACTION_LINK | ||
]; | ||
} | ||
return []; | ||
} | ||
|
||
public static function titleIsValid(?string $title): bool | ||
public static function assignableClass(): ?string | ||
{ | ||
return !empty($title); | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace EscolaLms\TemplatesEmail\Auth; | ||
|
||
use EscolaLms\Templates\Events\EventWrapper; | ||
use Illuminate\Support\Str; | ||
use EscolaLms\Auth\Repositories\Contracts\UserRepositoryContract; | ||
use Illuminate\Support\Facades\Lang; | ||
|
||
class ResetPasswordVariables extends CommonAuthVariables | ||
{ | ||
const VAR_ACTION_LINK_EXPIRATION = "@VarActionLinkExpiration"; | ||
|
||
public static function mockedVariables(): array | ||
{ | ||
return array_merge(parent::mockedVariables(), [ | ||
self::VAR_ACTION_LINK_EXPIRATION => config('auth.passwords.' . config('auth.defaults.passwords') . '.expire'), | ||
]); | ||
} | ||
|
||
public static function variablesFromEvent(EventWrapper $event): array | ||
{ | ||
return array_merge(parent::variablesFromEvent($event), [ | ||
self::VAR_ACTION_LINK_EXPIRATION => config('auth.passwords.' . config('auth.defaults.passwords') . '.expire'), | ||
]); | ||
} | ||
|
||
public static function getActionLink(EventWrapper $event): string | ||
{ | ||
$notifiable = $event->getUser(); | ||
|
||
$token = Str::random(32); | ||
|
||
app(UserRepositoryContract::class)->update([ | ||
'password_reset_token' => Str::random(32), | ||
], $notifiable->getKey()); | ||
|
||
try { | ||
$url = $event->getReturnUrl(); | ||
} catch (\Throwable $th) { | ||
$url = null; | ||
} | ||
|
||
if (!empty($url)) { | ||
return $url . | ||
'?email=' . $notifiable->getEmailForPasswordReset() . | ||
'&token=' . $token; | ||
} | ||
return url(route('password.reset', [ | ||
'token' => $token, | ||
'email' => $notifiable->getEmailForPasswordReset(), | ||
], false)); | ||
} | ||
|
||
public static function defaultSectionsContent(): array | ||
{ | ||
return [ | ||
'title' => Lang::get('Reset Password Notification'), | ||
'content' => self::wrapWithMjml( | ||
'<mj-text>' | ||
. '<p>' | ||
. Lang::get('You are receiving this email because we received a password reset request for your account.') | ||
. '</p>' | ||
. '</mj-text>' | ||
. '<mj-button href="' . self::VAR_ACTION_LINK . '">' . Lang::get('Reset Password') . '</mj-button>' | ||
. '<mj-text>' | ||
. '<p>' | ||
. Lang::get('This password reset link will expire in :count minutes.', ['count' => self::VAR_ACTION_LINK_EXPIRATION]) | ||
. '</p>' | ||
. '<p>' | ||
. Lang::get('If you did not request a password reset, no further action is required.') | ||
. '</p>' | ||
. '</mj-text>' | ||
) | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace EscolaLms\TemplatesEmail\Auth; | ||
|
||
use EscolaLms\Templates\Events\EventWrapper; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Facades\Lang; | ||
use Illuminate\Support\Facades\URL; | ||
|
||
class VerifyEmailVariables extends CommonAuthVariables | ||
{ | ||
public static function getActionLink(EventWrapper $event): string | ||
{ | ||
$notifiable = $event->getUser(); | ||
|
||
return URL::temporarySignedRoute( | ||
'verification.verify', | ||
Carbon::now()->addMinutes(config('auth.verification.expire', 60)), | ||
[ | ||
'id' => $notifiable->getKey(), | ||
'hash' => sha1($notifiable->getEmailForVerification()), | ||
] | ||
); | ||
} | ||
|
||
public static function defaultSectionsContent(): array | ||
{ | ||
return [ | ||
'title' => Lang::get('Verify Email Address'), | ||
'content' => self::wrapWithMjml( | ||
'<mj-text>' | ||
. '<p>' | ||
. Lang::get('Please click the button below to verify your email address.') | ||
. '</p>' | ||
. '</mj-text>' | ||
. '<mj-button href="' . self::VAR_ACTION_LINK . '">' . Lang::get('Verify Email Address') . '</mj-button>' | ||
. '<mj-text>' | ||
. '<p>' | ||
. Lang::get('If you did not create an account, no further action is required.') | ||
. '</p>' | ||
. '</mj-text>' | ||
) | ||
]; | ||
} | ||
} |
Oops, something went wrong.