Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 2de99ee

Browse files
author
Dominik František Bučík
authored
Added possibility to specify custom texts for warning_test_sp (#147)
* Added possibility to specify custom texts for warning_test_sp * Split inline translation into header and text
1 parent 66ae43f commit 2de99ee

File tree

6 files changed

+94
-6
lines changed

6 files changed

+94
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
5+
#### Added
6+
- Added possibility to add custom texts to the TEST_SP warning page.
7+
58
#### Fixed
69
- Fixed bad check in NagiosStatusConnector.php
710

config-templates/module_perun.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,15 @@
272272
],
273273
],
274274
],
275+
276+
'warning_test_sp_config' => [
277+
'header' => [
278+
'en' => '<h3>Warning - service in test environment</h3>',
279+
'cs' => '<h3>Varování - testovací služba</h3>'
280+
],
281+
'text' => [
282+
'en' => '<p>Service is in the test environment.<br class="spacer"/>Hit the continue button.</p>',
283+
'cs' => '<p>Služba je v testovacím režimu.<br class="spacer"/>Pokračujte zmáčknutím tlačítka.</p>',
284+
],
285+
],
275286
];

lib/Auth/Process/WarningTestSP.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SimpleSAML\Module\perun\Auth\Process;
44

5+
use SimpleSAML\Auth\ProcessingFilter;
56
use SimpleSAML\Auth\State;
67
use SimpleSAML\Module;
78
use SimpleSAML\Utils\HTTP;
@@ -11,8 +12,18 @@
1112
*
1213
* Warns user that he/she is accessing to the testing SP
1314
*/
14-
class WarningTestSP extends \SimpleSAML\Auth\ProcessingFilter
15+
class WarningTestSP extends ProcessingFilter
1516
{
17+
public const CONFIG_FILE_NAME = "module_perun.php";
18+
19+
public const TEST_SP_CONFIG = "warning_test_sp_config";
20+
public const TEST_SP_CONFIG_TEXT = "text";
21+
public const TEST_SP_CONFIG_HEADER = "header";
22+
23+
public const CUSTOM_HEADER_ENABLED = "custom_header_enabled";
24+
public const CUSTOM_TEXT_ENABLED = "custom_text_enabled";
25+
public const CUSTOM_HEADER_KEY = "{perun:warning_test_sp:custom_header}";
26+
public const CUSTOM_TEXT_KEY = "{perun:warning_test_sp:custom_text}";
1627

1728
public function __construct($config, $reserved)
1829
{

templates/warning-test-sp-tpl.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,32 @@
1010
* @var Template $this
1111
*/
1212

13+
$this->data['head'] = '<link rel="stylesheet" media="screen" type="text/css" href="' .
14+
Module::getModuleUrl('perun/res/css/warning_test_sp.css') . '" />';
15+
1316
$this->data['header'] = '';
1417

1518
$this->includeAtTemplateBase('includes/header.php');
16-
19+
$customHeaderEnabled = isset($this->data[Module\perun\Auth\Process\WarningTestSP::CUSTOM_HEADER_ENABLED])
20+
&& $this->data[Module\perun\Auth\Process\WarningTestSP::CUSTOM_HEADER_ENABLED];
21+
$customTextEnabled = isset($this->data[Module\perun\Auth\Process\WarningTestSP::CUSTOM_TEXT_ENABLED])
22+
&& $this->data[Module\perun\Auth\Process\WarningTestSP::CUSTOM_TEXT_ENABLED];
1723
?>
1824

1925
<form method="post" action="<?php echo Module::getModuleURL('perun/warning_test_sp_continue.php'); ?>">
2026

2127
<input type="hidden" name="StateId" value="<?php echo $_REQUEST['StateId'] ?>">
22-
<h3> <?php echo $this->t('{perun:perun:warning-test-sp-tpl_text}') ?> </h3>
23-
</hr>
24-
</br>
25-
28+
<h3><?php echo $customTextEnabled ?
29+
$this->t(Module\perun\Auth\Process\WarningTestSP::CUSTOM_HEADER_KEY) :
30+
$this->t('{perun:perun:warning-test-sp-tpl_text}')
31+
?>
32+
</h3>
33+
<?php
34+
if ($customTextEnabled) {
35+
echo '<div>' . $this->t(Module\perun\Auth\Process\WarningTestSP::CUSTOM_TEXT_KEY) . '</div>' . PHP_EOL;
36+
}
37+
?>
38+
<br/>
2639
<div class="form-group">
2740
<input type="submit" value="<?php echo $this->t('{perun:perun:continue}') ?>"
2841
class="btn btn-lg btn-primary btn-block">

www/res/css/warning_test_sp.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
html {
2+
position: relative;
3+
min-height: 100%;
4+
}
5+
6+
.spacer {
7+
margin-bottom: 3%;
8+
}
9+
10+
#wrap {
11+
padding: 3% 1% 1%;
12+
margin-top: 3%;
13+
margin-bottom: 110px;
14+
}
15+
16+
#footer {
17+
position: absolute;
18+
bottom: 0;
19+
left: 0;
20+
right: 0;
21+
height: 100px;
22+
}

www/warning_test_sp_page.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
use SimpleSAML\Auth\State;
44
use SimpleSAML\Configuration;
5+
use SimpleSAML\Logger;
6+
use SimpleSAML\Module\perun\Auth\Process\WarningTestSP;
57
use SimpleSAML\XHTML\Template;
68

79
$id = $_REQUEST['StateId'];
@@ -10,4 +12,30 @@
1012
$config = Configuration::getInstance();
1113

1214
$t = new Template($config, 'perun:warning-test-sp-tpl.php');
15+
$t->data[WarningTestSP::CUSTOM_TEXT_ENABLED] = false;
16+
17+
18+
$perunModuleConfig = null;
19+
try {
20+
$perunModuleConfig = Configuration::getConfig(WarningTestSP::CONFIG_FILE_NAME);
21+
} catch (\Exception $ex) {
22+
Logger::warning("perun:warning_test_sp_page: missing or invalid '" .
23+
WarningTestSP::CONFIG_FILE_NAME . "' config file");
24+
}
25+
if ($perunModuleConfig != null) {
26+
$testSpWarningConfig = $perunModuleConfig->getConfigItem(WarningTestSP::TEST_SP_CONFIG, null);
27+
if ($testSpWarningConfig != null) {
28+
$header = $testSpWarningConfig->getArray(WarningTestSP::TEST_SP_CONFIG_HEADER, []);
29+
if (!empty($header)) {
30+
$t->includeInlineTranslation(WarningTestSP::CUSTOM_HEADER_KEY, $header);
31+
$t->data[WarningTestSP::CUSTOM_HEADER_ENABLED] = true;
32+
}
33+
$text = $testSpWarningConfig->getArray(WarningTestSP::TEST_SP_CONFIG_TEXT, []);
34+
if (!empty($text)) {
35+
$t->includeInlineTranslation(WarningTestSP::CUSTOM_TEXT_KEY, $text);
36+
$t->data[WarningTestSP::CUSTOM_TEXT_ENABLED] = true;
37+
}
38+
}
39+
}
40+
1341
$t->show();

0 commit comments

Comments
 (0)