PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.4.5
Fluent Support – Helpdesk & Customer Support Ticket System v2.4.5
2.4.5 2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 All 69 releases
← All changes | app/Hooks/Handlers/AuthHandler.php +85 -38 1.10.3 → 2.4.5 View file →
@@ -3,10 +3,12 @@
3 3 namespace FluentSupport\App\Hooks\Handlers;
4 4
5 5 use FluentSupport\App\App;
6 6 use FluentSupport\App\Modules\PermissionManager;
7 +use FluentSupport\App\Services\FluentAuthBridge;
7 8 use FluentSupport\App\Services\Helper;
8 9 use FluentSupport\App\Services\Includes\CountryNames;
10 +use FluentSupport\App\Vite;
9 11 use FluentSupport\Framework\Support\Arr;
10 12 use FluentSupport\App\Models\Meta;
11 13
12 14 class AuthHandler
@@ -20,12 +22,13 @@
20 22 add_shortcode('fluent_support_signup', array($this, 'registrationForm'));
21 23 add_shortcode('fluent_support_auth', array($this, 'authForm'));
22 24 add_shortcode('fluent_support_reset_password', array($this, 'restPasswordForm'));
23 25 add_action('wp_ajax_fluent_support_renew_rest_nonce', [$this, 'maybeRenewNonce']);
26 +
27 + FluentAuthBridge::register();
24 28 }
25 29
26 30 /**
27 - * loginForm will generate html for login form
28 31 * @param $attributes
29 32 * @return string
30 33 */
31 34 public function loginForm($attributes)
@@ -44,11 +47,10 @@
44 47
45 48 $this->handleAlreadyLoggedIn($attributes);
46 49
47 50 if ($this->authProvider() == 'fluent_auth') {
48 - // Will be handled by FluentAuth plugin
49 51 $attributes['redirect_to'] = $redirect;
50 - return (new \FluentAuth\App\Hooks\Handlers\CustomAuthHandler())->loginForm($attributes);
52 + return $this->renderFluentAuthForms($attributes);
51 53 }
52 54
53 55 $this->loadAssets();
54 56
@@ -102,9 +104,8 @@
102 104 return $return;
103 105 }
104 106
105 107 /**
106 - * registrationForm method will generate html for sign up form
107 108 * @param $attributes
108 109 * @return string
109 110 */
110 111 public function registrationForm($attributes)
@@ -115,13 +116,23 @@
115 116
116 117 $attributes = $this->getShortcodes($attributes);
117 118 $this->handleAlreadyLoggedIn($attributes);
118 119
120 + if (!Helper::isSignupEnabled()) {
121 + if ($attributes['hide'] == 'true') {
122 + return '';
123 + }
124 +
125 + return '<p>' . __('User registration is not enabled on this site.', 'fluent-support') . '</p>';
126 + }
127 +
119 128 if ($this->authProvider() == 'fluent_auth') {
120 - return (new \FluentAuth\App\Hooks\Handlers\CustomAuthHandler())->registrationForm($attributes);
129 + return FluentAuthBridge::render(function () use ($attributes) {
130 + return (new \FluentAuth\App\Hooks\Handlers\CustomAuthHandler())->registrationForm($attributes);
131 + }, $attributes['redirect_to']);
121 132 }
122 133
123 - $customFieldsKey = apply_filters('fluent_support/custom_registration_form_fields_key', Helper::getBusinessSettings('custom_registration_form_field'));
134 + $customFieldsKey = Helper::getCustomRegistrationFieldKeys();
124 135
125 136 if (!empty($customFieldsKey)) {
126 137 add_filter('fluent_support/registration_form_fields', function($fields) use ($customFieldsKey) {
127 138 return $this->addCustomFieldsToRegistrationForm($fields,$customFieldsKey);
@@ -135,9 +146,8 @@
135 146
136 147 return $this->buildRegistrationForm($registrationFields, $hide, $attributes);
137 148 }
138 149
139 - // This method `buildRegistrationForm` will generate html for sign up form
140 150 private function buildRegistrationForm($registrationFields, $hide, $attributes)
141 151 {
142 152 $registrationForm = '<div class="fst_registration_wrapper ' . $hide . '"><form id="fstRegistrationForm" class="fs_registration_form" method="post" name="fs_registration_form">';
143 153
@@ -144,9 +154,9 @@
144 154 foreach ($registrationFields as $fieldName => $registrationField) {
145 155 $registrationForm .= $this->renderField($fieldName, $registrationField);
146 156 }
147 157
148 - $registrationForm .= '<input type="hidden" name="__redirect_to" value="' . $attributes['redirect-to'] . '">';
158 + $registrationForm .= '<input type="hidden" name="__redirect_to" value="' . esc_url($attributes['redirect-to']) . '">';
149 159 $registrationForm .= '<input type="hidden" name="_fsupport_signup_nonce" value="' . wp_create_nonce('fluent_support_signup_nonce') . '">';
150 160 $registrationForm .= '<button type="submit" id="fst_submit">' . $this->submitBtnLoadingSvg() . '<span>' . __('Signup', 'fluent-support') . '</span></button>';
151 161
152 162 $registrationForm .= '</form>';
@@ -174,9 +184,11 @@
174 184
175 185 $attributes = $this->getShortcodes($attributes);
176 186
177 187 if ($this->authProvider() == 'fluent_auth') {
178 - return (new \FluentAuth\App\Hooks\Handlers\CustomAuthHandler())->restPasswordForm($attributes);
188 + return FluentAuthBridge::render(function () use ($attributes) {
189 + return (new \FluentAuth\App\Hooks\Handlers\CustomAuthHandler())->restPasswordForm($attributes);
190 + }, $attributes['redirect_to']);
179 191 }
180 192
181 193 $this->handleAlreadyLoggedIn($attributes);
182 194
@@ -187,9 +199,8 @@
187 199
188 200 return $this->buildResetPassForm($resetPasswordFields, $hide, $attributes);
189 201 }
190 202
191 - // This method `buildResetPassForm` will generate html for password reset form
192 203 private function buildResetPassForm($resetPasswordFields, $hide, $attributes)
193 204 {
194 205 $restePasswordForm = '<div class="fst_reset_pass_wrapper ' . $hide . '"><form id="fstResetPasswordForm" class="fs_reset_pass_form" method="post" name="fs_reset_pass_form">';
195 206
@@ -196,9 +207,9 @@
196 207 foreach ($resetPasswordFields as $fieldName => $resetPasswordField) {
197 208 $restePasswordForm .= $this->renderField($fieldName, $resetPasswordField);
198 209 }
199 210
200 - $restePasswordForm .= '<input type="hidden" name="__redirect_to" value="' . $attributes['redirect-to'] . '">';
211 + $restePasswordForm .= '<input type="hidden" name="__redirect_to" value="' . esc_url($attributes['redirect-to']) . '">';
201 212 $restePasswordForm .= '<input type="hidden" name="_fsupport_reset_pass_nonce" value="' . wp_create_nonce('fluent_support_reset_pass_nonce') . '">';
202 213 $restePasswordForm .= '<button type="submit" id="fst_reset_pass">' . $this->submitBtnLoadingSvg() . '<span>' . __('Reset Password', 'fluent-support') . '</span></button>';
203 214
204 215 $restePasswordForm .= '</form>';
@@ -208,9 +219,10 @@
208 219 return $restePasswordForm;
209 220 }
210 221
211 222 /**
212 - * authForm will render the login form html
223 + * Login form with signup and reset links, or FluentAuth's form when it is the provider.
224 + *
213 225 * @param $attributes
214 226 * @return string
215 227 */
216 228 public function authForm($attributes)
@@ -219,21 +231,47 @@
219 231 // translators: %s is the URL to the support portal
220 232 return '<p>' . sprintf(__('You are already logged in. <a href="%s">Go to support portal</a>', 'fluent-support'), Helper::getPortalBaseUrl()) . '</p>';
221 233 }
222 234
223 - $attributes = $this->getShortcodes($attributes);
235 + $attributes = $this->getShortcodes($attributes, true);
224 236
225 237 if ($this->authProvider() == 'fluent_auth') {
226 - return (new \FluentAuth\App\Hooks\Handlers\CustomAuthHandler())->authForm($attributes);
238 + return $this->renderFluentAuthForms($attributes);
227 239 }
228 240
229 - $authForm = do_shortcode('[fluent_support_login show-signup=true show-reset-password=true]');
241 + return $this->loginForm($attributes);
242 + }
230 243
231 - return $authForm;
244 + /**
245 + * FluentAuth's login form, plus its signup and reset forms (hidden) when the shortcode
246 + * shows them. Its "Create an Account" and "Reset Password" links open a form that must
247 + * already be on the page, and its own authForm() always adds reset, so we pick the
248 + * forms here. FluentAuth renders and processes each one.
249 + *
250 + * @param array $attributes
251 + * @return string
252 + */
253 + private function renderFluentAuthForms($attributes)
254 + {
255 + return FluentAuthBridge::render(function () use ($attributes) {
256 + $handler = new \FluentAuth\App\Hooks\Handlers\CustomAuthHandler();
257 + $hidden = array_merge($attributes, ['hide' => 'true']);
258 +
259 + $html = '<div class="fls_auth_wrapper">' . $handler->loginForm($attributes);
260 +
261 + if ($attributes['show-signup'] == 'true') {
262 + $html .= $handler->registrationForm($hidden);
263 + }
264 +
265 + if ($attributes['show-reset-password'] == 'true') {
266 + $html .= $handler->restPasswordForm($hidden);
267 + }
268 +
269 + return $html . '</div>';
270 + }, $attributes['redirect_to']);
232 271 }
233 272
234 273 /**
235 - * renderField method will generate html for a field
236 274 * @param $fieldName
237 275 * @param $field
238 276 * @return string
239 277 */
@@ -249,9 +287,9 @@
249 287 $html .= '<div class="fst_field_label ' . $isRequired . '"><label for="' . Arr::get($field, 'id') . '">' . $label . '</label></div>';
250 288 }
251 289
252 290 $textTypes = ['text', 'email', 'password', 'number', 'date'];
253 - $selectTypes = ['select']; // Add 'select' type for dropdowns
291 + $selectTypes = ['select'];
254 292
255 293 if (in_array($fieldType, $textTypes)) {
256 294 $html .= $this->renderTextInput($fieldName, $field);
257 295 } elseif (in_array($fieldType, $selectTypes)) {
@@ -267,11 +305,11 @@
267 305
268 306 private function renderTextInput($fieldName, $field)
269 307 {
270 308 $inputAtts = array_filter([
271 - 'type' => esc_attr(Arr::get($field, 'type')),
272 - 'id' => esc_attr(Arr::get($field, 'id')),
273 - 'placeholder' => esc_attr(Arr::get($field, 'placeholder')),
309 + 'type' => esc_attr(Arr::get($field, 'type', '')),
310 + 'id' => esc_attr(Arr::get($field, 'id', '')),
311 + 'placeholder' => esc_attr(Arr::get($field, 'placeholder', '')),
274 312 'name' => esc_attr($fieldName),
275 313 'required' => Arr::get($field, 'required') ? 'required' : '',
276 314 ]);
277 315
@@ -284,14 +322,11 @@
284 322 return '<div class="fs_input_wrap"><input ' . $atts . ' /></div>';
285 323 }
286 324
287 325 /**
288 - * Render a select input field based on the provided field configuration.
289 - *
290 - * @param string $fieldName The name of the select input field.
291 - * @param array $field The field configuration containing options and attributes.
292 - *
293 - * @return string The rendered select input field HTML.
326 + * @param string $fieldName
327 + * @param array $field Field config with options and attributes.
328 + * @return string
294 329 */
295 330 private function renderSelectInput($fieldName, $field)
296 331 {
297 332 $choices = Arr::get($field, 'options', []);
@@ -303,9 +338,9 @@
303 338 $options .= '<option value="' . esc_attr($value) . '">' . esc_attr($optionData) . '</option>';
304 339 }
305 340
306 341 $selectAtts = [
307 - 'id' => esc_attr(Arr::get($field, 'id')),
342 + 'id' => esc_attr(Arr::get($field, 'id', '')),
308 343 'name' => esc_attr($fieldName),
309 344 'required' => Arr::get($field, 'required') ? 'required' : '',
310 345 ];
311 346
@@ -325,9 +360,8 @@
325 360 return $atts;
326 361 }
327 362
328 363 /**
329 - * getSignupFields method will return the list of fields that will be used for sign up form
330 364 * @return mixed
331 365 */
332 366 public static function getSignupFields()
333 367 {
@@ -379,9 +413,11 @@
379 413 private function addCustomFieldsToRegistrationForm($fields, $customFieldsKey) {
380 414 $customFields = $this->allCustomFields();
381 415
382 416 foreach ($customFieldsKey as $key) {
383 - $fields[$key] = $customFields[$key];
417 + if (isset($customFields[$key])) {
418 + $fields[$key] = $customFields[$key];
419 + }
384 420 }
385 421
386 422 return $fields;
387 423 }
@@ -480,12 +516,12 @@
480 516 */
481 517 return apply_filters('fluent_support/signup_loading_icon', $loadingIcon);
482 518 }
483 519
484 - protected function getShortcodes($attributes)
520 + protected function getShortcodes($attributes, $isAuthForm = false)
485 521 {
486 522 /*
487 - * Filter shortcode behavior for agent
523 + * Filter the default attributes of the auth shortcodes.
488 524 *
489 525 * @since v1.0.0
490 526 *
491 527 * @param array $shortCodeDefaults
@@ -493,15 +529,21 @@
493 529 $shortCodeDefaults = apply_filters('fluent_support/auth_shortcode_defaults', [
494 530 'auto-redirect' => false,
495 531 'redirect-to' => Helper::getPortalBaseUrl(),
496 532 'hide' => false,
497 - 'show-signup' => false,
498 - 'show-reset-password' => false,
533 + 'show-signup' => $isAuthForm ? 'true' : 'false',
534 + 'show-reset-password' => $isAuthForm ? 'true' : 'false',
499 535 ]);
500 536
501 537 $attributes = shortcode_atts($shortCodeDefaults, $attributes);
502 538
539 + // No signup form or link while the site does not allow registration.
540 + if (!Helper::isSignupEnabled()) {
541 + $attributes['show-signup'] = 'false';
542 + }
543 +
503 544 if (isset($attributes['redirect-to'])) {
545 + $attributes['redirect-to'] = esc_url_raw($attributes['redirect-to']);
504 546 $attributes['redirect_to'] = $attributes['redirect-to'];
505 547 }
506 548
507 549 return $attributes;
@@ -533,12 +575,17 @@
533 575 }
534 576
535 577 $app = App::getInstance();
536 578 $assets = $app['url.assets'];
537 - wp_enqueue_style('fluent_support_login_style', $assets . 'admin/css/all_public.css', [], FLUENT_SUPPORT_VERSION);
538 - wp_enqueue_script('fluent_support_login_helper', $assets . 'portal/js/login_helper.js', [], FLUENT_SUPPORT_VERSION);
539 579
540 - //Get Recaptcha settings and enqueue recaptcha script
580 + if (is_rtl()) {
581 + wp_enqueue_style('fluent_support_login_style_rtl', $assets . 'admin/css/all_public-rtl.css', [], FLUENT_SUPPORT_VERSION);
582 + } else {
583 + wp_enqueue_style('fluent_support_login_style', Vite::getEnqueuePath('admin/css/all_public.css'), [], FLUENT_SUPPORT_VERSION);
584 + }
585 +
586 + wp_enqueue_script('fluent_support_login_helper', Vite::getEnqueuePath('portal/js/login_helper.js'), [], FLUENT_SUPPORT_VERSION);
587 +
541 588 $reCaptchaSettingsData = Meta::where('object_type', '_fs_recaptcha_settings')->first();
542 589 $reCaptchaData = ($reCaptchaSettingsData) ? Helper::safeUnserialize($reCaptchaSettingsData->value, []) : '';
543 590
544 591 if (!empty($reCaptchaData) && isset($reCaptchaData['is_enabled']) && $reCaptchaData['is_enabled'] == "true") {
@@ -572,9 +619,9 @@
572 619 public function maybeRenewNonce()
573 620 {
574 621 if (!PermissionManager::currentUserPermissions()) {
575 622 wp_send_json([
576 - 'error' => 'You do not have permission to do this'
623 + 'error' => __('You do not have permission to do this.', 'fluent-support')
577 624 ], 403);
578 625 }
579 626
580 627 wp_send_json([