PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.4.0
Fluent Support – Helpdesk & Customer Support Ticket System v1.4.0
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
fluent-support / app / Hooks / Handlers / AuthHandler.php

AuthHandler.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.4.0, at app/Hooks/Handlers/AuthHandler.php

211 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Hooks\Handlers;
4
5 use FluentSupport\App\App;
6 use FluentSupport\App\Services\Helper;
7 use FluentSupport\Framework\Support\Arr;
8
9 class AuthHandler
10 {
11
12 public function init()
13 {
14 add_shortcode('fluent_support_login', array($this, 'loginForm'));
15 add_shortcode('fluent_support_signup', array($this, 'registrationForm'));
16 add_shortcode('fluent_support_auth', array($this, 'authForm'));
17 }
18
19 public function loginForm($attributes)
20 {
21 $attributes = $this->getShortcodes($attributes);
22 $this->handleAlreadyLoggedIn($attributes);
23
24 $app = App::getInstance();
25 $assets = $app['url.assets'];
26 wp_enqueue_style('fluent_support_login_style', $assets . 'admin/css/all_public.css');
27 wp_enqueue_script('fluent_support_login_helper', $assets . 'portal/js/login_helper.js');
28 $return = '<div class="fst_login_wrapper">';
29
30 $loginArgs = apply_filters('fluent_support/login_form_args', [
31 'echo' => false,
32 'redirect' => Helper::getPortalBaseUrl(),
33 'remember' => true,
34 'value_remember' => true
35 ]);
36
37 $return .= wp_login_form($loginArgs);
38 $return .= '</div>';
39 return $return;
40 }
41
42 public function registrationForm($attributes)
43 {
44 $attributes = $this->getShortcodes($attributes);
45 $this->handleAlreadyLoggedIn($attributes);
46
47 $app = App::getInstance();
48 $assets = $app['url.assets'];
49 wp_enqueue_style('fluent_support_login_style', $assets . 'admin/css/all_public.css');
50 wp_enqueue_script('fluent_support_login_helper', $assets . 'portal/js/login_helper.js');
51
52 wp_localize_script('fluent_support_login_helper', 'fluentSupportPublic', [
53 'signup' => rest_url($app->config->get('app.rest_namespace') . '/' . $app->config->get('app.rest_version')) . '/signup'
54 ]);
55
56 $registrationFields = static::getSignupFields();
57
58 $registrationForm = '<div class="fst_registration_wrapper"><form id="fstRegistrationForm" class="fs_registration_form" method="post" name="fs_registration_form">';
59
60 foreach ($registrationFields as $fieldName => $registrationField) {
61 $registrationForm .= $this->renderField($fieldName, $registrationField);
62 }
63
64 $registrationForm .= '<input type="hidden" name="__redirect_to" value="' . $attributes['redirect-to'] . '">';
65 $registrationForm .= '<button type="submit" id="fst_submit">' . $this->submitBtnLoadingSvg() . '<span>' . __('Signup', 'fluent-support') . '</span></button>';
66
67 $registrationForm .= '</form></div>';
68
69 return $registrationForm;
70 }
71
72 public function authForm($attributes)
73 {
74 $authForm = '<div class="fst_auth_wrapper">';
75
76 $authForm .= do_shortcode('[fluent_support_login]');
77 $authForm .= do_shortcode('[fluent_support_signup]');
78
79 $authForm .= '</div>';
80
81 return $authForm;
82 }
83
84 private function renderField($fieldName, $field)
85 {
86 $fieldType = Arr::get($field, 'type');
87 $isRequired = Arr::get($field, 'required');
88 $isRequired = $isRequired ? 'is-required' : '';
89
90 $textTypes = ['text', 'email', 'password'];
91
92 $html = '<div class="fst_field_group fst_field_'.$fieldName.'">';
93 if($label = Arr::get($field, 'label')) {
94 $html .= '<div class="fst_field_label ' . $isRequired . '"><label for="'.Arr::get($field, 'id').'">'.$label.'</label></div>';
95 }
96
97 if(in_array($fieldType, $textTypes)) {
98
99 $inputAtts = array_filter([
100 'type' => esc_attr($fieldType),
101 'id' => esc_attr(Arr::get($field, 'id')),
102 'placeholder' => esc_attr(Arr::get($field, 'placeholder')),
103 'name' => esc_attr($fieldName)
104 ]);
105
106 $atts = '';
107
108 foreach ($inputAtts as $attKey => $att) {
109 $atts .= $attKey.'="'.$att.'" ';
110 }
111
112 if(Arr::get($field, 'required')) {
113 $atts .= 'required';
114 }
115
116 $html .= '<div class="fs_input_wrap"><input '.$atts.'/></div>';
117 } else {
118 return '';
119 }
120
121 return $html.'</div>';
122 }
123
124 public static function getSignupFields()
125 {
126 return apply_filters('fluent_support/registration_form_fields', [
127 'first_name' => [
128 'required' => true,
129 'type' => 'text',
130 'label' => __('First name', 'fluent-support'),
131 'id' => 'fst_first_name',
132 'placeholder' => __('First name', 'fluent-support')
133 ],
134 'last_name' => [
135 'type' => 'text',
136 'label' => __('Last Name', 'fluent-support'),
137 'id' => 'fst_last_name',
138 'placeholder' => __('Last name', 'fluent-support')
139 ],
140 'username' => [
141 'required' => true,
142 'type' => 'text',
143 'label' => __('Username', 'fluent-support'),
144 'id' => 'fst_username',
145 'placeholder' => __('Username', 'fluent-support')
146 ],
147 'email' => [
148 'required' => true,
149 'type' => 'email',
150 'label' => __('Email Address', 'fluent-support'),
151 'id' => 'fst_email',
152 'placeholder' => __('Your Email Address', 'fluent-support')
153 ],
154 'password' => [
155 'required' => true,
156 'type' => 'password',
157 'label' => __('Password', 'fluent-support'),
158 'id' => 'fst_password',
159 'placeholder' => __('Password', 'fluent-support')
160 ]
161 ]);
162 }
163
164 protected function submitBtnLoadingSvg()
165 {
166 $loadingIcon = '<svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
167 width="40px" height="20px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve">
168 <path fill="#000" d="M43.935,25.145c0-10.318-8.364-18.683-18.683-18.683c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615c8.072,0,14.615,6.543,14.615,14.615H43.935z">
169 <animateTransform attributeType="xml"
170 attributeName="transform"
171 type="rotate"
172 from="0 25 25"
173 to="360 25 25"
174 dur="0.6s"
175 repeatCount="indefinite"/>
176 </path>
177 </svg>';
178
179 return apply_filters('fluent-support/signup_loading_icon', $loadingIcon);
180 }
181
182 protected function getShortcodes($attributes)
183 {
184 $shortCodeDefaults = apply_filters('fluent-support/auth_shortcode_defaults', [
185 'auto-redirect' => false,
186 'redirect-to' => Helper::getPortalBaseUrl()
187 ]);
188
189 return shortcode_atts($shortCodeDefaults, $attributes);
190 }
191
192 protected function handleAlreadyLoggedIn($attributes)
193 {
194 if (get_current_user_id() && !wp_is_json_request() && is_singular()) {
195 if ($attributes['auto-redirect'] === 'true') {
196 $redirect = $attributes['redirect-to'];
197 ?>
198 <script type="text/javascript">
199 document.addEventListener("DOMContentLoaded", function() {
200 var redirect = "<?php echo $redirect; ?>";
201 window.location.replace(redirect);
202 });
203 </script>
204 <?php
205 }
206
207 die();
208 }
209 }
210 }
211