PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.5.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.5.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 +40 -8 3.0.33.5.2 View file →
@@ -17,8 +17,12 @@
17 17 if ( '/templately/v1/pricing' === $_route ) {
18 18 return true;
19 19 }
20 20
21 + if ( '/templately/v1/google-auth-url' === $_route ) {
22 + return true;
23 + }
24 +
21 25 return parent::permission_check( $request );
22 26 }
23 27
24 28 public function register_routes() {
@@ -25,10 +29,22 @@
25 29 $this->post( 'login', [$this, 'login'] );
26 30 $this->post( 'logout', [$this, 'logout'] );
27 31 $this->get( 'is-signed', [$this, 'is_signed'] );
28 32 $this->get( 'pricing', [$this, 'pricing'] );
33 + $this->get( 'google-auth-url', [$this, 'google_auth_url'] );
29 34 }
30 35
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 + $url = $this->http()->google_auth_url( $redirect_to );
41 + return [
42 + 'status' => 'success',
43 + 'url' => $url
44 + ];
45 + }
46 +
31 47 public function pricing(){
32 48 $data = get_transient( "templately_subscriptions" );
33 49
34 50 if( is_array( $data ) && ! empty( $data ) ) {
@@ -34,9 +50,9 @@
34 50 if( is_array( $data ) && ! empty( $data ) ) {
35 51 return $data;
36 52 }
37 53
38 - $query = 'id, price, name, discounted_price, type, sites';
54 + $query = 'id, price, name, discounted_price, type, sites, coupon';
39 55 $response = $this->http()->query(
40 56 'subscriptionPlans',
41 57 $query
42 58 )->post();
@@ -60,8 +76,10 @@
60 76 'ip' => $_ip,
61 77 'site_url' => $_site_url
62 78 ];
63 79
80 + $postArgs = [];
81 +
64 82 if ( $viaAPI ) {
65 83 $api_key = $this->get_param( 'api_key' );
66 84 $funcArgs['api_key'] = $api_key;
67 85
@@ -84,20 +102,24 @@
84 102 if ( ! empty( $errors ) ) {
85 103 return $this->error( 'login_error', $errors, 'login', 400 );
86 104 }
87 105
88 - $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, reviews{ type, type_id, rating } }';
106 + $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 } }';
89 107
90 108 $response = $this->http()->mutation(
91 109 $viaAPI ? 'connectWithApiKey' : 'connect',
92 110 $query,
93 111 $funcArgs
94 - )->post();
112 + )->post($postArgs);
95 113
96 114 if ( is_wp_error( $response ) ) {
97 115 return $response;
98 116 }
99 117
118 + if ( empty( $response['user']['api_key'] ) ) {
119 + return $this->error( 'login_error', $response['message'] ?? __('Invalid API key.', 'templately'), 'login', 400 );
120 + }
121 +
100 122 if ( $global_signin && ! Login::is_globally_signed() ) {
101 123 Options::set_global_login();
102 124 }
103 125
@@ -133,8 +155,17 @@
133 155 unset( $response['user']['reviews'] );
134 156 $meta['reviews'] = $_reviews;
135 157 }
136 158
159 + if(Helper::is_dev_api()){
160 + $response['user']['is_dev_api'] = true;
161 + }
162 +
163 + if(! empty( $response['user'] ) && is_array($response['user'])){
164 + $response['user']['ip'] = $_ip;
165 + $response['user']['site_url'] = base64_encode( $_site_url );
166 + }
167 +
137 168 $this->utils( 'options' )->set( 'user', $response['user'] );
138 169 $response['user']['meta'] = $this->user_meta( $meta );
139 170
140 171 return $response;
@@ -180,11 +211,12 @@
180 211 ->remove( 'reviews' )
181 212 ->remove( 'cloud_activity' )
182 213 ->remove( 'api_key' )
183 214 ->remove( 'global_login' )
215 + ->remove( 'total_download_counts' )
184 216 ->remove( 'templates_in_clouds' );
185 217
186 - if ( $this->utils( 'options' )->whoami() === 'global' ) {
218 + if ( $this->utils( 'options' )->who_am_i() === 'global' ) {
187 219 $this->utils( 'options' )->remove_global_login();
188 220 }
189 221
190 222 $global_user_id = $this->utils( 'options' )->is_global();
@@ -200,9 +232,9 @@
200 232
201 233 return $global_user;
202 234 }
203 235
204 - public static function is_signed() {
236 + public static function is_signed(): array {
205 237 $_response = [
206 238 'status' => 'success'
207 239 ];
208 240
@@ -220,9 +252,9 @@
220 252
221 253 return $_response;
222 254 }
223 255
224 - public function user_meta( $meta = [] ) {
256 + public function user_meta( $meta = [] ): array {
225 257 $_meta = [
226 258 'link_account' => self::utils( 'options' )->link_account(),
227 259 'unlink_account' => self::utils( 'options' )->unlink_account(),
228 260 'is_globally_signed' => Login::is_globally_signed(),
@@ -235,12 +267,12 @@
235 267
236 268 return array_merge( $_meta, $meta );
237 269 }
238 270
239 - public static function is_globally_signed() {
271 + public static function is_globally_signed(): bool {
240 272 return rest_sanitize_boolean( ( new static )->utils( 'options' )->is_globally_signed() );
241 273 }
242 274
243 - public static function signed_as_global() {
275 + public static function signed_as_global(): bool {
244 276 return rest_sanitize_boolean( ( new static )->utils( 'options' )->signed_as_global() );
245 277 }
246 278 }