Skip to content

Commit

Permalink
GH-224 Move email address process entry 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 ff6f74c commit a8d71ee
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions modules/settings/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
include($includePath . './utils/errorMappers/validatePasswordChange.errorMapper.php');
include($includePath . './utils/errorMappers/validateEmailChange.errorMapper.php');

include($includePath . './utils/queries/createEmailChangeProcessEntry.query.php');
include($includePath . './utils/queries/getUserWithEmailAddress.query.php');

include($includePath . './utils/validators/validatePasswordChange.validator.php');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

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

/**
* @param array $params
* @param arrayRef $params['user']
* @param string $params['newEmailAddress']
* @param string $params['changeTokenOldAddress']
* @param string $params['changeTokenNewAddress']
* @param number $params['currentTimestamp']
*/
function createEmailChangeProcessEntry($params) {
$user = &$params['user'];
$newEmailAddress = $params['newEmailAddress'];
$changeTokenOldAddress = $params['changeTokenOldAddress'];
$changeTokenNewAddress = $params['changeTokenNewAddress'];
$currentTimestamp = $params['currentTimestamp'];

$query = (
"INSERT INTO {{table}} " .
"VALUES " .
"(" .
"NULL, " .
"{$currentTimestamp}, " .
"{$user['id']}, " .
"'{$user['email']}', " .
"'{$newEmailAddress}', " .
"0, " .
"0, " .
"'{$changeTokenOldAddress}', " .
"'{$changeTokenNewAddress}' " .
") " .
";"
);

doquery($query, 'mailchange');
}

?>
12 changes: 8 additions & 4 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,14 @@
$ChangeSet['email_2'] = $normalizedInputNewEmailAddress;
$ChangeSetTypes['email_2'] = 's';

doquery(
"INSERT INTO {{table}} VALUES (NULL, {$ThisTime}, {$_User['id']}, '{$_User['email']}', '{$normalizedInputNewEmailAddress}', 0, 0, '{$changeTokenOldAddress}', '{$changeTokenNewAddress}');",
'mailchange'
);
Settings\Utils\Queries\createEmailChangeProcessEntry([
'user' => &$_User,
'newEmailAddress' => $normalizedInputNewEmailAddress,
'changeTokenOldAddress' => $changeTokenOldAddress,
'changeTokenNewAddress' => $changeTokenNewAddress,
'currentTimestamp' => $ThisTime,
]);

$CheckMailChange = [ 'ID' => 1, 'Date' => $ThisTime, ];
$InfoMsgs[] = sprintf($_Lang['Mail_MailChange'], $_User['email']);
} else {
Expand Down

0 comments on commit a8d71ee

Please sign in to comment.