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

Commit

Permalink
fix(ui): do not display autologin shortcut when disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
adr-mo committed Apr 12, 2019
1 parent ff962bb commit af1b546
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
50 changes: 44 additions & 6 deletions www/api/class/centreon_topcounter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ public function putAutoLoginToken()
*/
public function getUser()
{
$enableAutoLogin = false;
$enableAutoLoginShortcut = false;
$autoLoginKey = null;

if (!isset($_SESSION['centreon'])) {
throw new \RestUnauthorizedException('Session does not exists.');
}
Expand All @@ -204,19 +208,53 @@ 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 ? */
$query = 'SELECT value FROM options WHERE options.key = "enable_autologin"';

try {
$res = $this->pearDB->query($query);
} catch (\Exception $e) {
throw new \RestInternalServerErrorException('Error getting the user.');
}

if ($res->rowCount() === 0) {
throw new \RestUnauthorizedException('User does not exists.');
if ($row = $res->fetch()) {
$enableAutoLogin = $row['value'] == '1' ? true : false;
}

/* Do we need to display the autologin shortcut ? */
$query = 'SELECT value FROM options WHERE options.key = "display_autologin_shortcut"';

try {
$res = $this->pearDB->query($query);
} catch (\Exception $e) {
throw new \RestInternalServerErrorException('Error getting the user.');
}

if ($row = $res->fetch()) {
$enableAutoLoginShortcut = $row['value'] == '1' ? true : false;
}

/* If the autologin feature is enabled then fetch the autologin key
* And display the shortcut if the option is enabled
*/
if ($enableAutoLogin && $enableAutoLoginShortcut) {
/* Get autologinkey */
$query = 'SELECT contact_autologin_key FROM contact WHERE contact_id = ' . (int)$user->user_id;

try {
$res = $this->pearDB->query($query);
} catch (\Exception $e) {
throw new \RestInternalServerErrorException('Error getting the user.');
}

if ($res->rowCount() === 0) {
throw new \RestUnauthorizedException('User does not exists.');
}

if ($row = $res->fetch()) {
$autoLoginKey = $row['contact_autologin_key'];
}
}
$row = $res->fetch();

return array(
'userId' => $user->user_id,
Expand All @@ -225,7 +263,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 @@ -120,7 +120,7 @@ class UserMenu extends Component {
</span>
</li>
{autologinkey &&
<React.Fragment>
<>
<button
className={'submenu-user-button'}
onClick={this.onCopy}
Expand All @@ -134,7 +134,7 @@ class UserMenu extends Component {
ref={node => this.autologinNode = node}
value={autolink}
/>
</React.Fragment>
</>
}
</ul>
<div class="button-wrap">
Expand Down

0 comments on commit af1b546

Please sign in to comment.