| @@ -17,12 +17,8 @@ | ||
| 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 | - | |
| 25 | 21 | return parent::permission_check( $request ); |
| 26 | 22 | } |
| 27 | 23 | |
| 28 | 24 | public function register_routes() { |
| @@ -29,25 +25,10 @@ | ||
| 29 | 25 | $this->post( 'login', [$this, 'login'] ); |
| 30 | 26 | $this->post( 'logout', [$this, 'logout'] ); |
| 31 | 27 | $this->get( 'is-signed', [$this, 'is_signed'] ); |
| 32 | 28 | $this->get( 'pricing', [$this, 'pricing'] ); |
| 33 | - $this->get( 'google-auth-url', [$this, 'google_auth_url'] ); | |
| 34 | 29 | } |
| 35 | 30 | |
| 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 | 31 | public function pricing(){ |
| 51 | 32 | $data = get_transient( "templately_subscriptions" ); |
| 52 | 33 | |
| 53 | 34 | if( is_array( $data ) && ! empty( $data ) ) { |
| @@ -53,9 +34,9 @@ | ||
| 53 | 34 | if( is_array( $data ) && ! empty( $data ) ) { |
| 54 | 35 | return $data; |
| 55 | 36 | } |
| 56 | 37 | |
| 57 | - $query = 'id, price, name, discounted_price, type, sites, coupon'; | |
| 38 | + $query = 'id, price, name, discounted_price, type, sites'; | |
| 58 | 39 | $response = $this->http()->query( |
| 59 | 40 | 'subscriptionPlans', |
| 60 | 41 | $query |
| 61 | 42 | )->post(); |
| @@ -79,10 +60,8 @@ | ||
| 79 | 60 | 'ip' => $_ip, |
| 80 | 61 | 'site_url' => $_site_url |
| 81 | 62 | ]; |
| 82 | 63 | |
| 83 | - $postArgs = []; | |
| 84 | - | |
| 85 | 64 | if ( $viaAPI ) { |
| 86 | 65 | $api_key = $this->get_param( 'api_key' ); |
| 87 | 66 | $funcArgs['api_key'] = $api_key; |
| 88 | 67 | |
| @@ -105,24 +84,20 @@ | ||
| 105 | 84 | if ( ! empty( $errors ) ) { |
| 106 | 85 | return $this->error( 'login_error', $errors, 'login', 400 ); |
| 107 | 86 | } |
| 108 | 87 | |
| 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 } }'; | |
| 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 } }'; | |
| 110 | 89 | |
| 111 | 90 | $response = $this->http()->mutation( |
| 112 | 91 | $viaAPI ? 'connectWithApiKey' : 'connect', |
| 113 | 92 | $query, |
| 114 | 93 | $funcArgs |
| 115 | - )->post($postArgs); | |
| 94 | + )->post(); | |
| 116 | 95 | |
| 117 | 96 | if ( is_wp_error( $response ) ) { |
| 118 | 97 | return $response; |
| 119 | 98 | } |
| 120 | 99 | |
| 121 | - if ( empty( $response['user']['api_key'] ) ) { | |
| 122 | - return $this->error( 'login_error', $response['message'] ?? __('Invalid API key.', 'templately'), 'login', 400 ); | |
| 123 | - } | |
| 124 | - | |
| 125 | 100 | if ( $global_signin && ! Login::is_globally_signed() ) { |
| 126 | 101 | Options::set_global_login(); |
| 127 | 102 | } |
| 128 | 103 | |
| @@ -158,17 +133,8 @@ | ||
| 158 | 133 | unset( $response['user']['reviews'] ); |
| 159 | 134 | $meta['reviews'] = $_reviews; |
| 160 | 135 | } |
| 161 | 136 | |
| 162 | - if(Helper::is_dev_api()){ | |
| 163 | - $response['user']['is_dev_api'] = true; | |
| 164 | - } | |
| 165 | - | |
| 166 | - if(! empty( $response['user'] ) && is_array($response['user'])){ | |
| 167 | - $response['user']['ip'] = $_ip; | |
| 168 | - $response['user']['site_url'] = base64_encode( $_site_url ); | |
| 169 | - } | |
| 170 | - | |
| 171 | 137 | $this->utils( 'options' )->set( 'user', $response['user'] ); |
| 172 | 138 | $response['user']['meta'] = $this->user_meta( $meta ); |
| 173 | 139 | |
| 174 | 140 | return $response; |
| @@ -214,12 +180,11 @@ | ||
| 214 | 180 | ->remove( 'reviews' ) |
| 215 | 181 | ->remove( 'cloud_activity' ) |
| 216 | 182 | ->remove( 'api_key' ) |
| 217 | 183 | ->remove( 'global_login' ) |
| 218 | - ->remove( 'total_download_counts' ) | |
| 219 | 184 | ->remove( 'templates_in_clouds' ); |
| 220 | 185 | |
| 221 | - if ( $this->utils( 'options' )->who_am_i() === 'global' ) { | |
| 186 | + if ( $this->utils( 'options' )->whoami() === 'global' ) { | |
| 222 | 187 | $this->utils( 'options' )->remove_global_login(); |
| 223 | 188 | } |
| 224 | 189 | |
| 225 | 190 | $global_user_id = $this->utils( 'options' )->is_global(); |
| @@ -228,12 +193,8 @@ | ||
| 228 | 193 | if ( $global_user_id !== $this->utils( 'options' )->current_user_id() ) { |
| 229 | 194 | $global_user = $this->utils( 'options' )->get( 'user', false, $global_user_id ); |
| 230 | 195 | |
| 231 | 196 | if ( ! empty( $global_user ) ) { |
| 232 | - if ( is_array( $global_user ) ) { | |
| 233 | - unset( $global_user['api_key'] ); | |
| 234 | - } | |
| 235 | - | |
| 236 | 197 | $global_user['meta'] = $this->user_meta(); |
| 237 | 198 | } |
| 238 | 199 | } |
| 239 | 200 | |
| @@ -239,9 +200,9 @@ | ||
| 239 | 200 | |
| 240 | 201 | return $global_user; |
| 241 | 202 | } |
| 242 | 203 | |
| 243 | - public static function is_signed(): array { | |
| 204 | + public static function is_signed() { | |
| 244 | 205 | $_response = [ |
| 245 | 206 | 'status' => 'success' |
| 246 | 207 | ]; |
| 247 | 208 | |
| @@ -247,13 +208,8 @@ | ||
| 247 | 208 | |
| 248 | 209 | $_user = ( new static )->utils( 'options' )->get( 'user', null ); |
| 249 | 210 | |
| 250 | 211 | if ( ! is_null( $_user ) ) { |
| 251 | - // Profiles stored before 3.7.1 may still carry the cloud API key. | |
| 252 | - if ( is_array( $_user ) ) { | |
| 253 | - unset( $_user['api_key'] ); | |
| 254 | - } | |
| 255 | - | |
| 256 | 212 | $_user['meta'] = self::get_instance()->user_meta(); |
| 257 | 213 | } |
| 258 | 214 | |
| 259 | 215 | if ( empty( $_user ) ) { |
| @@ -264,9 +220,9 @@ | ||
| 264 | 220 | |
| 265 | 221 | return $_response; |
| 266 | 222 | } |
| 267 | 223 | |
| 268 | - public function user_meta( $meta = [] ): array { | |
| 224 | + public function user_meta( $meta = [] ) { | |
| 269 | 225 | $_meta = [ |
| 270 | 226 | 'link_account' => self::utils( 'options' )->link_account(), |
| 271 | 227 | 'unlink_account' => self::utils( 'options' )->unlink_account(), |
| 272 | 228 | 'is_globally_signed' => Login::is_globally_signed(), |
| @@ -279,12 +235,12 @@ | ||
| 279 | 235 | |
| 280 | 236 | return array_merge( $_meta, $meta ); |
| 281 | 237 | } |
| 282 | 238 | |
| 283 | - public static function is_globally_signed(): bool { | |
| 239 | + public static function is_globally_signed() { | |
| 284 | 240 | return rest_sanitize_boolean( ( new static )->utils( 'options' )->is_globally_signed() ); |
| 285 | 241 | } |
| 286 | 242 | |
| 287 | - public static function signed_as_global(): bool { | |
| 243 | + public static function signed_as_global() { | |
| 288 | 244 | return rest_sanitize_boolean( ( new static )->utils( 'options' )->signed_as_global() ); |
| 289 | 245 | } |
| 290 | 246 | } |