PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 2.2.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v2.2.2
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
← All changes | includes/API/Login.php +18 -143 3.7.22.2.2 View file →
@@ -13,16 +13,8 @@
13 13 if ( '/templately/v1/login' === $_route ) {
14 14 return true;
15 15 }
16 16
17 - if ( '/templately/v1/pricing' === $_route ) {
18 - return true;
19 - }
20 -
21 - if ( '/templately/v1/google-auth-url' === $_route ) {
22 - return true;
23 - }
24 -
25 17 return parent::permission_check( $request );
26 18 }
27 19
28 20 public function register_routes() {
@@ -28,44 +20,10 @@
28 20 public function register_routes() {
29 21 $this->post( 'login', [$this, 'login'] );
30 22 $this->post( 'logout', [$this, 'logout'] );
31 23 $this->get( 'is-signed', [$this, 'is_signed'] );
32 - $this->get( 'pricing', [$this, 'pricing'] );
33 - $this->get( 'google-auth-url', [$this, 'google_auth_url'] );
34 24 }
35 25
36 - public function google_auth_url() {
37 - // Get redirect_to parameter from request if provided
38 - $redirect_to = $this->get_param( 'redirect-to', '' );
39 -
40 - // Use client-provided current_url instead of HTTP_REFERER for reliability
41 - $current_url = $this->get_param( 'current_url', '' );
42 -
43 - $url = $this->http()->google_auth_url( $redirect_to, $current_url );
44 - return [
45 - 'status' => 'success',
46 - 'url' => $url
47 - ];
48 - }
49 -
50 - public function pricing(){
51 - $data = get_transient( "templately_subscriptions" );
52 -
53 - if( is_array( $data ) && ! empty( $data ) ) {
54 - return $data;
55 - }
56 -
57 - $query = 'id, price, name, discounted_price, type, sites, coupon';
58 - $response = $this->http()->query(
59 - 'subscriptionPlans',
60 - $query
61 - )->post();
62 -
63 - set_transient( "templately_subscriptions", $response, WEEK_IN_SECONDS );
64 -
65 - return $response;
66 - }
67 -
68 26 public function login() {
69 27 $errors = [];
70 28 $_ip = Helper::get_ip();
71 29 $_site_url = home_url( '/' );
@@ -79,10 +37,8 @@
79 37 'ip' => $_ip,
80 38 'site_url' => $_site_url
81 39 ];
82 40
83 - $postArgs = [];
84 -
85 41 if ( $viaAPI ) {
86 42 $api_key = $this->get_param( 'api_key' );
87 43 $funcArgs['api_key'] = $api_key;
88 44
@@ -105,46 +61,20 @@
105 61 if ( ! empty( $errors ) ) {
106 62 return $this->error( 'login_error', $errors, 'login', 400 );
107 63 }
108 64
109 - $query = 'status, message, user{ id, name, first_name, last_name, display_name, email, profile_photo, joined, is_verified, is_company_user, api_key, plan, plan_expire_at, my_cloud{ limit, usages, last_pushed }, favourites{ id, type }, show_notice, reviews{ type, type_id, rating }, subscription { id, name, sites } }';
65 + $query = 'status, message, user{ id, name, first_name, last_name, display_name, email, profile_photo, joined, is_verified, api_key, plan, plan_expire_at, my_cloud{ limit, usages, last_pushed }, favourites{ id, type }, show_notice }';
110 66
111 67 $response = $this->http()->mutation(
112 68 $viaAPI ? 'connectWithApiKey' : 'connect',
113 69 $query,
114 70 $funcArgs
115 - )->post($postArgs);
71 + )->post();
116 72
117 73 if ( is_wp_error( $response ) ) {
118 74 return $response;
119 75 }
120 76
121 - if ( empty( $response['user']['api_key'] ) ) {
122 - return $this->error( 'login_error', $response['message'] ?? __('Invalid API key.', 'templately'), 'login', 400 );
123 - }
124 -
125 - $options = $this->utils( 'options' );
126 - $options->use_current_user( true );
127 -
128 - try {
129 - return $this->store_connection( $response, $global_signin, $_ip, $_site_url );
130 - } finally {
131 - $options->use_current_user( false );
132 - }
133 - }
134 -
135 - /**
136 - * Persist an authenticated connection against the acting user.
137 - *
138 - * @param array $response Cloud response, already validated.
139 - * @param bool $global_signin Whether the user asked to sign in globally.
140 - * @param string $_ip Request IP, echoed back into the profile.
141 - * @param string $_site_url Site URL, echoed back into the profile.
142 - *
143 - * @return array
144 - */
145 - private function store_connection( $response, $global_signin, $_ip, $_site_url ) {
146 -
147 77 if ( $global_signin && ! Login::is_globally_signed() ) {
148 78 Options::set_global_login();
149 79 }
150 80
@@ -172,25 +102,8 @@
172 102 unset( $response['user']['favourites'] );
173 103 $meta['favourites'] = $_favourites;
174 104 }
175 105
176 - if ( ! empty( $response['user']['reviews'] ) ) {
177 - $_reviews = $this->utils( 'helper' )->normalizeReviews( $response['user']['reviews'] );
178 - $this->utils( 'options' )->set( 'reviews', $_reviews );
179 -
180 - unset( $response['user']['reviews'] );
181 - $meta['reviews'] = $_reviews;
182 - }
183 -
184 - if(Helper::is_dev_api()){
185 - $response['user']['is_dev_api'] = true;
186 - }
187 -
188 - if(! empty( $response['user'] ) && is_array($response['user'])){
189 - $response['user']['ip'] = $_ip;
190 - $response['user']['site_url'] = base64_encode( $_site_url );
191 - }
192 -
193 106 $this->utils( 'options' )->set( 'user', $response['user'] );
194 107 $response['user']['meta'] = $this->user_meta( $meta );
195 108
196 109 return $response;
@@ -196,28 +109,13 @@
196 109 return $response;
197 110 }
198 111
199 112 public function logout() {
200 - // Read the key off the acting user's own record. Options::get() falls back to
201 - // the global-login administrator when no target is given, so $this->api_key
202 - // resolves to the administrator's key for any linked user — disconnecting the
203 - // administrator's account on the cloud as well as locally.
204 - $api_key = $this->utils( 'options' )->get( 'api_key', '', get_current_user_id() );
205 -
206 - if ( empty( $api_key ) ) {
207 - return $this->error(
208 - 'logout_error',
209 - __( 'You are not connected to Templately.', 'templately' ),
210 - 'logout',
211 - 403
212 - );
213 - }
214 -
215 113 $response = $this->http()->mutation(
216 114 'disconnect',
217 115 'status, message, data',
218 116 [
219 - 'api_key' => $api_key,
117 + 'api_key' => $this->api_key,
220 118 "site_url" => home_url( '/' )
221 119 ]
222 120 )->post();
223 121
@@ -244,33 +142,20 @@
244 142 return $response;
245 143 }
246 144
247 145 public function delete(){
248 - $options = $this->utils( 'options' );
146 + $this->utils( 'options' )
147 + ->remove( 'user' )
148 + ->remove( 'favourites' )
149 + ->remove( 'cloud_activity' )
150 + ->remove( 'api_key' )
151 + ->remove( 'global_login' )
152 + ->remove( 'templates_in_clouds' );
249 153
250 - // Pin the removals to the acting user. Without the pin, Options::user_id()
251 - // resolves a linked user to the global-login administrator and the delete
252 - // path wipes the administrator's connection instead of the caller's.
253 - $options->use_current_user( true );
154 + if ( $this->utils( 'options' )->whoami() === 'global' ) {
155 + $this->utils( 'options' )->remove_global_login();
156 + }
254 157
255 - try {
256 - $options
257 - ->remove( 'user' )
258 - ->remove( 'favourites' )
259 - ->remove( 'reviews' )
260 - ->remove( 'cloud_activity' )
261 - ->remove( 'api_key' )
262 - ->remove( 'global_login' )
263 - ->remove( 'total_download_counts' )
264 - ->remove( 'templates_in_clouds' );
265 -
266 - if ( $options->who_am_i() === 'global' ) {
267 - $options->remove_global_login();
268 - }
269 - } finally {
270 - $options->use_current_user( false );
271 - }
272 -
273 158 $global_user_id = $this->utils( 'options' )->is_global();
274 159 $global_user = null;
275 160
276 161 if ( $global_user_id !== $this->utils( 'options' )->current_user_id() ) {
@@ -276,12 +161,8 @@
276 161 if ( $global_user_id !== $this->utils( 'options' )->current_user_id() ) {
277 162 $global_user = $this->utils( 'options' )->get( 'user', false, $global_user_id );
278 163
279 164 if ( ! empty( $global_user ) ) {
280 - if ( is_array( $global_user ) ) {
281 - unset( $global_user['api_key'] );
282 - }
283 -
284 165 $global_user['meta'] = $this->user_meta();
285 166 }
286 167 }
287 168
@@ -287,9 +168,9 @@
287 168
288 169 return $global_user;
289 170 }
290 171
291 - public static function is_signed(): array {
172 + public static function is_signed() {
292 173 $_response = [
293 174 'status' => 'success'
294 175 ];
295 176
@@ -295,13 +176,8 @@
295 176
296 177 $_user = ( new static )->utils( 'options' )->get( 'user', null );
297 178
298 179 if ( ! is_null( $_user ) ) {
299 - // Profiles stored before 3.7.1 may still carry the cloud API key.
300 - if ( is_array( $_user ) ) {
301 - unset( $_user['api_key'] );
302 - }
303 -
304 180 $_user['meta'] = self::get_instance()->user_meta();
305 181 }
306 182
307 183 if ( empty( $_user ) ) {
@@ -312,9 +188,9 @@
312 188
313 189 return $_response;
314 190 }
315 191
316 - public function user_meta( $meta = [] ): array {
192 + public function user_meta( $meta = [] ) {
317 193 $_meta = [
318 194 'link_account' => self::utils( 'options' )->link_account(),
319 195 'unlink_account' => self::utils( 'options' )->unlink_account(),
320 196 'is_globally_signed' => Login::is_globally_signed(),
@@ -319,9 +195,8 @@
319 195 'unlink_account' => self::utils( 'options' )->unlink_account(),
320 196 'is_globally_signed' => Login::is_globally_signed(),
321 197 'signed_as_global' => Login::signed_as_global(),
322 198 'starred' => self::utils( 'options' )->get( 'favourites' ),
323 - 'reviews' => self::utils( 'options' )->get( 'reviews' ),
324 199 'cloud_activity' => self::utils( 'options' )->get( 'cloud_activity' ),
325 200 'has_api' => rest_sanitize_boolean( self::utils( 'options' )->get( 'api_key' ) )
326 201 ];
327 202
@@ -327,12 +202,12 @@
327 202
328 203 return array_merge( $_meta, $meta );
329 204 }
330 205
331 - public static function is_globally_signed(): bool {
206 + public static function is_globally_signed() {
332 207 return rest_sanitize_boolean( ( new static )->utils( 'options' )->is_globally_signed() );
333 208 }
334 209
335 - public static function signed_as_global(): bool {
210 + public static function signed_as_global() {
336 211 return rest_sanitize_boolean( ( new static )->utils( 'options' )->signed_as_global() );
337 212 }
338 -}
213 +}