You've already forked php-auth
generated from siteworxpro/Php-Template
initial
Some checks failed
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m50s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m59s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 3m11s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 3m33s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Failing after 3m18s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Failing after 1m14s
Some checks failed
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m50s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m59s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 3m11s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 3m33s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Failing after 3m18s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Failing after 1m14s
This commit is contained in:
12
src/Mailer/Drivers/DriverInterface.php
Normal file
12
src/Mailer/Drivers/DriverInterface.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\App\Mailer\Drivers;
|
||||
|
||||
use Siteworxpro\App\Mailer\Message;
|
||||
|
||||
interface DriverInterface
|
||||
{
|
||||
public function send(Message $message): bool;
|
||||
}
|
||||
36
src/Mailer/Drivers/Log.php
Normal file
36
src/Mailer/Drivers/Log.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\App\Mailer\Drivers;
|
||||
|
||||
use Siteworxpro\App\Mailer\Message;
|
||||
use Siteworxpro\App\Services\Facades\Logger;
|
||||
|
||||
class Log implements DriverInterface
|
||||
{
|
||||
public function send(Message $message): bool
|
||||
{
|
||||
$logMessage = `
|
||||
===============================================
|
||||
To: {$message->getTo()}
|
||||
Subject: {$message->getSubject()}
|
||||
Body:
|
||||
{$this->formatBodyForLog($message->getBody())}
|
||||
===============================================
|
||||
`;
|
||||
|
||||
Logger::info($logMessage);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function formatBodyForLog(string $body): string
|
||||
{
|
||||
$body = str_replace('<br>', "\n", $body);
|
||||
$body = str_replace('<br/>', "\n", $body);
|
||||
$body = strip_tags($body);
|
||||
|
||||
return wordwrap($body, 80);
|
||||
}
|
||||
}
|
||||
33
src/Mailer/Message.php
Normal file
33
src/Mailer/Message.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\App\Mailer;
|
||||
|
||||
readonly class Message
|
||||
{
|
||||
public function __construct(
|
||||
private string $to,
|
||||
private string $subject,
|
||||
private string $body
|
||||
) {
|
||||
if ($to != filter_var($to, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new \InvalidArgumentException('Invalid email address provided.');
|
||||
}
|
||||
}
|
||||
|
||||
public function getTo(): string
|
||||
{
|
||||
return $this->to;
|
||||
}
|
||||
|
||||
public function getSubject(): string
|
||||
{
|
||||
return $this->subject;
|
||||
}
|
||||
|
||||
public function getBody(): string
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
}
|
||||
25
src/Mailer/Sendmail.php
Normal file
25
src/Mailer/Sendmail.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\App\Mailer;
|
||||
|
||||
use Siteworxpro\App\Services\Facades\Config;
|
||||
|
||||
class Sendmail
|
||||
{
|
||||
private Drivers\DriverInterface $driver;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->driver = match (Config::get('mailer.driver')) {
|
||||
'log' => new Drivers\Log(),
|
||||
default => throw new \InvalidArgumentException('Invalid mailer driver specified.'),
|
||||
};
|
||||
}
|
||||
|
||||
public function send(Message $message): bool
|
||||
{
|
||||
return $this->driver->send($message);
|
||||
}
|
||||
}
|
||||
24
src/Mailer/Templates/_base.twig
Normal file
24
src/Mailer/Templates/_base.twig
Normal file
@@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{{ subject }}</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f9f9f9;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
}
|
||||
.container {
|
||||
background-color: #ffffff;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
{{ content|raw }}
|
||||
</body>
|
||||
</html>
|
||||
17
src/Mailer/Templates/password-reset.twig
Normal file
17
src/Mailer/Templates/password-reset.twig
Normal file
@@ -0,0 +1,17 @@
|
||||
{% extends _base.twig %}
|
||||
|
||||
{% block subject %}
|
||||
Password Reset Request
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<p>Dear {{ user.firstName }},</p>
|
||||
|
||||
<p>We received a request to reset your password. Click the link below to set a new password:</p>
|
||||
|
||||
<p><a href="{{ resetLink }}">Reset Your Password</a></p>
|
||||
|
||||
<p>If you did not request a password reset, please ignore this email.</p>
|
||||
|
||||
<p>Best regards,<br>{{ client.name }}</p>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user