Skip to content

Commit 555bb84

Browse files
ioigoumenikosev
authored andcommitted
Add attrauthcomanage noty template
Add noty.definition.json Add noty.tpl.php file Refactor attrauthcomanage noty template
1 parent 3f7f285 commit 555bb84

3 files changed

Lines changed: 305 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This version is compatible with [SimpleSAMLphp v1.18](https://simplesamlphp.org/
1919
- Add comanage loader
2020
- Add support to configure loader
2121
- Add view.php modal
22+
- Add attrauthcomanage noty template
2223

2324
### Fixed
2425

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"yes": {
3+
"en": "Resend Verification Email"
4+
},
5+
"no": {
6+
"en": "Abort Login"
7+
},
8+
"title": {
9+
"en": "Please verify your email address by clicking the link in the email we sent you"
10+
},
11+
"msg_title": {
12+
"en": "<b>This is your current status:</b>"
13+
},
14+
"default_status": {
15+
"en": "Action Required"
16+
},
17+
"account_pending_confirmation": {
18+
"en": "Account in Pending Email Confirmation Status"
19+
},
20+
"invitation_restored": {
21+
"en": "Invitation has been restored."
22+
},
23+
"petition_info": {
24+
"en": "The identifier <cite><b>%ORGIDENT%</b></cite> is in Email Pending Confirmation Status.&nbsp;Please check your Mail <cite><b>%MAIL%</b></cite> Inbox or Spam for further information.&nbsp;"
25+
},
26+
"petition_user_notify": {
27+
"en": "<p class=\"petition-user-notify\">We have sent an email with a confirmation link to your email address <cite><b>%MAIL%</b></cite>. In order to complete the sign-up process, please click the confirmation link. If you do not find the email in your Inbox, please check your Spam or Junk folder for an email from \"RCIAM Notifications\". If you do find the email in these folders, mark the email as \"safe\" or \"not spam\" to ensure that you receive any future notifications about your RCIAM ID.</p><p>You can also click the <strong>\"Resend Verification Email\"</strong> button below to have another email sent to you."
28+
},
29+
"petition_token_expired": {
30+
"en": "<div class=\"invite-expire\">Email confirmation token EXPIRED <b>&nbsp;%DATE%</b>&nbsp;ago</div>"
31+
},
32+
"petition_token_expires": {
33+
"en": "<div class=\"invite-expire\">Email confirmation token EXPIRES in <b>&nbsp;%DATE%</b></div>"
34+
},
35+
"petition_invalidate_msg": {
36+
"en": "<p><i class=\"fa fa-exclamation-triangle\" aria-hidden=\"true\"></i>This action will invalidate any previous confirmation links.</p>"
37+
}
38+
}
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
<?php
2+
3+
/**
4+
* Override noty.tpl.php template from attrauthcomanage ssp module
5+
*
6+
* @author: ioigoume@admin.grnet.gr
7+
*/
8+
9+
use SimpleSAML\Configuration;
10+
11+
assert('is_array($this->data["dstMetadata"])');
12+
// Where should i go on YES click
13+
assert('is_string($this->data["yesTarget"])');
14+
// YES Form input entries
15+
assert('is_array($this->data["yesData"])');
16+
// Abort needed variables
17+
assert('is_string($this->data["logoutLink"])');
18+
assert('is_array($this->data["logoutData"])');
19+
// Service Privacy Policy
20+
assert('$this->data["sppp"] === false || is_string($this->data["sppp"])');
21+
22+
if (array_key_exists('name', $this->data['dstMetadata'])) {
23+
$dstName = $this->data['dstMetadata']['name'];
24+
} elseif (array_key_exists('OrganizationDisplayName', $this->data['dstMetadata'])) {
25+
$dstName = $this->data['dstMetadata']['OrganizationDisplayName'];
26+
} else {
27+
$dstName = $this->data['dstMetadata']['entityid'];
28+
}
29+
30+
if (is_array($dstName)) {
31+
$dstName = $this->t($dstName);
32+
}
33+
34+
// XXX Parse Parameters
35+
$notyLevel = !empty($this->data['noty']['level']) ? $this->data['noty']['level'] : null;
36+
$notyDescription = !empty($this->data['noty']['description']) ? $this->data['noty']['description'] : [];
37+
$notyStatus = (!empty($this->data['noty']['status']) && is_string($this->data['noty']['status']))
38+
? $this->t('{themevanilla:attrauthcomanage_noty:' . $this->data['noty']['status'] . '}')
39+
: null;
40+
$yesButtonLabel = (!empty($this->data['noty']['ok_btn_label']) && is_string($this->data['noty']['ok_btn_label']))
41+
? $this->data['noty']['ok_btn_label']
42+
: $this->t('{themevanilla:attrauthcomanage_noty:yes}');
43+
$yesButtonShow = true;
44+
if (
45+
isset($this->data['noty']['yes_btn_show'])
46+
&& !is_null($this->data['noty']['yes_btn_show'])
47+
&& is_bool($this->data['noty']['yes_btn_show'])
48+
) {
49+
$yesButtonShow = $this->data['noty']['yes_btn_show'];
50+
}
51+
52+
// XXX Get Configuration and set the loader
53+
$globalConfig = Configuration::getInstance();
54+
$themeUse = $globalConfig->getString('theme.use', 'default');
55+
if ($themeUse !== 'default') {
56+
$themeConfigFile = 'module_' . explode(':', $themeUse)[0] . '.php';
57+
$themeConfig = Configuration::getConfig($themeConfigFile);
58+
$loader = $themeConfig->getValue('loader');
59+
if (!empty($loader)) {
60+
$this->includeAtTemplateBase('includes/' . $loader . '.php');
61+
}
62+
}
63+
64+
// XXX Set JS/CSS Dependencies
65+
$this->data['jquery'] = ['core' => true, 'ui' => false, 'css' => false];
66+
$this->data['head'] = '<link rel="stylesheet" '
67+
. 'href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">' . PHP_EOL
68+
. '<link rel="stylesheet" type="text/css" href="/' . $this->data['baseurlpath']
69+
. 'module.php/attrauthcomanage/resources/css/style.css" />' . PHP_EOL;
70+
71+
// XXX Include Header
72+
$this->includeAtTemplateBase('includes/header.php');
73+
74+
?>
75+
<p>
76+
<h3 id="attributeheader">
77+
<?php if (!empty($this->data['noty']['icon'])) : ?>
78+
<img class="gif-box" src="resources/icons/<?= $this->data['noty']['icon'] ?>">
79+
<?php endif; ?>
80+
<p><?= $this->t('{themevanilla:attrauthcomanage_noty:title}') ?></p>
81+
</h3>
82+
<?php if (!is_null($notyStatus)) : ?>
83+
<div id="noty-info-bar" class="<?= $notyLevel ?>"><?= $notyStatus ?></div>
84+
<?php endif; ?>
85+
<div class="noty-description">
86+
<?php
87+
foreach ($this->data['noty']['description'] as $dictKey => $placeholders) {
88+
if (!empty($placeholders)) {
89+
echo $this->t('{themevanilla:attrauthcomanage_noty:' . $dictKey . '}', $placeholders);
90+
} else {
91+
echo $this->t('{themevanilla:attrauthcomanage_noty:' . $dictKey . '}');
92+
}
93+
}
94+
?>
95+
</div>
96+
</p>
97+
<!-- Yes/Confirm Action -->
98+
<?php if (
99+
!empty($this->data['yesTarget'])
100+
&& $yesButtonShow
101+
) : ?>
102+
<form
103+
style="display: inline; margin: 0px; margin-right: 0.5em; padding: 0px"
104+
onclick="javascript:form_ajax(this)"
105+
onsubmit="event.preventDefault();return false;"
106+
method="post"
107+
action="<?= htmlspecialchars($this->data['yesTarget']) ?>"
108+
>
109+
<?php foreach ($this->data['yesData'] as $name => $value) : ?>
110+
<input
111+
type="hidden"
112+
name="<?= htmlspecialchars($name) ?>"
113+
value="<?= htmlspecialchars($value) ?>"
114+
/>
115+
<?php endforeach; ?>
116+
<?php foreach ($this->data['noty']['form_fields'] as $name => $value) : ?>
117+
<input
118+
type="hidden"
119+
name="<?= htmlspecialchars($name) ?>"
120+
value="<?= htmlspecialchars($value) ?>"
121+
/>
122+
<?php endforeach; ?>
123+
<input
124+
type="hidden"
125+
name="yes"
126+
value="yes"
127+
/>
128+
<button type="submit" name="yes" class="btn btn-primary" id="yesbutton">
129+
<?= htmlspecialchars($yesButtonLabel) ?>
130+
</button>
131+
</form>
132+
<?php endif; ?>
133+
134+
<!-- Cancel/ Abort Action -->
135+
<form
136+
style="display: inline;"
137+
action="<?= htmlspecialchars($this->data['logoutLink']) ?>"
138+
method="get"
139+
>
140+
<?php foreach ($this->data['logoutData'] as $name => $value) : ?>
141+
<input
142+
type="hidden"
143+
name="<?= htmlspecialchars($name) ?>"
144+
value="<?= htmlspecialchars($value) ?>"
145+
/>
146+
<?php endforeach; ?>
147+
<button
148+
type="submit"
149+
class="btn-link"
150+
name="no"
151+
id="nobutton"
152+
>
153+
<?= htmlspecialchars($this->t('{themevanilla:attrauthcomanage_noty:no}')) ?>
154+
</button>
155+
</form>
156+
157+
<?php
158+
// XXX Include footer
159+
$this->includeAtTemplateBase('includes/footer.php');
160+
161+
?>
162+
<script
163+
type="text/javascript"
164+
src="/<?= $this->data['baseurlpath'] ?>module.php/attrauthcomanage/resources/js/noty/jquery.noty.js">
165+
</script>
166+
<script
167+
type="text/javascript"
168+
src="/<?= $this->data['baseurlpath'] ?>module.php/attrauthcomanage/resources/js/noty/layouts/topCenter.js">
169+
</script>
170+
<script
171+
type="text/javascript"
172+
src="/<?= $this->data['baseurlpath'] ?>module.php/attrauthcomanage/resources/js/noty/themes/comanage.js">
173+
</script>
174+
<script type="application/javascript">
175+
let button_text = '<?= $this->t('{themevanilla:attrauthcomanage_noty:yes}') ?>';
176+
177+
// Generate flash notifications for messages
178+
function generateFlash(text, type) {
179+
var n = noty({
180+
text: text,
181+
type: type,
182+
dismissQueue: true,
183+
layout: 'topCenter',
184+
theme: 'comanage'
185+
});
186+
}
187+
188+
function form_ajax(frm_ob) {
189+
// hide the loader
190+
$('.loader-container').hide();
191+
// Handle the form
192+
var $form = $(frm_ob);
193+
let jqxhr = $.ajax({
194+
cache: false,
195+
type: $form.attr('method'),
196+
url: $form.attr('action'),
197+
beforeSend: function(xhr) {
198+
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
199+
// Update Button text and disable
200+
$button = $('#yesbutton');
201+
// debugger;
202+
$button.html('<i class="fa fa-spinner fa-spin"></i>Sending...');
203+
$button.prop("disabled", true);
204+
},
205+
data: $form.serialize(),
206+
});
207+
208+
jqxhr.done((data, textStatus, xhr) => {
209+
// Redirect to the general email
210+
// Update the status of the buttons
211+
$button = $('#yesbutton');
212+
$button.prop("disabled", false);
213+
$button.html(button_text);
214+
// Update the color of the class
215+
$('#noty-info-bar').removeClass().addClass('info');
216+
$('.invite-expire')
217+
.html('<?= htmlspecialchars($this->t('{themevanilla:attrauthcomanage_noty:invitation_restored}')) ?>');
218+
219+
generateFlash(data['msg'], 'success');
220+
});
221+
222+
jqxhr.fail((xhr, textStatus, error) => {
223+
// Enable the submit button
224+
$button = $('#yesbutton');
225+
$button.prop("disabled", false);
226+
$button.html(button_text);
227+
228+
let err_header = "";
229+
let reload_message = 'Please Reload View';
230+
231+
// Show an error message
232+
if (
233+
xhr.statusText != undefined
234+
&& xhr.statusText != ""
235+
) {
236+
error = error + " (Status Code: " + xhr.status + ")";
237+
}
238+
if (
239+
xhr.responseText != undefined
240+
&& xhr.responseText != ""
241+
) {
242+
// JSON text
243+
try {
244+
//try to parse JSON
245+
encodedJson = $.parseJSON(xhr.responseText);
246+
err_header = encodedJson.msg;
247+
} catch (e) {
248+
/* This is not JSON */
249+
}
250+
// HTML text
251+
try {
252+
let htmlparsed = $.parseHTML(xhr.responseText);
253+
err_header = htmlparsed[0].textContent;
254+
} catch (e) {
255+
/* This is not HTML either */
256+
}
257+
// Found no error header. Should i look elsewhere?
258+
}
259+
260+
error = (err_header != "") ? (error + "<br>" + err_header) : error;
261+
error = (err_header.includes("CSRF")) ? (error + "<br>" + reload_message) : error;
262+
263+
generateFlash(error, textStatus);
264+
});
265+
}
266+
</script>

0 commit comments

Comments
 (0)