-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
GH-224 | Settings - Username change screen refactor
- Loading branch information
Showing
8 changed files
with
162 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
modules/settings/screens/UsernameChange/UsernameChange.screen.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Settings\Screens\UsernameChange; | ||
|
||
use UniEngine\Engine\Modules\Settings; | ||
use UniEngine\Engine\Modules\Settings\Screens\UsernameChange; | ||
|
||
/** | ||
* @param array $params | ||
* @param arrayRef $params['input'] | ||
* @param arrayRef $params['user'] | ||
*/ | ||
function render($props) { | ||
global $_Lang, $_SkinPath; | ||
|
||
$input = &$props['input']; | ||
$user = &$props['user']; | ||
|
||
$screenTitle = $_Lang['NickChange_Title']; | ||
|
||
$inputHandlingResult = UsernameChange\Utils\handleScreenInput([ | ||
'input' => &$input, | ||
'user' => &$user, | ||
]); | ||
|
||
if ($inputHandlingResult) { | ||
if (!$inputHandlingResult['isSuccess']) { | ||
$errorMessage = Settings\Utils\ErrorMappers\mapValidateUsernameChangeErrorToReadableMessage( | ||
$inputHandlingResult['error'] | ||
); | ||
|
||
return message($errorMessage, $screenTitle, 'settings.php?mode=nickchange'); | ||
} | ||
|
||
return message($_Lang['NewNick_saved'], $screenTitle, 'login.php'); | ||
} | ||
|
||
$localTemplateLoader = createLocalTemplateLoader(__DIR__); | ||
$tplBodyCache = [ | ||
'body' => $localTemplateLoader('body'), | ||
]; | ||
|
||
$userDarkEnergy = $user['darkEnergy']; | ||
$usernameChangeCost = Settings\Utils\Helpers\getUsernameChangeCost(); | ||
|
||
$_Lang['skinpath'] = $_SkinPath; | ||
$_Lang['DarkEnergy_Counter'] = $userDarkEnergy; | ||
if ($userDarkEnergy >= $usernameChangeCost) { | ||
$_Lang['DarkEnergy_Color'] = 'lime'; | ||
} else if ($userDarkEnergy > 0) { | ||
$_Lang['DarkEnergy_Color'] = 'orange'; | ||
} else { | ||
$_Lang['DarkEnergy_Color'] = 'red'; | ||
} | ||
|
||
$_Lang['NickChange_Info'] = parsetemplate( | ||
$_Lang['NickChange_Info'], | ||
[ | ||
'data_changeCost' => $usernameChangeCost, | ||
] | ||
); | ||
$_Lang['AreYouSure'] = parsetemplate( | ||
$_Lang['AreYouSure'], | ||
[ | ||
'data_changeCost' => $usernameChangeCost, | ||
] | ||
); | ||
|
||
$screenHTML = parsetemplate($tplBodyCache['body'], $_Lang); | ||
|
||
display($screenHTML, $screenTitle, false); | ||
} | ||
|
||
?> |
54 changes: 54 additions & 0 deletions
54
modules/settings/screens/UsernameChange/UsernameChange.utils.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Settings\Screens\UsernameChange\Utils; | ||
|
||
use UniEngine\Engine\Modules\Session; | ||
use UniEngine\Engine\Modules\Settings; | ||
|
||
/** | ||
* @param array $params | ||
* @param arrayRef $params['input'] | ||
* @param arrayRef $params['user'] | ||
*/ | ||
function handleScreenInput($params) { | ||
$input = &$params['input']; | ||
$user = &$params['user']; | ||
|
||
if (empty($input['newnick'])) { | ||
return; | ||
} | ||
|
||
$normalizedNewUsername = trim($input['newnick']); | ||
|
||
$usernameChangeValidationResult = Settings\Utils\Validators\validateUsernameChange([ | ||
'input' => [ | ||
'newUsername' => $normalizedNewUsername, | ||
], | ||
'currentUser' => &$user, | ||
]); | ||
|
||
if (!$usernameChangeValidationResult['isSuccess']) { | ||
return [ | ||
'isSuccess' => false, | ||
'error' => $usernameChangeValidationResult['error'], | ||
]; | ||
} | ||
|
||
Settings\Utils\Queries\updateUserOnUsernameChange([ | ||
'newUsername' => $normalizedNewUsername, | ||
'currentUser' => &$user, | ||
]); | ||
Settings\Utils\Queries\createUsernameChangeEntry([ | ||
'newUsername' => $normalizedNewUsername, | ||
'currentUser' => &$user, | ||
]); | ||
|
||
Session\Utils\Cookie\clearSessionCookie(); | ||
|
||
return [ | ||
'isSuccess' => true, | ||
'payload' => [], | ||
]; | ||
} | ||
|
||
?> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.php"); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters