diff --git a/api/cora/session.php b/api/cora/session.php index 536d125..68c18d8 100644 --- a/api/cora/session.php +++ b/api/cora/session.php @@ -124,7 +124,6 @@ final class session { // Set all of the necessary cookies. Both *_session_key and *_user_id are // read every API request and made available to the API. $this->set_cookie('session_key', $session_key, $expire); - $this->set_cookie('session_user_id', $user_id, $expire); if(isset($additional_cookie_values) === true) { foreach($additional_cookie_values as $key => $value) { $this->set_cookie($key, $value, $expire, false); @@ -157,8 +156,6 @@ final class session { } if($session_key === null) { - $this->delete_cookie('session_key'); - $this->delete_cookie('session_user_id'); return false; } @@ -186,7 +183,6 @@ final class session { ) ) { $this->delete_cookie('session_key'); - $this->delete_cookie('session_user_id'); return false; } @@ -204,7 +200,6 @@ final class session { } else { $this->delete_cookie('session_key'); - $this->delete_cookie('session_user_id'); return false; } } @@ -277,7 +272,7 @@ final class session { /** * Sets a cookie. If you want to set custom cookies, use the - * $additional_cookie_valeus argument on $session->create(). + * $additional_cookie_values argument on $session->create(). * * @param string $name The name of the cookie. * @param mixed $value The value of the cookie. @@ -291,10 +286,13 @@ final class session { $this->setting = setting::get_instance(); $path = '/'; // The current directory that the cookie is being set in. $secure = $this->setting->get('force_ssl'); - $domain = null; - if($domain === null) { // See setting documentation for more info. - $domain = ''; - } + + preg_match( + '/https?:\/\/(.*?)\//', + $this->setting->get('beestat_root_uri'), + $matches + ); + $domain = $matches[1]; $cookie_success = setcookie( $name, diff --git a/api/cora/setting.example.php b/api/cora/setting.example.php index d961840..ec96eb5 100644 --- a/api/cora/setting.example.php +++ b/api/cora/setting.example.php @@ -106,7 +106,7 @@ final class setting { * Used anytime the API needs to know where the site is at. Don't forget * the trailing slash. * - * Example: https://beestat.io/ + * Example: https://app.beestat.io/ */ 'beestat_root_uri' => '', diff --git a/api/ecobee.php b/api/ecobee.php index 5a28844..ddce844 100644 --- a/api/ecobee.php +++ b/api/ecobee.php @@ -142,7 +142,7 @@ class ecobee extends external_api { } // Redirect to the proper location. - header('Location: ' . $this->setting->get('beestat_root_uri') . 'dashboard/'); + header('Location: ' . $this->setting->get('beestat_root_uri')); } else if(isset($error) === true) { throw new Exception($error_description); diff --git a/api/ecobee_initialize.php b/api/ecobee_initialize.php index 59de1a4..c5f67f5 100644 --- a/api/ecobee_initialize.php +++ b/api/ecobee_initialize.php @@ -24,6 +24,6 @@ if(isset($_GET['error_description']) === true) { $setting = cora\setting::get_instance(); -header('Location: ' . $setting->get('beestat_root_uri') . 'api/index.php?resource=ecobee&method=initialize&arguments=' . json_encode($arguments) . '&api_key=' . $setting->get('ecobee_api_key_local')); +header('Location: ' . $setting->get('beestat_root_uri') . 'api/?resource=ecobee&method=initialize&arguments=' . json_encode($arguments) . '&api_key=' . $setting->get('ecobee_api_key_local')); die(); diff --git a/api/patreon_initialize.php b/api/patreon_initialize.php index d53f34f..8bc2523 100644 --- a/api/patreon_initialize.php +++ b/api/patreon_initialize.php @@ -18,6 +18,6 @@ if(isset($_GET['code']) === true) { $setting = cora\setting::get_instance(); -header('Location: ' . $setting->get('beestat_root_uri') . 'api/index.php?resource=patreon&method=initialize&arguments=' . json_encode($arguments) . '&api_key=' . $setting->get('patreon_api_key_local')); +header('Location: ' . $setting->get('beestat_root_uri') . 'api/?resource=patreon&method=initialize&arguments=' . json_encode($arguments) . '&api_key=' . $setting->get('patreon_api_key_local')); die(); diff --git a/app.php b/app.php new file mode 100644 index 0000000..d5f7dd1 --- /dev/null +++ b/app.php @@ -0,0 +1,25 @@ + + + + + + beestat + + + + + + + + + + + diff --git a/index.php b/index.php index bba1167..56c4e73 100644 --- a/index.php +++ b/index.php @@ -14,64 +14,13 @@ $setting->get('force_ssl'), true ); - header('Location: dashboard/'); - die(); - } else { - // Skip this page entirely if you're logged in. - if(isset($_COOKIE['session_key']) === true) { - header('Location: dashboard/'); - die(); - } } -?> - - - - beestat - - - - - - - - - -
-
-
-
-
- beestat -
- -
-
-
- Connect your thermostat -
-
- -
-
- -
- -
- - + // var_dump($_COOKIE); + // Skip this page entirely if you're logged in. + // if(isset($_COOKIE['session_key']) === true) { + if(preg_match('/app\.beestat\.io/', $_SERVER['HTTP_HOST']) !== 0) { + require 'app.php'; + } else { + require 'www.php'; + } diff --git a/js/beestat/api.js b/js/beestat/api.js index d3b8a1d..46eb389 100644 --- a/js/beestat/api.js +++ b/js/beestat/api.js @@ -45,7 +45,12 @@ beestat.api.prototype.send = function(opt_api_call) { this.xhr_.addEventListener('load', function() { self.load_(this.responseText); }); - this.xhr_.open('POST', '../api/?' + query_string); + + // var endpoint = (window.environment === 'live') + // ? 'https://api.beestat.io/' + // : 'http://' + window.environment + '.api.beestat.io/'; + // this.xhr_.open('POST', endpoint + '?' + query_string); + this.xhr_.open('POST', 'api/?' + query_string); this.xhr_.send(); } else { if (this.api_calls_.length === 0) { @@ -87,7 +92,6 @@ beestat.api.prototype.send = function(opt_api_call) { var cached = this.get_cached_(single_api_call); if (cached !== undefined) { if (this.callback_ !== undefined) { - /** * Timeout makes this behave like an actual API call in terms of * program flow. Without this, if there is a rerender() inside a diff --git a/js/component/header.js b/js/component/header.js index fbf6ad3..4486ec3 100644 --- a/js/component/header.js +++ b/js/component/header.js @@ -152,7 +152,7 @@ beestat.component.header.prototype.decorate_ = function(parent) { .set_callback(function() { new beestat.api() .set_callback(function() { - window.location.reload(); + window.location.href = window.location.href.replace('app.', ''); }) .add_call( 'user', diff --git a/www.php b/www.php new file mode 100644 index 0000000..4a58e44 --- /dev/null +++ b/www.php @@ -0,0 +1,52 @@ + + + + beestat + + + + + + + + + + +
+
+
+
+
+ beestat +
+ +
+
+
+ Connect your thermostat +
+
+ + +
+
+ +
+ +
+ +