Skip to content

Commit

Permalink
GH-224 Move user updater to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jun 18, 2022
1 parent 783a0c6 commit b0899bc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions modules/settings/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
include($includePath . './utils/queries/getMovingFleetsCount.query.php');
include($includePath . './utils/queries/getUserIgnoreEntries.query.php');
include($includePath . './utils/queries/getUserWithEmailAddress.query.php');
include($includePath . './utils/queries/updateUserOnUsernameChange.query.php');

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

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

/**
* @param array $params
* @param string $params['newUsername']
* @param arrayRef $params['currentUser']
*/
function updateUserOnUsernameChange($params) {
$newUsername = $params['newUsername'];
$currentUser = &$params['currentUser'];

$CHANGE_COST = 10;

$query = (
"UPDATE {{table}} " .
"SET " .
"`darkEnergy` = `darkEnergy` - {$CHANGE_COST}, " .
"`username` = '{$newUsername}', " .
"`old_username` = '{$currentUser['username']}', " .
"`old_username_expire` = UNIX_TIMESTAMP() + (7 * 24 * 60 * 60) " .
"WHERE " .
"`id` = {$currentUser['id']} " .
"LIMIT 1 " .
"; -- UniEngine\Engine\Modules\Settings\Utils\Queries\updateUserOnUsernameChange"
);

doquery($query, 'users');
}

?>
6 changes: 4 additions & 2 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1195,8 +1195,10 @@

message($errorMessage, $_Lang['NickChange_Title'], 'settings.php?mode=nickchange');
} else {
doquery("UPDATE {{table}} SET `darkEnergy` = `darkEnergy` - 10, `username` = '{$NewNick}', `old_username` = '{$_User['username']}', `old_username_expire` = UNIX_TIMESTAMP() + (7*24*60*60) WHERE `id` = {$_User['id']} LIMIT 1;", 'users');

Settings\Utils\Queries\updateUserOnUsernameChange([
'newUsername' => $NewNick,
'currentUser' => &$_User,
]);
Settings\Utils\Queries\createUsernameChangeEntry([
'newUsername' => $NewNick,
'currentUser' => &$_User,
Expand Down

0 comments on commit b0899bc

Please sign in to comment.