Skip to content

Commit

Permalink
fix issues when not using user model for users
Browse files Browse the repository at this point in the history
  • Loading branch information
cannycookie committed Oct 27, 2023
1 parent a04f910 commit 7400362
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 26 deletions.
3 changes: 2 additions & 1 deletion config/filament-email-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//Admin Panel Resource Navigation Options
'navigation'=>[
'sort'=>50,
'group'=>'Settings',
'group'=>'Content Management',
],

//Email templates will be copied to resources/views/vendor/vb-email-templates/email
Expand Down Expand Up @@ -84,6 +84,7 @@
'user_verified' => true,
'login' => true,
'password_reset_success' => true,
'locked_out' => true,
],

];
6 changes: 4 additions & 2 deletions src/Listeners/PasswordResetListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public function __construct()
*/
public function handle(PasswordReset $event)
{
$user = $event->user;
$user->notify(new UserPasswordResetNotification());
if(config('filament-email-templates.send_emails.password_reset_success')) {
$user = $event->user;
$user->notify(new UserPasswordResetNotification());
}


}
Expand Down
6 changes: 4 additions & 2 deletions src/Listeners/UserLockoutListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class UserLockoutListener
*/
public function handle(Login $event)
{
$user = $event->user;
$user->notify(new UserLockoutNotification());
if(config('filament-email-templates.send_emails.locked_out')) {
$user = $event->user;
$user->notify(new UserLockoutNotification());
}

}
}
6 changes: 4 additions & 2 deletions src/Listeners/UserLoginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class UserLoginListener
*/
public function handle(Login $event)
{
$user = $event->user;
$user->notify(new UserLoginNotification());
if(config('filament-email-templates.send_emails.login')) {
$user = $event->user;
$user->notify(new UserLoginNotification());
}
}
}
8 changes: 4 additions & 4 deletions src/Listeners/UserVerifiedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function __construct()
*/
public function handle(Verified $event)
{
$user = $event->user;
$user->notify(new UserVerifiedNotification());


if(config('filament-email-templates.send_emails.user_verified')) {
$user = $event->user;
$user->notify(new UserVerifiedNotification());
}
}
}
19 changes: 10 additions & 9 deletions src/Models/EmailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function getEmailPreviewData()
$model = self::createEmailPreviewData();

// preparing logo
$logo = $this->prepareLogo($this->logo);
$logo = $this->resolveLogoUrl($this->logo);

return [
'user' => $model->user,
Expand Down Expand Up @@ -253,18 +253,19 @@ public function getMailableClass()
}

/**
* Resolve logo to a url
* @return string
*/
public function prepareLogo($logo)
public function resolveLogoUrl($logo):string
{
$preparedLogo = "";
if (is_null($logo)) {
return asset(config('filament-email-templates.logo'));
}

$preparedLogo = is_null($logo)
? asset(config('filament-email-templates.logo'))
: (Str::isUrl($logo)
? $logo
: asset('storage/' . $logo));
if (Str::isUrl($logo)) {
return $logo;
}

return $preparedLogo;
return asset($logo);
}
}
35 changes: 35 additions & 0 deletions src/Nodes/ModelAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Visualbuilder\EmailTemplates\Nodes;

use Tiptap\Core\Node;
use Tiptap\Utils\HTML;

class ModelAttribute extends Node
{
public static $name = 'model-attribute';

public static $priority = 100;

public function addOptions()
{
return [
'HTMLAttributes' => [],
];
}

public function parseHTML()
{
return [
[
'tag' => 'model-attribute[data-path]',
],

];
}

public function renderHTML($node,$HTMLAttributes = [])
{
return ['model-attribute', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
}
}
2 changes: 0 additions & 2 deletions src/Notifications/UserLoginNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public function via($notifiable)
*/
public function toMail($notifiable)
{
if(config('filament-email-templates.send_emails.login')) {
return app(UserLoginEmail::class, ['user' => $notifiable]);
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Notifications/UserVerifiedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public function via($notifiable)
*/
public function toMail($notifiable)
{
if(config('filament-email-templates.send_emails.user_verified')) {

return app(UserVerifiedEmail::class, ['user' => $notifiable]);
}

}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Resources/EmailTemplateResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public static function form(Form $form): Form
->hint(__('vb-email-templates::email-templates.form-fields-labels.title-hint')),

TiptapEditor::make('content')
->tools([])
->label(__('vb-email-templates::email-templates.form-fields-labels.content'))
->profile('default')
->default("<p>Dear ##user.firstname##, </p>"),
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/EmailTemplateThemeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function getPluralModelLabel(): string

public static function getPreviewData()
{
$emailTemplate = EmailTemplate::findEmailByKey('user-verify-email');
$emailTemplate = EmailTemplate::first();

return $emailTemplate->getEmailPreviewData();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/BuildGenericEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function build()
}

// preparing logo
$logo = $template->prepareLogo($template->logo);
$logo = $template->resolveLogoUrl($template->logo);

$data = [
'content' => $template->replaceTokens($template->content, $this),
Expand Down

0 comments on commit 7400362

Please sign in to comment.