PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.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
← All changes | Modules/Auth/Classes/InvitationHandler.php +56 -22 1.0.952.10.0 View file →
@@ -12,45 +12,55 @@
12 12 public function register()
13 13 {
14 14 add_filter('fluent_community/auth/invitation', function ($invitation, $token) {
15 15 return Invitation::where('message_rendered', $token)
16 - ->where('status', 'pending')
16 + ->whereIn('status', ['pending', 'active'])
17 17 ->first();
18 18 }, 10, 2);
19 19
20 - add_action('fluent_community/auth/show_inviration_for_user', [$this, 'showCommunityOnBoard'], 10, 2);
20 + add_action('fluent_community/auth/show_invitation_for_user', [$this, 'showCommunityOnBoard'], 10, 2);
21 21 add_action('wp_ajax_fcom_user_accept_invitation', [$this, 'acceptInvitationAjax']);
22 22 add_filter('fluent_community/auth/after_login_with_invitation', [$this, 'handleInvitationLogin'], 10, 3);
23 23 add_filter('fluent_community/auth/after_signup_redirect_url', function ($redirecctUrl, $user, $postedData) {
24 -
25 24 if (empty($postedData['invitation_token'])) {
26 25 return $redirecctUrl;
27 26 }
28 27
29 28 $invitation = Invitation::where('message_rendered', $postedData['invitation_token'])
30 - ->where('status', 'pending')
29 + ->whereIn('status', ['pending', 'active'])
31 30 ->first();
32 31
33 - if (!$invitation || !$user || $invitation->message != $user->user_email) {
32 + if (!$invitation || !$user || !$invitation->isValid()) {
34 33 return $redirecctUrl;
35 34 }
36 35
36 + if ($invitation->message && $invitation->message != $user->user_email) {
37 + return $redirecctUrl;
38 + }
39 +
37 40 if ($invitation->post_id) {
38 - $space = BaseSpace::find($invitation->post_id);
41 + $space = BaseSpace::withoutGlobalScopes()->find($invitation->post_id);
42 + /** @var BaseSpace|null $space */
39 43 if ($space) {
40 44 $role = 'member';
41 45 if ($space->type == 'course') {
42 46 $role = 'student';
43 47 }
44 - Helper::addToSpace($space, $user->ID, $role);
48 + $isNew = Helper::addToSpace($space, $user->ID, $role);
49 + if ($isNew && !$invitation->message) {
50 + $invitation->reactions_count = $invitation->reactions_count + 1;
51 + $invitation->save();
52 + }
53 +
54 + $redirecctUrl = $space->getPermalink();
45 55 }
56 + }
46 57
47 - $redirecctUrl = $space->getPermalink();
58 + if ($invitation->message) {
59 + $invitation->status = 'accepted';
60 + $invitation->save();
48 61 }
49 62
50 - $invitation->status = 'accepted';
51 - $invitation->save();
52 -
53 63 return $redirecctUrl;
54 64 }, 10, 3);
55 65 }
56 66
@@ -62,10 +72,21 @@
62 72 public function showCommunityOnBoard($invitation, $frameData)
63 73 {
64 74 $user = Helper::getCurrentUser();
65 75 $user->syncXProfile(false);
66 - $frameData['title'] = '';
67 - $frameData['description'] = sprintf(__('Welcome back %1s. %2s has been invited you to join the community. Please click the button bellow to continue.', 'fluent-community'), $user->display_name, $invitation->xprofile->display_name);
76 + $frameData['title'] = __('Accept Invitation', 'fluent-community');
77 +
78 + $space = BaseSpace::withoutGlobalScopes()->find($invitation->post_id);
79 +
80 + $spaceName = $space ? $space->title : __('the community', 'fluent-community');
81 +
82 + /* translators: %1$s is replaced by the name of the user, %2$s is replaced by the name of the inviter, %3$s is replaced by the name of the space */
83 + $frameData['description'] = \sprintf(__('Welcome back %1$s. %2$s has invited you to join in %3$s. Please click the button below to continue.', 'fluent-community'),
84 + $user->display_name,
85 + $invitation->xprofile ? $invitation->xprofile->display_name : __('Someone', 'fluent-community'),
86 + '<b>' . $spaceName . '</b>'
87 + );
88 +
68 89 $frameData['invitation_token'] = $invitation->message_rendered;
69 90
70 91 App::make('view')->render('auth.logged_in_accept', $frameData);
71 92 }
@@ -71,9 +92,15 @@
71 92 }
72 93
73 94 public function acceptInvitationAjax()
74 95 {
75 - $token = sanitize_text_field($_POST['invitation_token']);
96 + if (!check_ajax_referer('fcom_accept_invitation', '_fcom_accept_invitation_nonce', false)) {
97 + wp_send_json([
98 + 'message' => __('Invalid request', 'fluent-community')
99 + ], 403);
100 + }
101 +
102 + $token = isset($_POST['invitation_token']) ? sanitize_text_field(wp_unslash($_POST['invitation_token'])) : '';
76 103 $user = Helper::getCurrentUser();
77 104
78 105 $redirectUrl = $this->handleInvitationLogin(null, $user, $token);
79 106
@@ -84,9 +111,9 @@
84 111 }
85 112
86 113 wp_send_json([
87 114 'redirect_url' => $redirectUrl,
88 - 'message' => __('Invitation accepted successfully. Please wait....', 'fluent-community')
115 + 'message' => __('Invitation accepted successfully. Please wait...', 'fluent-community')
89 116 ]);
90 117 }
91 118
92 119 public function handleInvitationLogin($url, $user, $token)
@@ -93,13 +120,12 @@
93 120 {
94 121 $userModel = User::find($user->ID);
95 122
96 123 $invitation = Invitation::where('message_rendered', $token)
97 - ->where('status', 'pending')
124 + ->whereIn('status', ['pending', 'active'])
98 125 ->first();
99 126
100 -
101 - if (!$userModel || !$invitation || $invitation->message != $userModel->user_email) {
127 + if (!$userModel || !$invitation || !$invitation->isValid() || ($invitation->message && $invitation->message != $userModel->user_email)) {
102 128 return new \WP_Error('invalid_invitation', __('Invalid invitation token. Please try again', 'fluent-community'));
103 129 }
104 130
105 131 $userModel->syncXProfile(true);
@@ -105,20 +131,28 @@
105 131 $userModel->syncXProfile(true);
106 132
107 133 $space = null;
108 134 if ($invitation->post_id) {
109 - $space = BaseSpace::find($invitation->post_id);
135 + $space = BaseSpace::withoutGlobalScopes()->find($invitation->post_id);
136 + /** @var BaseSpace|null $space */
110 137 if ($space) {
111 138 $role = 'member';
112 139 if ($space->type == 'course') {
113 140 $role = 'student';
114 141 }
115 - Helper::addToSpace($space, $userModel->ID, $role);
142 + $isNew = Helper::addToSpace($space, $userModel->ID, $role);
143 +
144 + if ($isNew && !$invitation->message) {
145 + $invitation->reactions_count = $invitation->reactions_count + 1;
146 + $invitation->save();
147 + }
116 148 }
117 149 }
118 150
119 - $invitation->status = 'accepted';
120 - $invitation->save();
151 + if ($invitation->message) {
152 + $invitation->status = 'accepted';
153 + $invitation->save();
154 + }
121 155
122 156 $redirectUrl = Helper::baseUrl();
123 157 if ($space) {
124 158 $redirectUrl = $space->getPermalink();