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 +86 -38 1.10.1 → 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)
@@ -215,24 +227,51 @@
215 227 */
216 228 public function authForm($attributes)
217 229 {
218 230 if (get_current_user_id()) {
231 + // translators: %s is the URL to the support portal
219 232 return '<p>' . sprintf(__('You are already logged in. <a href="%s">Go to support portal</a>', 'fluent-support'), Helper::getPortalBaseUrl()) . '</p>';
220 233 }
221 234
222 - $attributes = $this->getShortcodes($attributes);
235 + $attributes = $this->getShortcodes($attributes, true);
223 236
224 237 if ($this->authProvider() == 'fluent_auth') {
225 - return (new \FluentAuth\App\Hooks\Handlers\CustomAuthHandler())->authForm($attributes);
238 + return $this->renderFluentAuthForms($attributes);
226 239 }
227 240
228 - $authForm = do_shortcode('[fluent_support_login show-signup=true show-reset-password=true]');
241 + return $this->loginForm($attributes);
242 + }
229 243
230 - 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']);
231 271 }
232 272
233 273 /**
234 - * renderField method will generate html for a field
235 274 * @param $fieldName
236 275 * @param $field
237 276 * @return string
238 277 */
@@ -248,9 +287,9 @@
248 287 $html .= '<div class="fst_field_label ' . $isRequired . '"><label for="' . Arr::get($field, 'id') . '">' . $label . '</label></div>';
249 288 }
250 289
251 290 $textTypes = ['text', 'email', 'password', 'number', 'date'];
252 - $selectTypes = ['select']; // Add 'select' type for dropdowns
291 + $selectTypes = ['select'];
253 292
254 293 if (in_array($fieldType, $textTypes)) {
255 294 $html .= $this->renderTextInput($fieldName, $field);
256 295 } elseif (in_array($fieldType, $selectTypes)) {
@@ -266,11 +305,11 @@
266 305
267 306 private function renderTextInput($fieldName, $field)
268 307 {
269 308 $inputAtts = array_filter([
270 - 'type' => esc_attr(Arr::get($field, 'type')),
271 - 'id' => esc_attr(Arr::get($field, 'id')),
272 - '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', '')),
273 312 'name' => esc_attr($fieldName),
274 313 'required' => Arr::get($field, 'required') ? 'required' : '',
275 314 ]);
276 315
@@ -283,14 +322,11 @@
283 322 return '<div class="fs_input_wrap"><input ' . $atts . ' /></div>';
284 323 }
285 324
286 325 /**
287 - * Render a select input field based on the provided field configuration.
288 - *
289 - * @param string $fieldName The name of the select input field.
290 - * @param array $field The field configuration containing options and attributes.
291 - *
292 - * @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
293 329 */
294 330 private function renderSelectInput($fieldName, $field)
295 331 {
296 332 $choices = Arr::get($field, 'options', []);
@@ -302,9 +338,9 @@
302 338 $options .= '<option value="' . esc_attr($value) . '">' . esc_attr($optionData) . '</option>';
303 339 }
304 340
305 341 $selectAtts = [
306 - 'id' => esc_attr(Arr::get($field, 'id')),
342 + 'id' => esc_attr(Arr::get($field, 'id', '')),
307 343 'name' => esc_attr($fieldName),
308 344 'required' => Arr::get($field, 'required') ? 'required' : '',
309 345 ];
310 346
@@ -324,9 +360,8 @@
324 360 return $atts;
325 361 }
326 362
327 363 /**
328 - * getSignupFields method will return the list of fields that will be used for sign up form
329 364 * @return mixed
330 365 */
331 366 public static function getSignupFields()
332 367 {
@@ -378,9 +413,11 @@
378 413 private function addCustomFieldsToRegistrationForm($fields, $customFieldsKey) {
379 414 $customFields = $this->allCustomFields();
380 415
381 416 foreach ($customFieldsKey as $key) {
382 - $fields[$key] = $customFields[$key];
417 + if (isset($customFields[$key])) {
418 + $fields[$key] = $customFields[$key];
419 + }
383 420 }
384 421
385 422 return $fields;
386 423 }
@@ -479,12 +516,12 @@
479 516 */
480 517 return apply_filters('fluent_support/signup_loading_icon', $loadingIcon);
481 518 }
482 519
483 - protected function getShortcodes($attributes)
520 + protected function getShortcodes($attributes, $isAuthForm = false)
484 521 {
485 522 /*
486 - * Filter shortcode behavior for agent
523 + * Filter the default attributes of the auth shortcodes.
487 524 *
488 525 * @since v1.0.0
489 526 *
490 527 * @param array $shortCodeDefaults
@@ -492,15 +529,21 @@
492 529 $shortCodeDefaults = apply_filters('fluent_support/auth_shortcode_defaults', [
493 530 'auto-redirect' => false,
494 531 'redirect-to' => Helper::getPortalBaseUrl(),
495 532 'hide' => false,
496 - 'show-signup' => false,
497 - 'show-reset-password' => false,
533 + 'show-signup' => $isAuthForm ? 'true' : 'false',
534 + 'show-reset-password' => $isAuthForm ? 'true' : 'false',
498 535 ]);
499 536
500 537 $attributes = shortcode_atts($shortCodeDefaults, $attributes);
501 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 +
502 544 if (isset($attributes['redirect-to'])) {
545 + $attributes['redirect-to'] = esc_url_raw($attributes['redirect-to']);
503 546 $attributes['redirect_to'] = $attributes['redirect-to'];
504 547 }
505 548
506 549 return $attributes;
@@ -532,12 +575,17 @@
532 575 }
533 576
534 577 $app = App::getInstance();
535 578 $assets = $app['url.assets'];
536 - wp_enqueue_style('fluent_support_login_style', $assets . 'admin/css/all_public.css', [], FLUENT_SUPPORT_VERSION);
537 - wp_enqueue_script('fluent_support_login_helper', $assets . 'portal/js/login_helper.js', [], FLUENT_SUPPORT_VERSION);
538 579
539 - //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 +
540 588 $reCaptchaSettingsData = Meta::where('object_type', '_fs_recaptcha_settings')->first();
541 589 $reCaptchaData = ($reCaptchaSettingsData) ? Helper::safeUnserialize($reCaptchaSettingsData->value, []) : '';
542 590
543 591 if (!empty($reCaptchaData) && isset($reCaptchaData['is_enabled']) && $reCaptchaData['is_enabled'] == "true") {
@@ -571,9 +619,9 @@
571 619 public function maybeRenewNonce()
572 620 {
573 621 if (!PermissionManager::currentUserPermissions()) {
574 622 wp_send_json([
575 - 'error' => 'You do not have permission to do this'
623 + 'error' => __('You do not have permission to do this.', 'fluent-support')
576 624 ], 403);
577 625 }
578 626
579 627 wp_send_json([