Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Finish Add snippets support for the classes #18
-> Fixed Settings
-> Edit User Finished
  • Loading branch information
NaysKutzu committed Nov 5, 2024
1 parent 31575a6 commit a61fc0f
Show file tree
Hide file tree
Showing 19 changed files with 595 additions and 61 deletions.
20 changes: 18 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
"cSpell.words": [
"acaches",
"aindex",
"akram",
"apikeys",
"asuccessful",
"asuccessfully",
"autoload",
"autoloader",
"Bcmath",
"Bethropolis",
"bradlc",
"Cassian",
"ccaches",
"chuaple",
"configpath",
"cronfile",
"dbconfigure",
"devsense",
"doesinfoexist",
"ealready",
"eamodio",
"ERRMODE",
"firstname",
"fklmnor",
Expand All @@ -25,12 +30,16 @@
"gravatarphp",
"Ifsnop",
"Inno",
"intelli",
"jsyaml",
"kosmapanel",
"Kutzu",
"Lastname",
"linyang",
"lkrms",
"mailserver",
"mbstring",
"mohd",
"myprofile",
"Mysqldump",
"mythicalclient",
Expand All @@ -40,17 +49,22 @@
"mythicalsystems",
"Nahh",
"nayskutzu",
"oderwat",
"ontry",
"Outedated",
"phpdocs",
"phpmailer",
"phprouter",
"phptools",
"phpunit",
"posible",
"Repobeats",
"rfiles",
"rifi",
"sitesecret",
"skey",
"skiptwofactorcheck",
"sophisticode",
"Swal",
"tailwindcss",
"twofauser",
Expand All @@ -64,13 +78,15 @@
"unverification",
"unverify",
"useractivity",
"userids"
"userids",
"xdebug",
"zarifprogrammer",
"zobo"
],
"cSpell.useGitignore": true,
"cSpell.ignorePaths": [
"/storage/settings.json",
"/composer.lock",

],
"window.title": "${appName}",
"window.autoDetectColorScheme": true,
Expand Down
107 changes: 107 additions & 0 deletions .vscode/vscode.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,94 @@
],
"description": "Get a specific value from the language file!"
},
"Get translation PHP": {
"prefix": "S_GetLang",
"scope": "php",
"body": [
"\\MythicalSystemsFramework\\Language\\Manager::getInstance()->get('$1')"
],
"description": "Get a specific value from the language file!"
},
"Decrypt": {
"prefix": "S_Decrypt",
"scope": "php",
"body": [
"\\MythicalSystemsFramework\\Encryption\\XChaCha20::decrypt('$1')"
],
"description": "Decrypt a string!"
},
"Encrypt": {
"prefix": "S_Encrypt",
"scope": "php",
"body": [
"\\MythicalSystemsFramework\\Encryption\\XChaCha20::encrypt('$1')"
],
"description": "Encrypt a string!"
},
"Get User IP": {
"prefix": "S_GetUserIP",
"scope": "php",
"body": [
"\\MythicalSystemsFramework\\CloudFlare\\CloudFlare::getUserIP()"
],
"description": "Get the user's IP address!"
},
"Debug Display Value Info": {
"prefix": "S_DebugDisplayValueInfo",
"scope": "php",
"body": [
"Debugger::display_info($1,false);"
],
"description": "Display the value info!"
},
"Debug Show All Errors": {
"prefix": "S_DebugShowAllErrors",
"scope": "php",
"body": [
"Debugger::ShowAllErrors();"
],
"description": "Show all errors!"
},
"Debug Hide All Errors": {
"prefix": "S_DebugHideAllErrors",
"scope": "php",
"body": [
"Debugger::HideAllErrors();"
],
"description": "Hide all errors!"
},
"Does role have permission": {
"prefix": "S_DoesRoleHavePermission",
"scope": "php",
"body": [
"RolesPermissionDataHandler::doesRoleHavePermission('$1','$2')"
],
"description": "Check if a role has a permission!"
},
"Add new activity": {
"prefix": "S_AddNewActivity",
"scope": "php",
"body": [
"\\MythicalSystemsFramework\\User\\Activity\\UserActivity::addActivity(\\MythicalSystemsFramework\\User\\UserDataHandler::getUUIDFromToken(\\$_COOKIE['token']),'$1',\\MythicalSystemsFramework\\CloudFlare\\CloudFlare::getUserIP(),'$2');"
],
"description": "Add a new activity!"
},
"Update specific user data": {
"prefix": "S_UpdateSpecificUserData",
"scope": "php",
"body": [
"\\MythicalSystemsFramework\\User\\UserDataHandler::updateSpecificUserData(\\$_COOKIE['token'], '$1', '$2',$3);"
],
"description": "Update specific user data!"
},
"Get specific user data": {
"prefix": "S_GetSpecificUserData",
"scope": "php",
"body": [
"\\MythicalSystemsFramework\\User\\UserDataHandler::getSpecificUserData(\\$_COOKIE['token'], '$1',$2);"
],
"description": "Get specific user data!"
},
"Get setting": {
"prefix": "S_GetSetting",
"scope": "twig",
Expand Down Expand Up @@ -167,5 +255,24 @@
"body": [
"{{ user('$1',false) }}"
],
},
"S_PageTemplate": {
"prefix": "S_PageTemplate",
"scope": "twig",
"body": [
"{% extends 'components/dashboard.twig' %}",
"{% block head %}",
"<!-- Head content goes here -->",
"$1",
"{% endblock %}",
"{% block dashboard %}",
"<!-- Dashboard content goes here -->",
"$2",
"{% endblock %}",
"{% block footer %}",
"<!-- Footer content goes here -->",
"$3",
"{% endblock %}",
],
}
}
4 changes: 1 addition & 3 deletions app/CloudFlare/CloudFlare.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ public static function getUserIP(): ?string
// Check if the ip is valid
if (filter_var($ip, FILTER_VALIDATE_IP)) {
$event->emit('cloudflare.onGetUserIP', [$ip]);

return $ip;
}

return null;

}


/**
* DEPRECATED: Use getUserIP() instead.
*/
Expand Down
1 change: 0 additions & 1 deletion app/Kernel/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public static function display_info($input, $collapse = false): void
echo 'document.getElementById("plus"+id).style.display = state == "inline" ? "inline" : "none";';
echo '}</script>' . "\n";
}

$type = !is_string($data) && is_callable($data) ? 'Callable' : ucfirst(gettype($data));
$type_data = null;
$type_color = null;
Expand Down
15 changes: 14 additions & 1 deletion app/Language/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ class Manager
public string $default_lang = 'en_US';
public string $language;

private Manager $instance;

public function __construct()
{
$this->instance = $this;

if (!$this->doesLanguageDirectoryExist()) {
$this->createLanguageDirectory();
}

$this->renameYAMLToYML();
$this->langs = $this->getLangs();
foreach ($this->langs as $lang) {
Expand Down Expand Up @@ -215,7 +220,7 @@ private function renameYAMLToYML(): void
}
}
}

/**
* Check if the language directory exists.
*/
Expand All @@ -231,4 +236,12 @@ private function createLanguageDirectory(): void
{
mkdir($this->lang_dir);
}
/**
* Get the instance of the language manager.
*
* @return \MythicalSystemsFramework\Language\Manager
*/
public static function getInstance(): Manager {
return self::$instance;
}
}
2 changes: 0 additions & 2 deletions app/User/Activity/UserActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class UserActivity
public static function addActivity(string $userId, string $description, string $ipv4, string $action): void
{
global $event; // This is a global variable that is used to emit events.

try {

$mysqli = new MySQL();
$conn = $mysqli->connectMYSQLI();
$stmt = $conn->prepare('INSERT INTO framework_users_activities (user_id, description, action, ip_address) VALUES (?, ?, ?, ?)');
Expand Down
24 changes: 24 additions & 0 deletions app/User/UserDataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,4 +616,28 @@ public static function doesUUIDExist(string $uuid): bool
return false;
}
}
/**
* Get the uuid by token.
*
* @param string $token The user token
*
* @return string The uuid
*/
public static function getUUIDFromToken(string $token): string
{
try {
$database = new MySQL();
$mysqli = $database->connectMYSQLI();
$stmt = $mysqli->prepare('SELECT uuid FROM framework_users WHERE token = ?');
$stmt->bind_param('s', $token);
$stmt->execute();
$stmt->bind_result($uuid);
$stmt->fetch();
$stmt->close();
return $uuid;
} catch (\Exception $e) {
logger::log(LoggerLevels::CRITICAL, LoggerTypes::DATABASE, '(App/User/UserDataHandler.php) Failed to get UUID from token: ' . $e->getMessage());
return '';
}
}
}
51 changes: 51 additions & 0 deletions app/Web/Routes/admin/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
return UserDataHandler::getSpecificUserData($userToken, $info, $encrypted);
}));


$activity = UserActivity::getActivities($uuid);
$itemCount = count($activity);
$renderer->addGlobal('activity_count', NumberFormatter::format($itemCount));
Expand All @@ -95,6 +96,56 @@
}
});

$router->add('/admin/users/(.*)/update', function (string $uuid): void {
global $router, $event, $renderer;

if (!isset($_GET['info'], $_GET['value'], $_GET['encrypted'])) {
exit(header('location: /admin/users?e=missing_values'));
}

if (empty($_GET['info']) || empty($_GET['value']) || empty($_GET['encrypted'])) {
exit(header('location: /admin/users?e=invalid_input'));
}

$info = $_GET['info'];
$value = $_GET['value'];
$encrypted = filter_var($_GET['encrypted'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

$template = 'admin/users/edit.twig';
if (isset($_COOKIE['token']) === false) {
exit(header('location: /auth/login'));
}

$user = new UserHelper($_COOKIE['token'], $renderer);
UserDataHandler::requireAuthorization($renderer, $_COOKIE['token']);

if (
!UserDataHandler::hasPermission($_COOKIE['token'], 'mythicalframework.admin.users.edit')
) {
exit(header('location: /errors/403'));
}

if ($uuid == '') {
exit(header('location: /admin/users'));
}
if (UserDataHandler::doesUUIDExist($uuid) === false) {
exit(header('location: /admin/users?e=not_found'));
}
$userToken = UserDataHandler::getTokenUUID($uuid);
if ($userToken === null) {
exit(header('location: /admin/users?e=not_found'));
}

$renderer->addFunction(new TwigFunction('other_info', function ($info, $encrypted) use ($userToken) {
return UserDataHandler::getSpecificUserData($userToken, $info, $encrypted);
}));

UserDataHandler::updateSpecificUserData($userToken, $info, $value, $encrypted);
\MythicalSystemsFramework\Api\Api::init();
MythicalSystemsFramework\Api\Api::OK("User data updated successfully",null);

});

$router->add('/admin/users', function (): void {
global $router, $event, $renderer;
$template = 'admin/users/list.twig';
Expand Down
Loading

0 comments on commit a61fc0f

Please sign in to comment.