Skip to content

Commit 574a73c

Browse files
authored
Merge pull request #330 from RRZE-Webteam/dev
Dev
2 parents bc161c3 + 2886a0a commit 574a73c

File tree

6 files changed

+47
-45
lines changed

6 files changed

+47
-45
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rrze/rrze-rsvp",
3-
"version": "2.10.0",
3+
"version": "2.10.1",
44
"require": {
55
"cmb2/cmb2": "^2.10.0",
66
"tecnickcom/tcpdf": "^6.4.4"

includes/Main.php

+6-11
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,13 @@ public function includeSingleTemplate()
9292
return;
9393
}
9494

95-
$idm = new IdM();
96-
$ldap = new LDAP();
97-
9895
$template = '';
99-
if (
100-
!$idm->isAuthenticated() &&
101-
!$ldap->isAuthenticated() &&
102-
isset($_GET['require-auth']) &&
103-
wp_verify_nonce($_GET['require-auth'], 'require-auth')
104-
) {
105-
$template = plugin()->getPath('includes/templates/auth') . 'single-auth.php';
96+
if (isset($_GET['require-auth']) && wp_verify_nonce($_GET['require-auth'], 'require-auth')) {
97+
$idm = new IdM;
98+
$ldap = new LDAP;
99+
if (!$idm->isAuthenticated() && !$ldap->isAuthenticated()) {
100+
$template = plugin()->getPath('includes/templates/auth') . 'single-auth.php';
101+
}
106102
} elseif (
107103
isset($_REQUEST['nonce']) &&
108104
wp_verify_nonce($_REQUEST['nonce'], 'rsvp-availability')
@@ -128,7 +124,6 @@ public function maybeAuthenticate()
128124
if (isset($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'rrze-rsvp-seat-check-inout')) {
129125
$idm = new IdM;
130126
$ldap = new LDAP;
131-
132127
if (!$idm->isAuthenticated() && !$ldap->isAuthenticated()) {
133128
$queryStr = Functions::getQueryStr([], ['require-auth']);
134129
Auth::tryLogIn($queryStr);

includes/Shortcodes/Bookings.php

+30-21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace RRZE\RSVP\Shortcodes;
44

55
use RRZE\RSVP\{Email, Functions, Template, TransientData};
6+
use RRZE\RSVP\Auth\{IdM, LDAP};
67

78
use function RRZE\RSVP\Config\defaultOptions;
89
use function RRZE\RSVP\Config\getShortcodeSettings;
@@ -48,7 +49,7 @@ public function __construct($settings)
4849
public function shortcodeBooking($atts, $content = '', $tag = '')
4950
{
5051
global $post;
51-
$postID = $post->ID;
52+
$postID = $post->ID;
5253

5354
if (isset($_GET['transient-data']) && isset($_GET['transient-data-nonce']) && wp_verify_nonce($_GET['transient-data-nonce'], 'transient-data-' . $_GET['transient-data'])) {
5455
$transient = $_GET['transient-data'];
@@ -63,14 +64,14 @@ public function shortcodeBooking($atts, $content = '', $tag = '')
6364
wp_redirect($redirectUrl);
6465
exit;
6566
}
66-
}
67-
67+
}
68+
6869
wp_enqueue_style('rrze-rsvp-shortcode');
6970

7071
if ($output = $this->ssoAuthenticationError()) {
7172
return $output;
7273
}
73-
// if ($output = $this->ldapAuthenticationError()) {
74+
// if ($output = $ldapAuthenticationError()) {
7475
// return $output;
7576
// }
7677
if ($output = $this->postDataError()) {
@@ -107,10 +108,12 @@ public function shortcodeBooking($atts, $content = '', $tag = '')
107108
wp_enqueue_script('rrze-rsvp-shortcode');
108109

109110
// Perhaps the user needs authentication?
111+
$idm = new IdM;
112+
$ldap = new LDAP;
110113
$ssoRequired = Functions::getBoolValueFromAtt(get_post_meta($input_room, 'rrze-rsvp-room-sso-required', true));
111114
$ldapRequired = Functions::getBoolValueFromAtt(get_post_meta($input_room, 'rrze-rsvp-room-ldap-required', true));
112115
$ldapRequired = $ldapRequired && $this->settings->getOption('ldap', 'server') ? true : false;
113-
if (($ssoRequired && !$this->idm->isAuthenticated()) || ($ldapRequired && !$this->ldap->isAuthenticated())) {
116+
if (($ssoRequired && !$idm->isAuthenticated()) || ($ldapRequired && !$ldap->isAuthenticated())) {
114117
if ($output = $this->authForm($ssoRequired, $ldapRequired)) {
115118
return $output;
116119
}
@@ -273,8 +276,8 @@ public function shortcodeBooking($atts, $content = '', $tag = '')
273276
$output .= '<fieldset>';
274277
$output .= '<legend>' . __('Your data', 'rrze-rsvp') . ' <span class="notice-required">(' . __('Required', 'rrze-rsvp') . ')</span></legend>';
275278

276-
if ($this->idm->isAuthenticated()) {
277-
$data = $this->idm->getCustomerData();
279+
if ($idm->isAuthenticated()) {
280+
$data = $idm->getCustomerData();
278281
$output .= '<input type="hidden" value="' . $data['customer_lastname'] . '" id="rsvp_lastname" name="rsvp_lastname">';
279282
$output .= '<input type="hidden" value="' . $data['customer_firstname'] . '" id="rsvp_firstname" name="rsvp_firstname">';
280283
$output .= '<input type="hidden" value="' . $data['customer_email'] . '" id="rsvp_email" name="rsvp_email">';
@@ -286,16 +289,16 @@ public function shortcodeBooking($atts, $content = '', $tag = '')
286289
. '</div>';
287290
}
288291

289-
if ($this->ldap->isAuthenticated()) {
290-
$data = $this->ldap->getCustomerData();
292+
if ($ldap->isAuthenticated()) {
293+
$data = $ldap->getCustomerData();
291294
$output .= '<input type="hidden" value="' . $data['customer_email'] . '" id="rsvp_email" name="rsvp_email">';
292295

293296
$output .= '<div class="form-group">'
294297
. '<p>' . __('Email', 'rrze-rsvp') . ': <strong>' . $data['customer_email'] . '</strong></p>'
295298
. '</div>';
296299
}
297300

298-
if (!$this->idm->isAuthenticated()) {
301+
if (!$idm->isAuthenticated()) {
299302
$error = isset($fieldErrors['rsvp_lastname']) ? ' error' : '';
300303
$value = isset($fieldErrors['rsvp_lastname']['value']) ? $fieldErrors['rsvp_lastname']['value'] : '';
301304
$message = isset($fieldErrors['rsvp_lastname']['message']) ? $fieldErrors['rsvp_lastname']['message'] : '';
@@ -315,7 +318,7 @@ public function shortcodeBooking($atts, $content = '', $tag = '')
315318
. '</div>';
316319
}
317320

318-
if (!$this->idm->isAuthenticated() && !$this->ldap->isAuthenticated()) {
321+
if (!$idm->isAuthenticated() && !$ldap->isAuthenticated()) {
319322
$error = isset($fieldErrors['rsvp_email']) ? ' error' : '';
320323
$value = isset($fieldErrors['rsvp_email']['value']) ? $fieldErrors['rsvp_email']['value'] : '';
321324
$message = isset($fieldErrors['rsvp_email']['message']) ? $fieldErrors['rsvp_email']['message'] : '';
@@ -530,15 +533,18 @@ protected function bookedNotice()
530533
return '';
531534
}
532535

536+
$idm = new IdM;
537+
$ldap = new LDAP;
538+
533539
$queryStr = Functions::getQueryStr([], ['require-auth']);
534540
$returnTo = trailingslashit(get_permalink()) . ($queryStr ? '?' . $queryStr : '');
535541

536-
if ($this->idm->isAuthenticated()) {
537-
$this->idm->logout($returnTo);
542+
if ($idm->isAuthenticated()) {
543+
$idm->logout($returnTo);
538544
}
539545

540-
if ($this->ldap->isAuthenticated()) {
541-
$this->ldap->logout($returnTo);
546+
if ($ldap->isAuthenticated()) {
547+
$ldap->logout($returnTo);
542548
}
543549

544550
$bookingId = absint($_GET['id']);
@@ -608,6 +614,9 @@ public function bookingSubmitted()
608614
return;
609615
}
610616

617+
$idm = new IdM;
618+
$ldap = new LDAP;
619+
611620
array_walk_recursive(
612621
$_POST,
613622
function (&$value) {
@@ -665,9 +674,9 @@ function (&$value) {
665674
$booking_end = array_key_exists($booking_start, $schedule[$weekday]) ? $schedule[$weekday][$booking_start] : $booking_start;
666675
$booking_timestamp_end = strtotime($booking_date . ' ' . $booking_end);
667676

668-
if ($this->idm->isAuthenticated()) {
669-
if ($this->idm->isAuthenticated()) {
670-
$sso_data = $this->idm->getCustomerData();
677+
if ($idm->isAuthenticated()) {
678+
if ($idm->isAuthenticated()) {
679+
$sso_data = $idm->getCustomerData();
671680
$booking_lastname = $sso_data['customer_lastname'];
672681
$booking_firstname = $sso_data['customer_firstname'];
673682
$booking_email = $sso_data['customer_email'];
@@ -682,9 +691,9 @@ function (&$value) {
682691
wp_redirect($redirectUrl);
683692
exit;
684693
}
685-
} elseif ($this->ldap->isAuthenticated()) {
686-
if ($this->ldap->isAuthenticated()) {
687-
$ldap_data = $this->ldap->getCustomerData();
694+
} elseif ($ldap->isAuthenticated()) {
695+
if ($ldap->isAuthenticated()) {
696+
$ldap_data = $ldap->getCustomerData();
688697
$booking_email = $ldap_data['customer_email'];
689698
} else {
690699
$redirectUrl = add_query_arg(

includes/Shortcodes/Shortcodes.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@
1111
*/
1212
class Shortcodes
1313
{
14-
protected $idm;
15-
16-
protected $ldap;
17-
1814
public function __construct()
1915
{
20-
$this->idm = new IdM;
21-
$this->ldap = new LDAP;
16+
//
2217
}
2318

2419
public function shortcodeAtts($atts, $tag, $settings)
@@ -37,19 +32,22 @@ public function shortcodeAtts($atts, $tag, $settings)
3732

3833
protected function authForm($ssoRequired = false, $ldapRequired = false)
3934
{
35+
$idm = new IdM;
36+
$ldap = new LDAP;
37+
4038
$emailError = filter_input(INPUT_GET, 'email_error', FILTER_VALIDATE_INT);
4139
$emailError = ($emailError ? '<p class="error-message">' . __('Please login to the account you have used to book this seat.', 'rrze-rsvp') . '</p><br><br>' : '');
4240

4341
$ldapError = '';
4442
if ($ldapRequired && isset($_POST['submit_ldap'])) {
45-
$this->ldap->login();
46-
if (!$this->ldap->isAuthenticated()) {
43+
$ldap->login();
44+
if (!$ldap->isAuthenticated()) {
4745
$ldapError = '<p class="error-message">' . __('Login denied', 'rrze-rsvp') . '</p>';
4846
}
4947
}
5048

51-
if ($ssoRequired && $this->idm->simplesamlAuth) {
52-
$loginUrl = $this->idm->getLoginURL();
49+
if ($ssoRequired && $idm->simplesamlAuth) {
50+
$loginUrl = $idm->getLoginURL();
5351
$idmLogin = sprintf(__('<a href="%s">Please login with your IdM username</a>.', 'rrze-rsvp'), $loginUrl);
5452
}
5553

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rrze-rsvp",
3-
"version": "2.10.0",
3+
"version": "2.10.1",
44
"main": "rrze-rsvp.php",
55
"scripts": {
66
"start": "webpack --mode=development --watch",

rrze-rsvp.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Plugin Name: RRZE RSVP
55
Plugin URI: https://github.com/RRZE-Webteam/rrze-rsvp
66
Description: FAU Reservation Tool
7-
Version: 2.10.0
7+
Version: 2.10.1
88
Author: RRZE-Webteam
99
Author URI: https://blogs.fau.de/webworking/
1010
License: GNU General Public License v2

0 commit comments

Comments
 (0)