| @@ -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,24 +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 | 77 | if ( $global_signin && ! Login::is_globally_signed() ) { |
| 126 | 78 | Options::set_global_login(); |
| 127 | 79 | } |
| 128 | 80 | |
| @@ -150,25 +102,8 @@ | ||
| 150 | 102 | unset( $response['user']['favourites'] ); |
| 151 | 103 | $meta['favourites'] = $_favourites; |
| 152 | 104 | } |
| 153 | 105 | |
| 154 | - if ( ! empty( $response['user']['reviews'] ) ) { | |
| 155 | - $_reviews = $this->utils( 'helper' )->normalizeReviews( $response['user']['reviews'] ); | |
| 156 | - $this->utils( 'options' )->set( 'reviews', $_reviews ); | |
| 157 | - | |
| 158 | - unset( $response['user']['reviews'] ); | |
| 159 | - $meta['reviews'] = $_reviews; | |
| 160 | - } | |
| 161 | - | |
| 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 | 106 | $this->utils( 'options' )->set( 'user', $response['user'] ); |
| 172 | 107 | $response['user']['meta'] = $this->user_meta( $meta ); |
| 173 | 108 | |
| 174 | 109 | return $response; |
| @@ -210,16 +145,14 @@ | ||
| 210 | 145 | public function delete(){ |
| 211 | 146 | $this->utils( 'options' ) |
| 212 | 147 | ->remove( 'user' ) |
| 213 | 148 | ->remove( 'favourites' ) |
| 214 | - ->remove( 'reviews' ) | |
| 215 | 149 | ->remove( 'cloud_activity' ) |
| 216 | 150 | ->remove( 'api_key' ) |
| 217 | 151 | ->remove( 'global_login' ) |
| 218 | - ->remove( 'total_download_counts' ) | |
| 219 | 152 | ->remove( 'templates_in_clouds' ); |
| 220 | 153 | |
| 221 | - if ( $this->utils( 'options' )->who_am_i() === 'global' ) { | |
| 154 | + if ( $this->utils( 'options' )->whoami() === 'global' ) { | |
| 222 | 155 | $this->utils( 'options' )->remove_global_login(); |
| 223 | 156 | } |
| 224 | 157 | |
| 225 | 158 | $global_user_id = $this->utils( 'options' )->is_global(); |
| @@ -235,9 +168,9 @@ | ||
| 235 | 168 | |
| 236 | 169 | return $global_user; |
| 237 | 170 | } |
| 238 | 171 | |
| 239 | - public static function is_signed(): array { | |
| 172 | + public static function is_signed() { | |
| 240 | 173 | $_response = [ |
| 241 | 174 | 'status' => 'success' |
| 242 | 175 | ]; |
| 243 | 176 | |
| @@ -255,9 +188,9 @@ | ||
| 255 | 188 | |
| 256 | 189 | return $_response; |
| 257 | 190 | } |
| 258 | 191 | |
| 259 | - public function user_meta( $meta = [] ): array { | |
| 192 | + public function user_meta( $meta = [] ) { | |
| 260 | 193 | $_meta = [ |
| 261 | 194 | 'link_account' => self::utils( 'options' )->link_account(), |
| 262 | 195 | 'unlink_account' => self::utils( 'options' )->unlink_account(), |
| 263 | 196 | 'is_globally_signed' => Login::is_globally_signed(), |
| @@ -262,9 +195,8 @@ | ||
| 262 | 195 | 'unlink_account' => self::utils( 'options' )->unlink_account(), |
| 263 | 196 | 'is_globally_signed' => Login::is_globally_signed(), |
| 264 | 197 | 'signed_as_global' => Login::signed_as_global(), |
| 265 | 198 | 'starred' => self::utils( 'options' )->get( 'favourites' ), |
| 266 | - 'reviews' => self::utils( 'options' )->get( 'reviews' ), | |
| 267 | 199 | 'cloud_activity' => self::utils( 'options' )->get( 'cloud_activity' ), |
| 268 | 200 | 'has_api' => rest_sanitize_boolean( self::utils( 'options' )->get( 'api_key' ) ) |
| 269 | 201 | ]; |
| 270 | 202 | |
| @@ -270,12 +202,12 @@ | ||
| 270 | 202 | |
| 271 | 203 | return array_merge( $_meta, $meta ); |
| 272 | 204 | } |
| 273 | 205 | |
| 274 | - public static function is_globally_signed(): bool { | |
| 206 | + public static function is_globally_signed() { | |
| 275 | 207 | return rest_sanitize_boolean( ( new static )->utils( 'options' )->is_globally_signed() ); |
| 276 | 208 | } |
| 277 | 209 | |
| 278 | - public static function signed_as_global(): bool { | |
| 210 | + public static function signed_as_global() { | |
| 279 | 211 | return rest_sanitize_boolean( ( new static )->utils( 'options' )->signed_as_global() ); |
| 280 | 212 | } |
| 281 | 213 | } |