diff --git a/www/api/class/centreon_topcounter.class.php b/www/api/class/centreon_topcounter.class.php
index 98bf38bbb54..3e6f9050145 100755
--- a/www/api/class/centreon_topcounter.class.php
+++ b/www/api/class/centreon_topcounter.class.php
@@ -194,9 +194,10 @@ public function getUser()
if (!isset($_SESSION['centreon'])) {
throw new \RestUnauthorizedException('Session does not exists.');
}
- $user = $_SESSION['centreon']->user;
+ $user = $_SESSION['centreon']->user;
$locale = $user->lang === 'browser' ? null : $user->lang;
+ $autoLoginKey = null;
if (isset($_SESSION['disable_sound'])) {
$this->soundNotificationsEnabled = !$_SESSION['disable_sound'];
@@ -204,19 +205,54 @@ public function getUser()
$this->soundNotificationsEnabled = true;
}
- /* Get autologinkey */
- $query = 'SELECT contact_autologin_key FROM contact WHERE contact_id = ' . (int)$user->user_id;
+ /* Is the autologin feature enabled ? */
+ try {
+ $res = $this->pearDB->query(
+ 'SELECT value FROM options WHERE options.key = "enable_autologin"'
+ );
+ } catch (\Exception $e) {
+ throw new \RestInternalServerErrorException('Error getting the user.');
+ }
+
+ $rowEnableShortcut = $res->fetch();
+ /* Do we need to display the autologin shortcut ? */
try {
- $res = $this->pearDB->query($query);
+ $res = $this->pearDB->query(
+ 'SELECT value FROM options WHERE options.key = "display_autologin_shortcut"'
+ );
} catch (\Exception $e) {
throw new \RestInternalServerErrorException('Error getting the user.');
}
- if ($res->rowCount() === 0) {
- throw new \RestUnauthorizedException('User does not exists.');
+ $rowEnableAutoLogin = $res->fetch();
+
+ /* If the autologin feature is enabled then fetch the autologin key
+ * And display the shortcut if the option is enabled
+ */
+ if (isset($rowEnableAutoLogin['value'])
+ && isset($rowEnableShortcut['value'])
+ && $rowEnableAutoLogin['value'] === '1'
+ && $rowEnableShortcut['value'] === '1'
+ ) {
+ /* Get autologinkey */
+ try {
+ $res = $this->pearDB->prepare(
+ 'SELECT contact_autologin_key FROM contact WHERE contact_id = :userId'
+ );
+ $res->bindValue(':userId', (int)$user->user_id, \PDO::PARAM_INT);
+ $res->execute();
+ } catch (\Exception $e) {
+ throw new \RestInternalServerErrorException('Error getting the user.');
+ }
+
+ if ($res->rowCount() === 0) {
+ throw new \RestUnauthorizedException('User does not exist.');
+ }
+
+ $row = $res->fetch();
+ $autoLoginKey = $row['contact_autologin_key'] ?? null;
}
- $row = $res->fetch();
return array(
'userId' => $user->user_id,
@@ -225,7 +261,7 @@ public function getUser()
'locale' => $locale,
'timezone' => $user->gmt,
'hasAccessToProfile' => $this->hasAccessToProfile,
- 'autologinkey' => $row['contact_autologin_key'],
+ 'autologinkey' => $autoLoginKey,
'soundNotificationsEnabled' => $this->soundNotificationsEnabled
);
}
diff --git a/www/front_src/src/components/userMenu/index.js b/www/front_src/src/components/userMenu/index.js
index 6df02092c8a..2c129bff3b5 100755
--- a/www/front_src/src/components/userMenu/index.js
+++ b/www/front_src/src/components/userMenu/index.js
@@ -122,7 +122,7 @@ class UserMenu extends Component {
{autologinkey &&
-