Refactor user session handling and permissions management

- Updated session variables to use 'authorization' array instead of 'username' for user identification across multiple files.
- Introduced a new function `getUserPermissions` to consolidate user permissions retrieval based on assigned roles.
- Modified API calls to use the new authorization structure and updated endpoints to v2.
- Enhanced language support by adding 'PL' to the list of supported languages.
- Cleaned up redundant code and improved session management during user login and registration processes.
- Added a new API endpoint for fetching user permissions based on user ID.
This commit is contained in:
“VeLiTi”
2026-01-19 15:29:16 +01:00
parent 782050c3ca
commit 24481279d5
99 changed files with 683 additions and 539 deletions

View File

@@ -15,30 +15,26 @@ if (session_status() == PHP_SESSION_NONE) {
//=========================================
//GET Language
//=========================================
if (isset($_GET['language']) && $_GET['language'] !=''){
//INCLUDE LANGUAGE FILE
$api_file_language = './settings/translations/translations_'.strtoupper($_GET['language']).'.php';
if (file_exists($api_file_language)){
include $api_file_language; //Include the code
//DEFINE LANGUAGE
$_SESSION['country_code'] = trim($_GET['language']);
}
else {
include './settings/translations/translations_US.php';
//DEFINE LANGUAGE
$_SESSION['country_code'] = 'US';
}
// Check for GET parameter override first
if (isset($_GET['language']) && $_GET['language'] != ''){
$lang = strtoupper(trim($_GET['language']));
$lang = in_array($lang, $supportedLanguages) ? $lang : 'US';
$_SESSION['country_code'] = $lang;
}
// Check for existing session language
elseif (isset($_SESSION['country_code'])){
$lang = strtoupper($_SESSION['country_code']);
$lang = in_array($lang, $supportedLanguages) ? $lang : 'US';
}
// Default to browser language
else {
$lang = strtoupper(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
$lang = in_array($lang, $supportedLanguages) ? $lang : 'US';
}
if(isset($_SESSION['country_code'])){
$api_file_language = './settings/translations/translations_'.strtoupper($_SESSION['country_code']).'.php';
if (file_exists($api_file_language)){
include $api_file_language; //Include the code
}
else {
include './settings/translations/translations_US.php';
}
}
//INCLUDE THE TRANSLATION
include_once './settings/translations/translations_'.$lang.'.php';
include_once './settings/countries.php';
//=========================================
//GET DOMAIN FOR CORRECT STYLING AND SETTINGS
//=========================================
@@ -77,12 +73,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Validate credentials
if (empty($username_err) && empty($password_err) && $retry < 3) {
$data = json_encode(array("username" => $username, "password" => $password), JSON_UNESCAPED_UNICODE);
//Secure data
$payload = generate_payload($data);
//API call
$responses = ioServer('/v1/authorization', $payload);
$responses = ioServer('/v2/authorization', $data);
//Decode Payload
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = '400';}
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = '400';}
if ($responses === 'NOK'){
$retry++;
@@ -93,21 +88,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Start a new session
session_start();
// Store data in sessions
// Store data in session
$_SESSION['loggedin'] = true;
$_SESSION['id'] = $responses->id;
$_SESSION['username'] = $responses->username;
$_SESSION['email'] = $responses->email;
$_SESSION['salesID'] = $responses->salesID;
$_SESSION['partnerhierarchy'] = $responses->partnerhierarchy; //clean;
$_SESSION['permission'] = $responses->permission;
$_SESSION['profile_name'] = $responses->profile_name;
$_SESSION['profile'] = $responses->profile;
$_SESSION['userkey'] = $responses->userkey;
$_SESSION['language'] = $responses->language;
$_SESSION['token'] = $responses->token;
$language_user = trim($responses->language) ?? 'US';
$_SESSION['authorization'] = $responses;
$language_user = trim($_SESSION['authorization']['language']) ?? 'US';
if($responses->profile == 'firmwaretool,products_software,application'){
header('location: index.php?page=firmwaretool');
exit();