PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.1.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.1.0
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / Modules / Auth / AuthModdule.php

AuthModdule.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 1.1.0, at Modules/Auth/AuthModdule.php

653 lines 26.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace FluentCommunity\Modules\Auth;
5
6 use FluentAuth\App\Hooks\Handlers\CustomAuthHandler;
7 use FluentCommunity\App\App;
8 use FluentCommunity\App\Services\AuthenticationService;
9 use FluentCommunity\App\Models\BaseSpace;
10 use FluentCommunity\App\Models\User;
11 use FluentCommunity\App\Services\Helper;
12 use FluentCommunity\App\Services\ProfileHelper;
13 use FluentCommunity\App\Vite;
14 use FluentCommunity\Framework\Support\Arr;
15 use FluentCommunity\Modules\Auth\Classes\InvitationService;
16
17 class AuthModdule
18 {
19 public function register($app)
20 {
21 add_action('fluent_community/portal_action_signed_url', [$this, 'maybeAutoLogin'], 10, 1);
22 add_action('fluent_community/portal_action_auth', [$this, 'viewAuthPage']);
23 add_action('wp_ajax_nopriv_fcom_user_registration', [$this, 'handleUserSignup']);
24 add_action('wp_ajax_fcom_user_registration', [$this, 'handleUserSignup']);
25 add_action('wp_ajax_nopriv_fcom_user_login_form', [$this, 'handleUserLogin']);
26 add_action('wp_ajax_fcom_user_login_form', [$this, 'handleUserLogin']);
27
28 add_filter('fluent_auth/login_redirect_url', function ($redirectUrl, $user) {
29 if (empty($_REQUEST['is_fcom_auth']) || empty($_REQUEST['fcom_redirect'])) {
30 return $redirectUrl;
31 }
32
33 // validate the url
34 $redirectUrl = $_REQUEST['fcom_redirect'];
35 if (!filter_var($redirectUrl, FILTER_VALIDATE_URL)) {
36 $redirectUrl = Helper::baseUrl();
37 }
38
39 $redirectUrl = apply_filters('fluent_community/auth/after_login_redirect_url', $redirectUrl, $user);
40 return $redirectUrl;
41 }, 10, 2);
42
43 add_filter('login_form_defaults', function ($defaults) {
44 $defaults['label_username'] = __('Email Address', 'fluent-community');
45 return $defaults;
46 });
47
48 }
49
50 public function maybeAutoLogin($requestData)
51 {
52 $urlHash = Arr::get($requestData, 'fcom_url_hash');
53 if ($urlHash) {
54 $tagetUser = ProfileHelper::getUserByUrlHash($urlHash);
55
56 if ($tagetUser) {
57 $willAtoLogin = apply_filters('fluent_community/allow_auto_login_by_url', !user_can($tagetUser, 'delete_pages'), $tagetUser);
58 // $willAtoLogin = true;
59 if ($willAtoLogin) {
60 InvitationService::makeLogin($tagetUser);
61 }
62 }
63 }
64
65 // Remove fcom_action and fcom_url_hash from the current url
66 $currentUrl = home_url(add_query_arg($_GET, $GLOBALS['wp']->request));
67 $url = remove_query_arg(['fcom_action', 'fcom_url_hash'], $currentUrl);
68 wp_redirect($url);
69 exit();
70 }
71
72 public function viewAuthPage()
73 {
74 $currentUserId = get_current_user_id();
75 // check if there has any invitation token
76 $inivtationToken = Arr::get($_GET, 'invitation_token');
77
78 $inviation = null;
79 if ($inivtationToken) {
80 $inviation = apply_filters('fluent_community/auth/invitation', null, $inivtationToken);
81 }
82
83 if ($currentUserId && !$inviation) {
84 wp_redirect(Helper::baseUrl());
85 exit();
86 }
87
88 do_action('fluent_community/auth/before_auth_page_process', $currentUserId, $inviation);
89
90 $acceptedForms = ['login', 'register', 'reset_password'];
91 $targetForm = Arr::get($_GET, 'form');
92 if (!in_array($targetForm, $acceptedForms)) {
93 $targetForm = 'login';
94 }
95
96 if ($inviation && $targetForm != 'reset_password') {
97 $isUserAvailable = get_user_by('email', $inviation->message);
98 $targetForm = $isUserAvailable ? 'login' : 'register';
99 }
100
101 if ($inviation && $currentUserId) {
102 $invitedUser = get_user_by('email', $inviation->message);
103 if ($invitedUser && $invitedUser->ID == $currentUserId) {
104 $targetForm = 'accept_invitation';
105 }
106 }
107
108 $isFluentAuth = AuthHelper::isFluentAuthAvailable();
109 if (!$isFluentAuth && $targetForm == 'reset_password') {
110 wp_redirect(wp_lostpassword_url(Helper::baseUrl()));
111 exit();
112 }
113
114 $portalSettings = Helper::generalSettings();
115 $titleVar = Arr::get($portalSettings, 'site_title');
116
117 $frameData = [
118 'logo' => Arr::get($portalSettings, 'logo', ''),
119 'title' => sprintf(__('Join %s', 'fluent-community'), $titleVar),
120 'description' => __('Login or Signup to join the community', 'fluent-community'),
121 'loginBtnText' => __('Login', 'fluent-community'),
122 'signupBtnText' => __('Signup', 'fluent-community'),
123 ];
124
125 $currentUrl = home_url(add_query_arg($_GET, $GLOBALS['wp']->request));
126
127 $pageVars = [
128 'title' => $frameData['title'],
129 'description' => $frameData['description'],
130 'url' => $currentUrl,
131 'featured_image' => '',
132 'css_files' => [
133 Vite::getDynamicSrcUrl('theme-default.scss'),
134 Vite::getStaticSrcUrl('user_registration.css')
135 ],
136 'js_files' => [
137 Vite::getStaticSrcUrl('public/js/user_registration.js')
138 ],
139 'js_vars' => [
140 'fluentComRegistration' => [
141 'ajax_url' => admin_url('admin-ajax.php'),
142 'is_logged_in' => is_user_logged_in(),
143 ]
144 ],
145 'scope' => 'user_registration',
146 'layout' => 'signup',
147 'portal' => [
148 'logo' => Arr::get($portalSettings, 'logo', ''),
149 'title' => \sprintf( __('Welcome to %s', 'fluent-community'), Arr::get($portalSettings, 'site_title') ),
150 'description' => get_bloginfo('description')
151 ]
152 ];
153
154 if ($isFluentAuth) {
155 $pageVars['js_files'][] = FLUENT_AUTH_PLUGIN_URL . 'dist/public/login_helper.js';
156 $pageVars['js_vars']['fluentAuthPublic'] = [
157 'hide' => false,
158 'redirect_fallback' => site_url(),
159 'fls_login_nonce' => wp_create_nonce('fsecurity_login_nonce'),
160 'ajax_url' => admin_url('admin-ajax.php'),
161 'i18n' => [
162 'Username_or_Email' => __('Email Address', 'fluent-community'),
163 'Password' => __('Password', 'fluent-community')
164 ]
165 ];
166 }
167
168 $formType = ($targetForm == 'login') ? 'login' : 'signup';
169 $formSettings = AuthenticationService::getFormattedAuthSettings($formType);
170
171 if ($formSettings) {
172 $pageVars['portal'] = Arr::get($formSettings, 'banner');
173 $pageVars['portal']['form'] = Arr::get($formSettings, 'form');
174 }
175
176 add_action('fluent_community/headless/content', function ($context) use ($targetForm, $currentUrl, $frameData, $inviation, $formSettings) {
177 if ($targetForm == 'login') {
178 $this->showLoginForm($frameData, $inviation);
179 } else if ($targetForm == 'reset_password') {
180 $frameData['title'] = __('Reset your password', 'fluent-community');
181 ?>
182 <div id="fcom_user_onboard_wrap" class="fcom_user_onboard">
183 <div class="fcom_onboard_header">
184 <div class="fcom_onboard_header_title">
185 <h2><?php echo esc_html($frameData['title']); ?></h2>
186 </div>
187 </div>
188 <div class="fcom_onboard_body">
189 <div class="fcom_onboard_form">
190 <?php echo do_shortcode('[fluent_auth_reset_password redirect_to="' . esc_url($currentUrl) . '"]'); ?>
191 <div class="fcom_spaced_divider">
192 <div class="fcom_alt_auth_text">
193 <a href="<?php echo esc_url(add_query_arg('form', 'login', $currentUrl)); ?>">
194 <?php _e('Back to Login', 'fluent-community'); ?>
195 </a>
196 </div>
197 </div>
198 </div>
199 </div>
200 </div>
201 <?php
202 } else if ($targetForm == 'accept_invitation') {
203 do_action('fluent_community/auth/show_invitation_for_user', $inviation, $frameData);
204 } else {
205 //check if the registration is disabled
206 if (!AuthHelper::isRegistrationEnabled()) {
207 echo '<div class="fcom_completed"><div class="fcom_complted_header"><h4>' . __('Registration is disabled for this community', 'fluent-community') . '</h4>';
208 return;
209 }
210
211 $frameData['hiddenFields'] = [
212 'register' => 'yes',
213 'action' => 'fcom_user_signup',
214 '_fls_signup_nonce' => wp_create_nonce('fluent_auth_signup_nonce')
215 ];
216
217 $frameData['loginUrl'] = add_query_arg('form', 'login', $currentUrl);
218 $frameData = wp_parse_args(Arr::get($formSettings, 'form'), $frameData);
219
220 $this->renderRegistrationForm($frameData, $inviation);
221 }
222 }, 10, 1);
223
224 status_header(200);
225 App::make('view')->render('headless_page', $pageVars);
226 exit(200);
227 }
228
229 public function handleUserSignup()
230 {
231 if (is_user_logged_in()) {
232 return $this->handleSignupCompleted(get_current_user_id());
233 }
234
235 if (!AuthHelper::isRegistrationEnabled()) {
236 wp_send_json([
237 'message' => __('Registration is disabled for this community', 'fluent-community')
238 ], 422);
239 }
240
241 $app = App::make('app');
242 $request = $app->make('request');
243 $fields = AuthHelper::getFormFields();
244
245 $requiredFields = array_filter($fields, function ($field) {
246 return $field['required'] ?? false;
247 });
248
249 $keys = array_keys($fields);
250 $data = Arr::only($request->all(), $keys);
251
252 // remove space and special characters from username
253 $data['username'] = sanitize_user(strtolower(preg_replace('/[^A-Za-z0-9_]/', '', $data['username'])));
254
255 if (empty($data['username'])) {
256 wp_send_json([
257 'message' => __('Username is not valid', 'fluent-community'),
258 'errors' => [
259 'username' => __('Please provide a valid username', 'fluent-community')
260 ]
261 ], 422);
262 }
263
264 if (!ProfileHelper::isUsernameAvailable($data['username'])) {
265 wp_send_json([
266 'message' => __('Username is already taken', 'fluent-community'),
267 'errors' => [
268 'username' => __('Username is already taken. Please use a different username', 'fluent-community')
269 ]
270 ], 422);
271 }
272
273 $data['email'] = sanitize_email($data['email']);
274
275 $validations = [
276 'full_name' => 'required|max:100|string',
277 'username' => 'required|unique:users,user_login|unique:fcom_xprofile,username|min:4|max:30',
278 'email' => 'required|email|unique:users,user_email',
279 'password' => 'required|same:conf_password|max:50|string',
280 'conf_password' => 'required|same:password'
281 ];
282
283 if (!AuthHelper::isPasswordConfRequired()) {
284 unset($validations['conf_password']);
285 $validations['password'] = 'required|max:50|string';
286 }
287
288 foreach ($requiredFields as $key => $field) {
289 if (!isset($data[$key])) {
290 $validations[$key] = 'required';
291 }
292 }
293
294 $validator = $app->make('validator')->make($data, $validations, [
295 'username.required' => __('Username is required', 'fluent-community'),
296 'username.unique' => __('Username is already taken', 'fluent-community'),
297 'email.required' => __('Email is required', 'fluent-community'),
298 'email.email' => __('Email is not valid', 'fluent-community'),
299 'email.unique' => __('Email is already taken', 'fluent-community'),
300 'password.required' => __('Password is required', 'fluent-community'),
301 'password.same' => __('Password and confirmation password do not match', 'fluent-community'),
302 'conf_password.required' => __('Password confirmation is required', 'fluent-community'),
303 'conf_password.same' => __('Password and confirmation password do not match', 'fluent-community'),
304 'terms.required' => __('You must agree to the terms and conditions', 'fluent-community'),
305 'full_name.required' => __('Full name is required', 'fluent-community'),
306 ]);
307
308 if ($validator->fails()) {
309 wp_send_json([
310 'message' => __('Please fill in all required fields correctly.', 'fluent-community'),
311 'errors' => $validator->errors()
312 ], 422);
313 }
314
315 foreach ($data as $key => $value) {
316 // let's sanitize the data
317 $callBack = $fields[$key]['sanitize_callback'] ?? null;
318 if ($callBack) {
319 $data[$key] = call_user_func($callBack, $value);
320 }
321 }
322
323 // let's extract the full_name and set the first_name and last_name
324 if (!empty($data['full_name'])) {
325 $nameParts = explode(' ', $data['full_name']);
326 $data['first_name'] = $nameParts[0];
327 $data['last_name'] = implode(' ', array_slice($nameParts, 1));
328 unset($data['full_name']);
329 $data = array_filter($data);
330 }
331
332 if (AuthHelper::isFluentAuthAvailable()) {
333 $data = wp_parse_args($data, $request->all());
334 $this->handleSignupViaFlentAuth($data);
335 wp_send_json([
336 'message' => __('Something is not working! Please try again', 'fluent-community')
337 ], 422);
338 }
339
340 $rateLimit = AuthHelper::isAuthRateLimit();
341
342 if (is_wp_error($rateLimit)) {
343 wp_send_json([
344 'message' => $rateLimit->get_error_message()
345 ], 422);
346 }
347
348 // We need two-factor authentication here
349 if (AuthHelper::isTwoFactorEnabled()) {
350 // Check if Two Factor code is given
351 $verificationToken = $request->get('__two_fa_signed_token');
352 if ($verificationToken) {
353 $code = $request->get('_email_verification_code');
354 if (!$code) {
355 wp_send_json([
356 'message' => __('Verification code is required', 'fluent-community')
357 ], 422);
358 }
359
360 $validated = AuthHelper::validateVerificationCode($code, $verificationToken, $data);
361 if (is_wp_error($validated)) {
362 wp_send_json([
363 'message' => $validated->get_error_message()
364 ], 422);
365 }
366 } else {
367 // Let's send the verification code
368 $htmlForm = AuthHelper::get2FaRegistrationCodeForm($data);
369 wp_send_json([
370 'verifcation_html' => $htmlForm
371 ]);
372 }
373 }
374
375 // let's create the user now
376 $userId = AuthHelper::registerNewUser($data['username'], $data['email'], $data['password'], [
377 'first_name' => Arr::get($data, 'first_name'),
378 'last_name' => Arr::get($data, 'last_name'),
379 'role' => get_option('default_role', 'subscriber')
380 ]);
381
382 if (is_wp_error($userId)) {
383 wp_send_json([
384 'message' => $userId->get_error_message()
385 ], 422);
386 }
387
388 $this->handleSignupCompleted($userId);
389 }
390
391 private function handleSignupViaFlentAuth($data)
392 {
393 add_filter('fluent_auth/signup_form_data', function ($requestData) use ($data) {
394 return $data;
395 });
396
397 add_action('fluent_auth/after_creating_user', function ($userId) {
398 $this->handleSignupCompleted($userId);
399 }, 1, 1);
400
401 (new CustomAuthHandler())->handleSignupAjax();
402 }
403
404 private function handleSignupCompleted($userId)
405 {
406 // We have the user now let's set the community membership
407 $user = User::find($userId);
408 $user->syncXProfile(true, true);
409
410 $redirectUrl = Helper::baseUrl();
411
412 $redirectUrl = apply_filters('fluent_community/auth/after_signup_redirect_url', $redirectUrl, $user, $_REQUEST);
413 $btnText = __('Continue to the community', 'fluent-community');
414
415 $html = '<div class="fcom_completed"><div class="fcom_complted_header"><h2>' . __('Congratulations!', 'fluent-community') . '</h2>';
416 $html .= '<p>' . __('You have successfully registered to the community', 'fluent-community') . '</p></div>';
417 $html .= '<a href="' . $redirectUrl . '" class="fcom_btn fcom_btn_success">' . $btnText . '</a>';
418 $html .= '</div>';
419
420 if (!get_current_user_id()) {
421 $wpUser = get_user_by('ID', $userId);
422 AuthHelper::makeLogin($wpUser);
423 }
424
425 wp_send_json([
426 'success_html' => $html,
427 'redirect_url' => $redirectUrl
428 ]);
429 }
430
431 public function handleUserLogin()
432 {
433 if (is_user_logged_in()) {
434 $user = get_user_by('ID', get_current_user_id());
435 return $this->handleUserLoginSuccess($user);
436 }
437
438 if (AuthHelper::isFluentAuthAvailable()) {
439 wp_send_json([
440 'message' => __('This form cannot be used to log in. Please reload the page and try again.', 'fluent-community')
441 ], 422);
442 }
443
444 $app = App::make('app');
445 $request = $app->make('request');
446
447 $data = $request->all();
448
449 $validator = $app->make('validator')->make($data, [
450 'log' => 'required',
451 'pwd' => 'required'
452 ], [
453 'log.required' => __('Email is required', 'fluent-community'),
454 'pwd.required' => __('Password is required', 'fluent-community')
455 ]);
456
457 if ($validator->fails()) {
458 wp_send_json([
459 'message' => __('Please fill all the required fields correctly', 'fluent-community'),
460 'errors' => $validator->errors()
461 ], 422);
462 }
463
464 $rateLimit = AuthHelper::isAuthRateLimit();
465 if (is_wp_error($rateLimit)) {
466 wp_send_json([
467 'message' => $rateLimit->get_error_message()
468 ], 422);
469 }
470
471 $user = wp_authenticate($data['log'], $data['pwd']);
472
473 if (is_wp_error($user)) {
474 wp_send_json([
475 'message' => $user->get_error_message()
476 ], 422);
477 }
478
479 InvitationService::makeLogin($user);
480
481 $redirectUrl = null;
482 if (!empty($_REQUEST['redirect_to'])) {
483 $redirectUrl = sanitize_url($_REQUEST['redirect_to']);
484 }
485
486 if (!$redirectUrl) {
487 $redirectUrl = Helper::baseUrl();
488 }
489
490 if ($invitationToken = $request->get('invitation_token')) {
491 $maybeRedirectUrl = apply_filters('fluent_community/auth/after_login_with_invitation', null, $user, $invitationToken);
492 if ($maybeRedirectUrl && !is_wp_error($maybeRedirectUrl)) {
493 $redirectUrl = $maybeRedirectUrl;
494 }
495 }
496
497 $this->handleUserLoginSuccess($user, $redirectUrl);
498 }
499
500 private function handleUserLoginSuccess($user, $redirectUrl = null)
501 {
502 if (!$redirectUrl) {
503 $redirectUrl = Helper::baseUrl();
504 }
505
506 $redirectUrl = apply_filters('fluent_community/auth/after_login_redirect_url', $redirectUrl, $user);
507 $btnText = __('Continue to the community', 'fluent-community');
508
509 $html = '<div class="fcom_completed"><div class="fcom_complted_header"><h2>' . __('Welcome back!', 'fluent-community') . '</h2>';
510 $html .= '<p>' . __('You have successfully logged in to the community', 'fluent-community') . '</p></div>';
511 $html .= '<a href="' . $redirectUrl . '" class="fcom_btn fcom_btn_success">' . $btnText . '</a>';
512 $html .= '</div>';
513
514 wp_send_json([
515 'success_html' => $html,
516 'redirect_url' => $redirectUrl
517 ]);
518 }
519
520 public function showLoginForm($frameData, $invitation = null)
521 {
522 $portalSettings = Helper::generalSettings();
523 $isFluentAuth = AuthHelper::isFluentAuthAvailable();
524 $loginSettings = AuthenticationService::getFormattedAuthSettings('login');
525 $formSettings = Arr::get($loginSettings, 'form');
526 $currentUrl = home_url(add_query_arg($_GET, $GLOBALS['wp']->request));
527 $title = sprintf(__('Login to %s', 'fluent-community'), Arr::get($portalSettings, 'site_title'));
528
529 $description = '';
530 if ($invitation) {
531 $invitationBy = $invitation->xprofile ? $invitation->xprofile->display_name : __('Someone', 'fluent-community');
532 if ($invitation->post_id) {
533 $space = BaseSpace::find($invitation->post_id);
534 if ($space) {
535 $title = $space->title . ' - ' . Arr::get($portalSettings, 'site_title');
536 }
537 }
538 $description = sprintf(__('%s has invited you to join this community. Please login to accept your invitation.', 'fluent-community'), $invitationBy);
539 }
540
541 if ($isFluentAuth) {
542 add_filter('login_form_top', function () {
543 $reditectUrl = Arr::get($_GET, 'redirect_to');
544 if (!$reditectUrl) {
545 $reditectUrl = apply_filters('fluent_community/default_redirect_url', $reditectUrl);
546 }
547 ob_start();
548 ?>
549 <input name="is_fcom_auth" type="hidden" value="yes"/>
550 <input type="hidden" name="fcom_redirect" value="<?php echo esc_url($reditectUrl); ?>"/>
551 <?php
552 return ob_get_clean();
553 });
554
555 ?>
556 <div id="fcom_user_onboard_wrap" class="fcom_user_onboard">
557 <div class="fcom_onboard_header">
558 <div class="fcom_onboard_header_title">
559 <?php if (!empty($formSettings['title'])): ?>
560 <h2 style="color: <?php echo esc_attr($formSettings['title_color']); ?>;">
561 <?php echo esc_html($formSettings['title']); ?>
562 </h2>
563 <?php endif; ?>
564 </div>
565 <?php if (!empty($formSettings['description'])): ?>
566 <div class="fcom_onboard_sub">
567 <p style="color: <?php echo esc_attr($formSettings['text_color']); ?>;">
568 <?php echo wp_kses_post($formSettings['description']); ?>
569 </p>
570 </div>
571 <?php endif; ?>
572 </div>
573 <div class="fcom_onboard_body">
574 <div class="fcom_onboard_form">
575 <?php echo do_shortcode('[fluent_auth_login redirect_to="' . esc_url($currentUrl) . '"]'); ?>
576 <div class="fcom_spaced_divider">
577 <?php if (AuthHelper::isRegistrationEnabled()): ?>
578 <div class="fcom_alt_auth_text">
579 <?php _e('Don\'t have an account?', 'fluent-community'); ?>
580 <a href="<?php echo esc_url(add_query_arg('form', 'register', $currentUrl)); ?>">
581 <?php _e('Signup', 'fluent-community'); ?>
582 </a>
583 </div>
584 <?php endif; ?>
585 <p class="fcom_reset_pass_text">
586 <a href="<?php echo esc_url(add_query_arg('form', 'reset_password', $currentUrl)); ?>">
587 <?php _e('Lost your password?', 'fluent-community'); ?>
588 </a>
589 </p>
590 </div>
591 </div>
592 </div>
593 </div>
594 <?php
595 return;
596 }
597
598 $frameData['redirect'] = $currentUrl;
599
600 $frameData['hiddenFields'] = [];
601 if ($invitation) {
602 $frameData['loginBtnText'] = __('Log In & Accept Invitation', 'fluent-community');
603 $frameData['hiddenFields']['invitation_token'] = $invitation->message_rendered;
604 }
605
606 $frameData['title'] = $title;
607 $frameData['description'] = $description;
608
609 $frameData['defaults'] = [
610 'email' => $invitation ? $invitation->message : ''
611 ];
612
613 if (AuthHelper::isRegistrationEnabled()) {
614 $frameData['signupUrl'] = add_query_arg('form', 'register', $currentUrl);
615 }
616
617 $frameData['settings'] = $formSettings;
618
619 if (isset($_GET['redirect_to'])) {
620 $frameData['redirect_to'] = sanitize_url($_GET['redirect_to']);
621 }
622
623 App::make('view')->render('auth.login_form', $frameData);
624 }
625
626 public function renderRegistrationForm($frameData, $invitation = null)
627 {
628 $formFields = AuthHelper::getFormFields($invitation);
629
630 $frameData['formFields'] = $formFields;
631
632 if ($invitation) {
633 $frameData['hiddenFields'] = [
634 'invitation_token' => $invitation->message_rendered,
635 'action' => 'fcom_user_registration',
636 '_fls_signup_nonce' => wp_create_nonce('fluent_auth_signup_nonce')
637 ];
638
639 $invitationBy = $invitation->xprofile ? $invitation->xprofile->display_name : __('Someone', 'fluent-community');
640 $frameData['description'] = sprintf(__('%s has invited you to join this community. Please create an account to accept your invitation.', 'fluent-community'), $invitationBy);
641 $frameData['signupBtnText'] = __('Register & Accept invitation', 'fluent-community');
642 } else {
643 $frameData['hiddenFields'] = [
644 'register' => 'yes',
645 'action' => 'fcom_user_registration',
646 '_fls_signup_nonce' => wp_create_nonce('fluent_auth_signup_nonce')
647 ];
648 }
649
650 App::make('view')->render('auth.user_invitation', $frameData);
651 }
652 }
653