fix: [UI] Terms and Conditions

pull/8349/head
Jakub Onderka 2022-05-07 11:43:14 +02:00
parent 1a6589270f
commit 5371623ad7
2 changed files with 36 additions and 31 deletions

View File

@ -1491,17 +1491,36 @@ class UsersController extends AppController
$this->Flash->success(__('You accepted the Terms and Conditions.'));
$this->redirect(array('action' => 'routeafterlogin'));
}
$termsFile = Configure::read('MISP.terms_file');
if (empty($termsFile)) {
throw new NotFoundException(__("MISP Terms and Conditions are not defined"));
}
$termsDownload = (bool)Configure::read('MISP.terms_download');
if (!$termsDownload) {
$termsFilePath = APP . 'files' . DS . 'terms' . DS . basename($termsFile);
try {
$termsContent = FileAccessTool::readFromFile($termsFilePath);
} catch (Exception $e) {
$termsContent = false;
}
$this->set("termsContent", $termsContent);
}
$this->set("termsDownload", $termsDownload);
$this->set('termsaccepted', $this->Auth->user('termsaccepted'));
}
public function downloadTerms()
{
if (!Configure::read('MISP.terms_file')) {
$termsFile = APP ."View/Users/terms";
} else {
$termsFile = APP . 'files' . DS . 'terms' . DS . Configure::read('MISP.terms_file');
$termsFile = Configure::read('MISP.terms_file');
if (empty($termsFile)) {
throw new NotFoundException(__("MISP Terms and Conditions are not defined"));
}
$this->response->file($termsFile, array('download' => true, 'name' => Configure::read('MISP.terms_file')));
$termsFilePath = APP . 'files' . DS . 'terms' . DS . basename($termsFile);
$this->response->file($termsFilePath, ['download' => true, 'name' => $termsFile]);
return $this->response;
}

View File

@ -1,35 +1,21 @@
<div class="users form">
<h2><?php echo __('MISP Terms and Conditions');?></h2>
<?php
$embedableExtensions = array('pdf');
if (!Configure::read('MISP.terms_file')) {
$termsFile = APP ."View/Users/terms";
} else {
$customTermsFile = basename(realpath(Configure::read('MISP.terms_file')));
$termsFile = APP . 'files' . DS . 'terms' . DS . $customTermsFile;
}
if (!(file_exists($termsFile))) {
echo "<p>" . __("Terms and Conditions file not found.") . "</p>";
} else {
if (!Configure::read('MISP.terms_download')) {
$terms = new File($termsFile, false);
echo $terms->read(true,'r');
$terms->close();
} else {
?>
<a href="<?php echo $baseurl;?>/users/downloadTerms" class="btn btn-inverse"><?php echo __('Download Terms and Conditions');?></a>
<?php
}
}
<?php if ($termsDownload): ?>
<a href="<?= $baseurl ?>/users/downloadTerms" class="btn btn-inverse"><?= __('Download Terms and Conditions');?></a>
<?php elseif (!$termsContent): ?>
<p><?= __("Terms and Conditions file not found.") ?></p>
<?php else: ?>
<?= $termsContent ?>
<?php endif; ?>
<?php
if (!$termsaccepted) {
echo "<br /><br />";
echo "<br><br>";
echo $this->Form->create('User');
echo $this->Form->hidden('termsaccepted', array('default' => '1'));
echo $this->Form->submit(__('Accept Terms'), array('class' => 'btn btn-primary'));
echo $this->Form->end();
}
?>
?>
</div>
<?php
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'globalActions', 'menuItem' => 'terms'));
?>
<?= $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'globalActions', 'menuItem' => 'terms'));