Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

fix(ui): do not display autologin shortcut when disabled #7340

Merged
merged 4 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions www/api/class/centreon_topcounter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,29 +194,65 @@ 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'];
} else {
$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'
);
adr-mo marked this conversation as resolved.
Show resolved Hide resolved
$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,
Expand All @@ -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
);
}
Expand Down
4 changes: 2 additions & 2 deletions www/front_src/src/components/userMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class UserMenu extends Component {
</span>
</li>
{autologinkey &&
<React.Fragment>
<>
<button
className={'submenu-user-button'}
onClick={this.onCopy}
Expand All @@ -136,7 +136,7 @@ class UserMenu extends Component {
ref={node => this.autologinNode = node}
value={autolink}
/>
</React.Fragment>
</>
}
</ul>
<div class="button-wrap">
Expand Down