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

Commit 66b6656

Browse files
author
Dominik Frantisek Bucik
committed
fix: 🐛 Fixed PrivacyIDEA template
1 parent e86c260 commit 66b6656

File tree

3 files changed

+181
-346
lines changed

3 files changed

+181
-346
lines changed
Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
{
2-
"alternate_login_options": {
3-
"en": "Alternate login options",
4-
"cs": "Další možnosti přihlášení"
2+
"close": {
3+
"en": "Close",
4+
"cs": "Zavřít"
55
},
6-
"introduction_notice": {
7-
"en": "The service you are authenticating to requires MFA (Multi Factor Authentication). To complete the authentication, select one from the options below.",
8-
"cs": "Služba, ke které chcete přistoupit, vyžaduje vícefaktorovou autentizaci. Pro dokončení přihlášení zvolte jednu z možností níže."
6+
"info_text": {
7+
"en": "The service you are trying to access has requested authentication using multiple factors. Use one of your registered additional authentication token using the buttons below.",
8+
"cs": "Služba ke které přistupujete vyžádala vícefaktorovout autentizaci. Použijte jednu z vašich zaregistrovaných metod kliknutím na jedno z tlačítek nížě."
99
},
10-
"webauthn": {
11-
"en": "WebAuthn",
12-
"cs": "WebAuthn"
10+
"otp": {
11+
"en": "Security code",
12+
"cs": "Bezpečnostní kód"
1313
},
14-
"push": {
15-
"en": "Push",
16-
"cs": "Push"
14+
"otp_help": {
15+
"en": "Enter the 6 digit one time password from the smartphone application.",
16+
"cs": "Vložte jednorázový kód, například z TOTP aplikace."
1717
},
18-
"otp": {
19-
"en": "OTP",
20-
"cs": "OTP"
18+
"otp_submit_btn": {
19+
"en": "Submit",
20+
"cs": "Potvrdit"
21+
},
22+
"webauthn": {
23+
"en": "Web Authentication",
24+
"cs": "Web Authentication"
2125
},
22-
"u2f": {
23-
"en": "U2F",
24-
"cs": "U2F"
26+
"webauthn_btn": {
27+
"en": "Trigger authentication",
28+
"cs": "Spustit autentizaci"
2529
}
2630
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?php declare(strict_types=1);
2+
3+
use SimpleSAML\Module;
4+
5+
$this->data['u2fAvailable'] = !empty($this->data['u2fSignRequest']);
6+
$this->data['webauthnAvailable'] = !empty($this->data['webAuthnSignRequest']);
7+
$this->data['pushAvailable'] = $this->data['pushAvailable'] ?? false;
8+
9+
$this->data['mode'] = ($this->data['mode'] ?? null) ?: 'otp';
10+
$this->data['noAlternatives'] = true;
11+
foreach (['webauthn', 'otp', 'push', 'u2f'] as $mode) {
12+
if ($mode !== $this->data['mode'] && $this->data[$mode . 'Available']) {
13+
$this->data['noAlternatives'] = false;
14+
break;
15+
}
16+
}
17+
18+
// Set default scenario if isn't set
19+
if (!empty($this->data['authProcFilterScenario'])) {
20+
if (empty($this->data['username'])) {
21+
$this->data['username'] = '';
22+
}
23+
} else {
24+
$this->data['authProcFilterScenario'] = 0;
25+
}
26+
27+
// Set the right text shown in otp/pass field(s)
28+
$otpHint = $this->data['otpFieldHint'] ?? $this->t('{privacyidea:privacyidea:otp}');
29+
$passHint = $this->data['passFieldHint'] ?? $this->t('{privacyidea:privacyidea:password}');
30+
31+
$this->data['header'] = $this->t('{privacyidea:privacyidea:login_title_challenge}');
32+
33+
// Prepare next settings
34+
if (!empty($this->data['username'])) {
35+
$this->data['autofocus'] = 'password';
36+
} else {
37+
$this->data['autofocus'] = 'username';
38+
}
39+
40+
$this->data['head'] .= '<link rel="stylesheet" href="'
41+
. htmlspecialchars(Module::getModuleUrl('privacyidea/css/loginform.css'), ENT_QUOTES)
42+
. '" media="screen" />';
43+
44+
$this->includeAtTemplateBase('includes/header.php');
45+
46+
// Prepare error case to show it in UI if needed
47+
if (null !== $this->data['errorCode']) {
48+
?>
49+
<div class="alert alert-dismissable alert-danger" role="alert">
50+
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
51+
<span aria-hidden="true">&times;</span>
52+
</button>
53+
<h2 class="alert-heading"><?php echo $this->t('{login:error_header}'); ?></h2>
54+
<p>
55+
<?php
56+
echo htmlspecialchars(
57+
sprintf('%s%s: %s', $this->t(
58+
'{privacyidea:privacyidea:error}'
59+
), $this->data['errorCode'] ? (' ' . $this->data['errorCode']) : '', $this->data['errorMessage'])
60+
); ?>
61+
</p>
62+
</div>
63+
64+
<?php
65+
} // end of errorcode
66+
?>
67+
<p><?php echo $this->t('{perun:privacyidea:info_text}'); ?></p>
68+
<form action="FormReceiver.php" method="POST" id="piLoginForm" name="piLoginForm" class="loginForm">
69+
<div class="row">
70+
<?php if ($this->data['webauthnAvailable']) { ?>
71+
<div class="<?php echo (!$this->data['noAlternatives']) ? 'col-md-6' : 'col-sm-12'; ?>">
72+
<h2><?php echo $this->t('{perun:privacyidea:webauthn}'); ?></h2>
73+
<div>
74+
<button id="useWebAuthnButton" name="useWebAuthnButton" class="btn btn-primary btn-block text-nowrap" type="button"><?php echo $this->t('{perun:privacyidea:webauthn_btn}'); ?></button>
75+
</div>
76+
<div id="message" role="alert">
77+
<?php
78+
$messageOverride = $this->data['messageOverride'] ?? null;
79+
if (null === $messageOverride || is_string($messageOverride)) {
80+
echo htmlspecialchars($messageOverride ?? $this->data['message'] ?? '', ENT_QUOTES);
81+
} elseif (is_callable($messageOverride)) {
82+
echo call_user_func($messageOverride, $this->data['message'] ?? '');
83+
}
84+
?>
85+
</div>
86+
</div>
87+
<?php } ?>
88+
89+
<?php if ($this->data['otpAvailable'] ?? true) { ?>
90+
<div class="<?php echo (!$this->data['noAlternatives']) ? 'col-md-6' : 'col-sm-12'; ?>">
91+
<h2><?php echo $this->t('{privacyidea:privacyidea:otp}'); ?></h2>
92+
<p><?php echo $this->t('{perun:privacyidea:otp_help}'); ?></p>
93+
<div class="form-row">
94+
<div class="form-group col-sm-12 <?php echo (!$this->data['noAlternatives']) ? '' : 'col-md-6'; ?>">
95+
<label for="otp" class="sr-only"><?php echo $this->t('{perun:privacyidea:otp}'); ?></label>
96+
<input id="otp" name="otp" tabindex="1" value="" class="form-control" autocomplete="one-time-code" type="text" inputmode="numeric" pattern="[0-9]{6,}" required placeholder="<?php echo htmlspecialchars($otpHint, ENT_QUOTES); ?>"/>
97+
</div>
98+
<div class="form-group col-sm-12 <?php echo (!$this->data['noAlternatives']) ? '' : 'col-md-6'; ?>">
99+
<button id="submitButton" tabindex="1" class="btn btn-primary btn-block text-nowrap" type="submit" name="Submit"><?php echo htmlspecialchars($this->t('{perun:privacyidea:otp_submit_btn}'), ENT_QUOTES); ?></button>
100+
</div>
101+
</div>
102+
</div>
103+
<?php } ?>
104+
</div>
105+
106+
<!-- Undefined index is suppressed and the default is used for these values -->
107+
<input id="mode" type="hidden" name="mode" value="otp" data-preferred="<?php echo htmlspecialchars($this->data['mode'], ENT_QUOTES); ?>"/>
108+
<input id="pushAvailable" type="hidden" name="pushAvailable" value="<?php echo ($this->data['pushAvailable'] ?? false) ? 'true' : ''; ?>"/>
109+
<input id="otpAvailable" type="hidden" name="otpAvailable" value="<?php echo ($this->data['otpAvailable'] ?? true) ? 'true' : ''; ?>"/>
110+
<input id="webAuthnSignRequest" type="hidden" name="webAuthnSignRequest" value='<?php echo htmlspecialchars($this->data['webAuthnSignRequest'] ?? '', ENT_QUOTES); ?>'/>
111+
<input id="u2fSignRequest" type="hidden" name="u2fSignRequest" value='<?php echo htmlspecialchars($this->data['u2fSignRequest'] ?? '', ENT_QUOTES); ?>'/>
112+
<input id="modeChanged" type="hidden" name="modeChanged" value=""/>
113+
<input id="step" type="hidden" name="step" value="<?php echo htmlspecialchars(strval(($this->data['step'] ?? null) ?: 2), ENT_QUOTES); ?>"/>
114+
<input id="webAuthnSignResponse" type="hidden" name="webAuthnSignResponse" value=""/>
115+
<input id="u2fSignResponse" type="hidden" name="u2fSignResponse" value=""/>
116+
<input id="origin" type="hidden" name="origin" value=""/>
117+
<input id="loadCounter" type="hidden" name="loadCounter" value="<?php echo htmlspecialchars(strval(($this->data['loadCounter'] ?? null) ?: 1), ENT_QUOTES); ?>"/>
118+
119+
<!-- Additional input to persist the message -->
120+
<input type="hidden" name="message" value="<?php echo htmlspecialchars($this->data['message'] ?? '', ENT_QUOTES); ?>"/>
121+
</form>
122+
<script src="<?php echo htmlspecialchars(Module::getModuleUrl('privacyidea/js/pi-webauthn.js'), ENT_QUOTES); ?>">
123+
</script>
124+
125+
<script src="<?php echo htmlspecialchars(Module::getModuleUrl('privacyidea/js/u2f-api.js'), ENT_QUOTES); ?>">
126+
</script>
127+
128+
<meta id="privacyidea-step" name="privacyidea-step" content="<?php echo $this->data['step']; ?>">
129+
130+
<meta id="privacyidea-translations" name="privacyidea-translations" content="<?php
131+
$translations = [];
132+
$translation_keys = [
133+
'webauthn_insecure_context',
134+
'webauthn_library_unavailable',
135+
'webauthn_AbortError',
136+
'webauthn_InvalidStateError',
137+
'webauthn_NotAllowedError',
138+
'webauthn_NotSupportedError',
139+
'webauthn_TypeError',
140+
'webauthn_other_error',
141+
'webauthn_in_progress',
142+
'webauthn_success',
143+
'u2f_insecure_context',
144+
'u2f_unavailable',
145+
'u2f_sign_request_error',
146+
'try_again',
147+
];
148+
foreach ($translation_keys as $translation_key) {
149+
$translations[$translation_key] = $this->t(sprintf('{privacyidea:privacyidea:%s}', $translation_key));
150+
}
151+
echo htmlspecialchars(json_encode($translations));
152+
?>">
153+
154+
<script src="<?php echo htmlspecialchars(Module::getModuleUrl('privacyidea/js/loginform.js'), ENT_QUOTES); ?>"></script>
155+
<script src="<?php echo htmlspecialchars(Module::getModuleUrl('perun/js/privacy-idea-loginform.js'), ENT_QUOTES); ?>"></script>
156+
157+
<?php
158+
$this->includeAtTemplateBase('includes/footer.php');
159+
?>

0 commit comments

Comments
 (0)