Merge branch 'ent-13270-si-estoy-logueado-en-fenix-no-puedo-ver-enlace-publico-del-dashboard' into 'develop'

Ent 13270 si estoy logueado en fenix no puedo ver enlace publico del dashboard

See merge request artica/pandorafms!7299
This commit is contained in:
Matias Didier 2024-04-26 10:13:35 +00:00
commit c285af503f
3 changed files with 62 additions and 0 deletions

View File

@ -363,6 +363,27 @@ class Manager implements PublicLogin
}
/**
* Generates a hash to authenticate in public dashboards with user form url.
*
* @param string|null $other_secret To authenticate some parts
* of public dashboards (like visual consoles or wux widgets)
* another hash is needed. Other secret avoid
* to reuse the main hash to view other components.
*
* @return string Returns a hash with the authenticaction.
*/
public static function generatePublicHashUser(?string $other_secret='', $id_user=''):string
{
global $config;
$str = $config['dbpass'];
$str .= ($id_user ?? $config['id_user']);
$str .= $other_secret;
return hash('sha256', $str);
}
/**
* Validates a hash to authenticate in public dashboards.
*
@ -1040,6 +1061,17 @@ class Manager implements PublicLogin
break;
}
}
if (empty($this->dashboardId) === true) {
$id_user_url = get_parameter('id_user', $config['id_user']);
foreach ($dashboards as $key => $layout) {
$hash_compare = self::generatePublicHashUser($key, $id_user_url);
if (hash_equals($hash_aux, $hash_compare)) {
$this->dashboardId = $key;
break;
}
}
}
}
if ($this->dashboardId === 0

View File

@ -236,6 +236,25 @@ class User extends Entity implements PublicLogin
}
/**
* Generates a hash to authenticate in public views with user from url.
*
* @param string|null $other_secret If you need to authenticate using a
* varable string, use this 'other_secret' to customize the hash.
*
* @return string Returns a hash with the authenticaction.
*/
public static function generatePublicHashUser(?string $other_secret='', $id_user_url=''): string
{
global $config;
$str = $config['dbpass'];
$str .= ($id_user_url ?? $config['id_user']);
$str .= $other_secret;
return hash('sha256', $str);
}
/**
* Validates a hash to authenticate in public view.
*

View File

@ -79,6 +79,17 @@ foreach ($vcs as $key => $data) {
}
}
$id_user_url = get_parameter('id_user', $config['id_user']);
if (empty($visualConsoleId) === true) {
foreach ($vcs as $key => $data) {
$hash_compare = User::generatePublicHashUser($key, $id_user_url);
if (hash_equals($hash_compare, $hash)) {
$visualConsoleId = (int) $key;
break;
}
}
}
if (empty($visualConsoleId) === true) {
db_pandora_audit(
AUDIT_LOG_VISUAL_CONSOLE_MANAGEMENT,