From 2162d8898bd201b5df1582e88f947fd9b23d0df9 Mon Sep 17 00:00:00 2001 From: NaysKutzu Date: Sun, 8 Sep 2024 18:38:12 +0200 Subject: [PATCH] PUSH -> Email Template --- app/App.php | 5 + app/Mail/MailService.php | 64 ++++++++++++ app/Mail/Templates/Verification.php | 19 ++++ app/Managers/DBSettingsManager.php | 3 +- app/Web/Routes/emails.php | 30 ++++++ storage/mails/login.html | 141 +++++++++++++++++++++++++ storage/mails/notification.html | 154 ++++++++++++++++++++++++++++ storage/mails/reset-password.html | 138 +++++++++++++++++++++++++ storage/mails/user-banned.html | 132 ++++++++++++++++++++++++ storage/mails/verify.html | 148 ++++++++++++++++++++++++++ storage/migrate/config/7.php | 5 + 11 files changed, 837 insertions(+), 2 deletions(-) create mode 100644 app/Mail/Templates/Verification.php create mode 100644 app/Web/Routes/emails.php create mode 100644 storage/mails/login.html create mode 100644 storage/mails/notification.html create mode 100644 storage/mails/reset-password.html create mode 100644 storage/mails/user-banned.html create mode 100644 storage/mails/verify.html create mode 100644 storage/migrate/config/7.php diff --git a/app/App.php b/app/App.php index fb8be51..60d405a 100755 --- a/app/App.php +++ b/app/App.php @@ -151,5 +151,10 @@ public static function checkForRequirements(): void if (version_compare(PHP_VERSION, '8.1.0', '<')) { Installer::showError('This application requires at least PHP 8.1.0'); } + + $url = Settings::getSetting('app', 'url'); + if ($url == "http://example.com") { + Settings::updateSetting('app', 'url', "https://".$_SERVER['SERVER_NAME'],true); + } } } diff --git a/app/Mail/MailService.php b/app/Mail/MailService.php index 1602ae9..9d92f8d 100755 --- a/app/Mail/MailService.php +++ b/app/Mail/MailService.php @@ -3,6 +3,7 @@ namespace MythicalSystemsFramework\Mail; use MythicalSystemsFramework\Managers\Settings as setting; +use MythicalSystemsFramework\User\UserHelper; class MailService { @@ -17,4 +18,67 @@ public static function isEnabled(): bool return false; } } + /** + * Process the template at a user level + * + * @param string $template + * @return string + */ + public static function processTemplateUserLevel(string $template,string $token) : string { + $user = new UserHelper($token); + $template = str_replace("{username}", $user->getInfo("username",false), $template); + $template = str_replace("{email}", $user->getInfo("email",false), $template); + $template = str_replace("{first_name}", $user->getInfo("first_name",true), $template); + $template = str_replace("{last_name}", $user->getInfo("last_name",true), $template); + return $template; + } + + /** + * Process the template at a system level (app_name, app_logo, app_url, support_mail) + * @param string $template + * @return string + */ + public static function processTemplateSystemLevel(string $template) : string { + $template = str_replace("{app_name}", setting::getSetting('app', 'name'), $template); + $template = str_replace("{app_logo}", setting::getSetting('app', 'logo'), $template); + $template = str_replace("{app_url}", setting::getSetting('app', 'url'), $template); + $template = str_replace("{support_mail}", setting::getSetting('smtp', 'fromMail'), $template); + return $template; + } + + /** + * Get the template + * + * @param string $template The template you want to get + * + * @return string + */ + public static function getTemplate(string $template): string + { + $template_dir = __DIR__ . "/../../storage/mails/"; + $template_file = $template_dir . $template . ".html"; + if (self::doesTemplateExist($template)) { + return file_get_contents($template_file); + } else { + return ""; + } + } + + /** + * Does the template exist? + * + * @param string $template The template you want to check if it exists + * + * @return bool + */ + public static function doesTemplateExist(string $template): bool + { + $template_dir = __DIR__ . "/../../storage/mails/"; + $template_file = $template_dir . $template . ".html"; + if (file_exists($template_file)) { + return true; + } else { + return false; + } + } } diff --git a/app/Mail/Templates/Verification.php b/app/Mail/Templates/Verification.php new file mode 100644 index 0000000..6dddfee --- /dev/null +++ b/app/Mail/Templates/Verification.php @@ -0,0 +1,19 @@ +connectMYSQLI(); $stmt = $conn->prepare('UPDATE framework_settings SET `svalue` = ? WHERE `skey` = ? AND `scategory` = ?'); - $stmt->bind_param('sss', $scategory, $value, $key); + $stmt->bind_param('sss', $value, $key, $category); $success = $stmt->execute(); $stmt->close(); - return $success; } else { return false; diff --git a/app/Web/Routes/emails.php b/app/Web/Routes/emails.php new file mode 100644 index 0000000..103d5a5 --- /dev/null +++ b/app/Web/Routes/emails.php @@ -0,0 +1,30 @@ +add('/emails/welcome', function () { + $file = file_get_contents(__DIR__ . '/../../../storage/mails/welcome.html'); + echo die($file); +}); + + +$router->add('/emails/reset-password', function () { + $file = file_get_contents(__DIR__ . '/../../../storage/mails/reset-password.html'); + echo die($file); +}); + +$router->add('/emails/user-banned', function () { + $file = file_get_contents(__DIR__ . '/../../../storage/mails/user-banned.html'); + echo die($file); +}); + + +$router->add('/emails/login', function () { + $file = file_get_contents(__DIR__ . '/../../../storage/mails/login.html'); + echo die($file); +}); + +$router->add('/emails/notification', function () { + $file = file_get_contents(__DIR__ . '/../../../storage/mails/notification.html'); + echo die($file); +}); \ No newline at end of file diff --git a/storage/mails/login.html b/storage/mails/login.html new file mode 100644 index 0000000..5738e05 --- /dev/null +++ b/storage/mails/login.html @@ -0,0 +1,141 @@ + + + + + + + + + + + New Account Login + + + + + +
New Account Login
+
+ + + + +
+ + + + + + + + +
+
+ + + diff --git a/storage/mails/notification.html b/storage/mails/notification.html new file mode 100644 index 0000000..fbf620c --- /dev/null +++ b/storage/mails/notification.html @@ -0,0 +1,154 @@ + + + + + + + + + + + + + New Notification + + + + + +
New Notification
+
+ + + + +
+ + + + + + + + +
+
+ + + \ No newline at end of file diff --git a/storage/mails/reset-password.html b/storage/mails/reset-password.html new file mode 100644 index 0000000..17eac90 --- /dev/null +++ b/storage/mails/reset-password.html @@ -0,0 +1,138 @@ + + + + + + + + + + + Reset your Password + + + + + +
A request to reset password was received from + your {app_name} Account
+
+ + + + +
+ + + + + + + + +
+
+ + + \ No newline at end of file diff --git a/storage/mails/user-banned.html b/storage/mails/user-banned.html new file mode 100644 index 0000000..3a03fed --- /dev/null +++ b/storage/mails/user-banned.html @@ -0,0 +1,132 @@ + + + + + + + + + + + Account Deactivated 😔 + + + + + +
Your account on + {app_name} is deactivated.
+
+ + + + +
+ + + + + + + + +
+
+ + + \ No newline at end of file diff --git a/storage/mails/verify.html b/storage/mails/verify.html new file mode 100644 index 0000000..dc71472 --- /dev/null +++ b/storage/mails/verify.html @@ -0,0 +1,148 @@ + + + + + + + + + + + Verify Email Address + + + + + +
Please verify your email address
+
+ + + + +
+ + + + + + + + +
+
+ + + \ No newline at end of file diff --git a/storage/migrate/config/7.php b/storage/migrate/config/7.php new file mode 100644 index 0000000..e4ac5d1 --- /dev/null +++ b/storage/migrate/config/7.php @@ -0,0 +1,5 @@ +