From 388c90669edea601be1cb798f5fb516e44da81eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Sat, 11 Jun 2022 14:08:17 +0200 Subject: [PATCH] GH-224 Move email content creator to an util --- modules/settings/_includes.php | 2 + modules/settings/utils/content/index.php | 5 ++ .../prepareChangeProcessEmails.content.php | 69 +++++++++++++++++++ settings.php | 56 +++++---------- 4 files changed, 94 insertions(+), 38 deletions(-) create mode 100644 modules/settings/utils/content/index.php create mode 100644 modules/settings/utils/content/prepareChangeProcessEmails.content.php diff --git a/modules/settings/_includes.php b/modules/settings/_includes.php index 7c83d5427..a3d56cf7a 100644 --- a/modules/settings/_includes.php +++ b/modules/settings/_includes.php @@ -6,6 +6,8 @@ $includePath = $_EnginePath . 'modules/settings/'; + include($includePath . './utils/content/prepareChangeProcessEmails.content.php'); + include($includePath . './utils/errorMappers/validatePasswordChange.errorMapper.php'); include($includePath . './utils/errorMappers/validateEmailChange.errorMapper.php'); diff --git a/modules/settings/utils/content/index.php b/modules/settings/utils/content/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/settings/utils/content/index.php @@ -0,0 +1,5 @@ + diff --git a/modules/settings/utils/content/prepareChangeProcessEmails.content.php b/modules/settings/utils/content/prepareChangeProcessEmails.content.php new file mode 100644 index 000000000..fa6aae6f4 --- /dev/null +++ b/modules/settings/utils/content/prepareChangeProcessEmails.content.php @@ -0,0 +1,69 @@ + $_GameConfig['game_name'], + 'EP_User' => $user['username'], + 'EP_GameLink' => GAMEURL_STRICT, + 'EP_OldMail' => $user['email'], + 'EP_NewMail' => $newEmailAddress, + 'EP_Date' => date('d.m.Y - H:i:s', $currentTimestamp), + 'EP_IP' => $user['user_lastip'], + 'EP_ContactLink' => GAMEURL_STRICT . '/contact.php', + ]; + + $mailContentOldAddressProps = [ + 'EP_Link' => GAMEURL . "email_change.php?hash=old&key={$changeTokenOldAddress}", + 'EP_Text' => $_Lang['Email_MailOld'], + 'EP_Text2' => $_Lang['Email_WarnOld'] + ]; + $mailContentNewAddressProps = [ + 'EP_Link' => GAMEURL . "email_change.php?hash=new&key={$changeTokenNewAddress}", + 'EP_Text' => $_Lang['Email_MailNew'], + 'EP_Text2' => $_Lang['Email_WarnNew'] + ]; + + $mailTitle = parsetemplate( + $_Lang['Email_Title'], + [ + 'gameName' => $_GameConfig['game_name'] + ] + ); + + return [ + 'oldAddress' => [ + 'title' => $mailTitle, + 'content' => parsetemplate( + $_Lang['Email_Body'], + array_merge($mailContentCommonProps, $mailContentOldAddressProps) + ), + ], + 'newAddress' => [ + 'title' => $mailTitle, + 'content' => parsetemplate( + $_Lang['Email_Body'], + array_merge($mailContentCommonProps, $mailContentNewAddressProps) + ), + ], + ]; +} + +?> diff --git a/settings.php b/settings.php index 7df1c2421..546442939 100644 --- a/settings.php +++ b/settings.php @@ -176,49 +176,29 @@ $changeTokenOldAddress = md5($_User['id'] . $_User['username'] . mt_rand(0, 999999999)); $changeTokenNewAddress = md5($_User['id'] . $_User['username'] . mt_rand(0, 999999999)); - $mailContentCommonProps = [ - 'EP_GameName' => $_GameConfig['game_name'], - 'EP_User' => $_User['username'], - 'EP_GameLink' => GAMEURL_STRICT, - 'EP_OldMail' => $_User['email'], - 'EP_NewMail' => $normalizedInputNewEmailAddress, - 'EP_Date' => date('d.m.Y - H:i:s', $ThisTime), - 'EP_IP' => $_User['user_lastip'], - 'EP_ContactLink' => GAMEURL_STRICT.'/contact.php', - ]; - - $mailContentOldAddressProps = [ - 'EP_Link' => GAMEURL."email_change.php?hash=old&key={$changeTokenOldAddress}", - 'EP_Text' => $_Lang['Email_MailOld'], - 'EP_Text2' => $_Lang['Email_WarnOld'] - ]; - $mailContentNewAddressProps = [ - 'EP_Link' => GAMEURL."email_change.php?hash=new&key={$changeTokenNewAddress}", - 'EP_Text' => $_Lang['Email_MailNew'], - 'EP_Text2' => $_Lang['Email_WarnNew'] - ]; - include($_EnginePath.'includes/functions/SendMail.php'); - $mailBodyOldAddress = parsetemplate( - $_Lang['Email_Body'], - array_merge($mailContentCommonProps, $mailContentOldAddressProps) + $changeProcessEmails = Settings\Utils\Content\prepareChangeProcessEmails([ + 'user' => &$_User, + 'newEmailAddress' => $normalizedInputNewEmailAddress, + 'changeTokenOldAddress' => $changeTokenOldAddress, + 'changeTokenNewAddress' => $changeTokenNewAddress, + 'currentTimestamp' => $ThisTime, + ]); + + $sendMail2OldAddressResult = SendMail( + $_User['email'], + $changeProcessEmails['oldAddress']['title'], + $changeProcessEmails['oldAddress']['content'], + '', + true ); - $mailBodyNewAddress = parsetemplate( - $_Lang['Email_Body'], - array_merge($mailContentCommonProps, $mailContentNewAddressProps) + $sendMail2NewAddressResult = SendMail( + $normalizedInputNewEmailAddress, + $changeProcessEmails['newAddress']['title'], + $changeProcessEmails['newAddress']['content'] ); - $mailTitle = parsetemplate( - $_Lang['Email_Title'], - [ - 'gameName' => $_GameConfig['game_name'] - ] - ); - - $sendMail2OldAddressResult = SendMail($_User['email'], $mailTitle, $mailBodyOldAddress, '', true); - $sendMail2NewAddressResult = SendMail($normalizedInputNewEmailAddress, $mailTitle, $mailBodyNewAddress); - CloseMailConnection(); if (