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 +68 -26 2.2.1 → 2.4.5 View file →
@@ -3,8 +3,9 @@
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;
9 10 use FluentSupport\App\Vite;
10 11 use FluentSupport\Framework\Support\Arr;
@@ -21,12 +22,13 @@
21 22 add_shortcode('fluent_support_signup', array($this, 'registrationForm'));
22 23 add_shortcode('fluent_support_auth', array($this, 'authForm'));
23 24 add_shortcode('fluent_support_reset_password', array($this, 'restPasswordForm'));
24 25 add_action('wp_ajax_fluent_support_renew_rest_nonce', [$this, 'maybeRenewNonce']);
26 +
27 + FluentAuthBridge::register();
25 28 }
26 29
27 30 /**
28 - * loginForm will generate html for login form
29 31 * @param $attributes
30 32 * @return string
31 33 */
32 34 public function loginForm($attributes)
@@ -45,11 +47,10 @@
45 47
46 48 $this->handleAlreadyLoggedIn($attributes);
47 49
48 50 if ($this->authProvider() == 'fluent_auth') {
49 - // Will be handled by FluentAuth plugin
50 51 $attributes['redirect_to'] = $redirect;
51 - return (new \FluentAuth\App\Hooks\Handlers\CustomAuthHandler())->loginForm($attributes);
52 + return $this->renderFluentAuthForms($attributes);
52 53 }
53 54
54 55 $this->loadAssets();
55 56
@@ -103,9 +104,8 @@
103 104 return $return;
104 105 }
105 106
106 107 /**
107 - * registrationForm method will generate html for sign up form
108 108 * @param $attributes
109 109 * @return string
110 110 */
111 111 public function registrationForm($attributes)
@@ -116,13 +116,23 @@
116 116
117 117 $attributes = $this->getShortcodes($attributes);
118 118 $this->handleAlreadyLoggedIn($attributes);
119 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 +
120 128 if ($this->authProvider() == 'fluent_auth') {
121 - 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']);
122 132 }
123 133
124 - $customFieldsKey = apply_filters('fluent_support/custom_registration_form_fields_key', Helper::getBusinessSettings('custom_registration_form_field'));
134 + $customFieldsKey = Helper::getCustomRegistrationFieldKeys();
125 135
126 136 if (!empty($customFieldsKey)) {
127 137 add_filter('fluent_support/registration_form_fields', function($fields) use ($customFieldsKey) {
128 138 return $this->addCustomFieldsToRegistrationForm($fields,$customFieldsKey);
@@ -136,9 +146,8 @@
136 146
137 147 return $this->buildRegistrationForm($registrationFields, $hide, $attributes);
138 148 }
139 149
140 - // This method `buildRegistrationForm` will generate html for sign up form
141 150 private function buildRegistrationForm($registrationFields, $hide, $attributes)
142 151 {
143 152 $registrationForm = '<div class="fst_registration_wrapper ' . $hide . '"><form id="fstRegistrationForm" class="fs_registration_form" method="post" name="fs_registration_form">';
144 153
@@ -145,9 +154,9 @@
145 154 foreach ($registrationFields as $fieldName => $registrationField) {
146 155 $registrationForm .= $this->renderField($fieldName, $registrationField);
147 156 }
148 157
149 - $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']) . '">';
150 159 $registrationForm .= '<input type="hidden" name="_fsupport_signup_nonce" value="' . wp_create_nonce('fluent_support_signup_nonce') . '">';
151 160 $registrationForm .= '<button type="submit" id="fst_submit">' . $this->submitBtnLoadingSvg() . '<span>' . __('Signup', 'fluent-support') . '</span></button>';
152 161
153 162 $registrationForm .= '</form>';
@@ -175,9 +184,11 @@
175 184
176 185 $attributes = $this->getShortcodes($attributes);
177 186
178 187 if ($this->authProvider() == 'fluent_auth') {
179 - 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']);
180 191 }
181 192
182 193 $this->handleAlreadyLoggedIn($attributes);
183 194
@@ -188,9 +199,8 @@
188 199
189 200 return $this->buildResetPassForm($resetPasswordFields, $hide, $attributes);
190 201 }
191 202
192 - // This method `buildResetPassForm` will generate html for password reset form
193 203 private function buildResetPassForm($resetPasswordFields, $hide, $attributes)
194 204 {
195 205 $restePasswordForm = '<div class="fst_reset_pass_wrapper ' . $hide . '"><form id="fstResetPasswordForm" class="fs_reset_pass_form" method="post" name="fs_reset_pass_form">';
196 206
@@ -197,9 +207,9 @@
197 207 foreach ($resetPasswordFields as $fieldName => $resetPasswordField) {
198 208 $restePasswordForm .= $this->renderField($fieldName, $resetPasswordField);
199 209 }
200 210
201 - $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']) . '">';
202 212 $restePasswordForm .= '<input type="hidden" name="_fsupport_reset_pass_nonce" value="' . wp_create_nonce('fluent_support_reset_pass_nonce') . '">';
203 213 $restePasswordForm .= '<button type="submit" id="fst_reset_pass">' . $this->submitBtnLoadingSvg() . '<span>' . __('Reset Password', 'fluent-support') . '</span></button>';
204 214
205 215 $restePasswordForm .= '</form>';
@@ -209,9 +219,10 @@
209 219 return $restePasswordForm;
210 220 }
211 221
212 222 /**
213 - * 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 + *
214 225 * @param $attributes
215 226 * @return string
216 227 */
217 228 public function authForm($attributes)
@@ -223,9 +234,9 @@
223 234
224 235 $attributes = $this->getShortcodes($attributes, true);
225 236
226 237 if ($this->authProvider() == 'fluent_auth') {
227 - return (new \FluentAuth\App\Hooks\Handlers\CustomAuthHandler())->authForm($attributes);
238 + return $this->renderFluentAuthForms($attributes);
228 239 }
229 240
230 241 return $this->loginForm($attributes);
231 242 }
@@ -230,9 +241,37 @@
230 241 return $this->loginForm($attributes);
231 242 }
232 243
233 244 /**
234 - * renderField method will generate html for a field
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']);
271 + }
272 +
273 + /**
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)) {
@@ -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', []);
@@ -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 }
@@ -482,9 +519,9 @@
482 519
483 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
@@ -498,9 +535,15 @@
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;
@@ -541,9 +584,8 @@
541 584 }
542 585
543 586 wp_enqueue_script('fluent_support_login_helper', Vite::getEnqueuePath('portal/js/login_helper.js'), [], FLUENT_SUPPORT_VERSION);
544 587
545 - //Get Recaptcha settings and enqueue recaptcha script
546 588 $reCaptchaSettingsData = Meta::where('object_type', '_fs_recaptcha_settings')->first();
547 589 $reCaptchaData = ($reCaptchaSettingsData) ? Helper::safeUnserialize($reCaptchaSettingsData->value, []) : '';
548 590
549 591 if (!empty($reCaptchaData) && isset($reCaptchaData['is_enabled']) && $reCaptchaData['is_enabled'] == "true") {
@@ -577,9 +619,9 @@
577 619 public function maybeRenewNonce()
578 620 {
579 621 if (!PermissionManager::currentUserPermissions()) {
580 622 wp_send_json([
581 - 'error' => 'You do not have permission to do this'
623 + 'error' => __('You do not have permission to do this.', 'fluent-support')
582 624 ], 403);
583 625 }
584 626
585 627 wp_send_json([