-
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.
GH-224 Move username change screen code to Screen
- Loading branch information
Showing
7 changed files
with
139 additions
and
66 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
73 changes: 73 additions & 0 deletions
73
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,73 @@ | ||
<?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']; | ||
|
||
$_Lang['skinpath'] = $_SkinPath; | ||
$_Lang['DarkEnergy_Counter'] = $userDarkEnergy; | ||
if ($userDarkEnergy >= 15) { | ||
$_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' => Settings\Utils\Helpers\getUsernameChangeCost(), | ||
] | ||
); | ||
$_Lang['AreYouSure'] = parsetemplate( | ||
$_Lang['AreYouSure'], | ||
[ | ||
'data_changeCost' => Settings\Utils\Helpers\getUsernameChangeCost(), | ||
] | ||
); | ||
|
||
$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