Skip to content

Commit

Permalink
GH-224 Move email content creator to an util
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jun 11, 2022
1 parent a8d71ee commit 388c906
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 38 deletions.
2 changes: 2 additions & 0 deletions modules/settings/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
5 changes: 5 additions & 0 deletions modules/settings/utils/content/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace UniEngine\Engine\Modules\Settings\Utils\Content;

/**
* @param array $params
* @param arrayRef $params['user']
* @param string $params['newEmailAddress']
* @param string $params['changeTokenOldAddress']
* @param string $params['changeTokenNewAddress']
* @param number $params['currentTimestamp']
*/
function prepareChangeProcessEmails($params) {
global $_Lang, $_GameConfig;

$user = &$params['user'];
$newEmailAddress = $params['newEmailAddress'];
$changeTokenOldAddress = $params['changeTokenOldAddress'];
$changeTokenNewAddress = $params['changeTokenNewAddress'];
$currentTimestamp = $params['currentTimestamp'];

$mailContentCommonProps = [
'EP_GameName' => $_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&amp;key={$changeTokenOldAddress}",
'EP_Text' => $_Lang['Email_MailOld'],
'EP_Text2' => $_Lang['Email_WarnOld']
];
$mailContentNewAddressProps = [
'EP_Link' => GAMEURL . "email_change.php?hash=new&amp;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)
),
],
];
}

?>
56 changes: 18 additions & 38 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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&amp;key={$changeTokenOldAddress}",
'EP_Text' => $_Lang['Email_MailOld'],
'EP_Text2' => $_Lang['Email_WarnOld']
];
$mailContentNewAddressProps = [
'EP_Link' => GAMEURL."email_change.php?hash=new&amp;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 (
Expand Down

0 comments on commit 388c906

Please sign in to comment.