1
0
mirror of https://github.com/beestat/app.git synced 2025-05-24 02:14:03 -04:00

Subdomains!

beestat.io, app.beestat.io, api.beestat.io, demo.beestat.io They all now work and the cookies should behave better. Fixes #134 among other things.
This commit is contained in:
Jon Ziebell 2019-10-17 21:20:25 -04:00
parent e195a5260b
commit 55f9aae26f
10 changed files with 104 additions and 76 deletions

View File

@ -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,

View File

@ -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' => '',

View File

@ -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);

View File

@ -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();

View File

@ -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();

25
app.php Normal file
View File

@ -0,0 +1,25 @@
<?php
// If you're not logged in, just take you directly to the ecobee login page.
if(isset($_COOKIE['session_key']) === false) {
header('Location: http://' . $_SERVER['HTTP_HOST'] . '/api/?resource=ecobee&method=authorize&arguments={}&api_key=ER9Dz8t05qUdui0cvfWi5GiVVyHP6OB8KPuSisP2');
die();
}
?>
<!doctype html>
<html>
<head>
<title>beestat</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<!-- Chrome, Firefox OS and Opera -->
<meta name="theme-color" content="#222222">
<link rel="manifest" href="/manifest.json">
<link href="../css/dashboard.css" rel="stylesheet">
<?php require 'js/js.php'; ?>
</head>
<body></body>
</html>

View File

@ -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();
}
}
?>
<!doctype html>
<html>
<head>
<title>beestat</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<!-- Chrome, Firefox OS and Opera -->
<meta name="theme-color" content="#222222">
<link rel="manifest" href="/manifest.json">
<link href="css/index.css" rel="stylesheet">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-10019370-7"></script>
</head>
<body>
<div class="_index">
<main>
<div class="waveform"></div>
<div class="header">
<div class="beestat">
<span class="bee">bee</span><span class="stat">stat</span>
</div>
<div class="log_in">
Log In
</div>
</div>
<div class="connect">
<div class="connect_text">
Connect your thermostat
</div>
<div class="connect_platforms">
<a href="api/?resource=ecobee&method=authorize&arguments={}&api_key=ER9Dz8t05qUdui0cvfWi5GiVVyHP6OB8KPuSisP2" class="ecobee"></a>
</div>
</div>
<div class="demo">
<a href="https://demo.beestat.io" target="_blank">Try a Demo</a>
</div>
</main>
<footer>
<div class="footer_text">
Beestat is a free tool intended to help you view and analyze your home HVAC usage and efficiency.<br/>
</div>
<div class="footer_links">
<a href="mailto:contact@beestat.io">Contact</a>
<a href="privacy/">Privacy</a>
<a href="http://eepurl.com/dum59r" target="_blank">Mailing List</a>
<a href="https://github.com/beestat/app/issues" target="_blank">Report Issue</a>
</div>
</footer>
</div>
</body>
</html>
// 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';
}

View File

@ -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

View File

@ -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',

52
www.php Normal file
View File

@ -0,0 +1,52 @@
<!doctype html>
<html>
<head>
<title>beestat</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<!-- Chrome, Firefox OS and Opera -->
<meta name="theme-color" content="#222222">
<link rel="manifest" href="/manifest.json">
<link href="css/index.css" rel="stylesheet">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-10019370-7"></script>
</head>
<body>
<div class="_index">
<main>
<div class="waveform"></div>
<div class="header">
<div class="beestat">
<span class="bee">bee</span><span class="stat">stat</span>
</div>
<div class="log_in">
Log In
</div>
</div>
<div class="connect">
<div class="connect_text">
Connect your thermostat
</div>
<div class="connect_platforms">
<!-- <a href="api/?resource=ecobee&method=authorize&arguments={}&api_key=ER9Dz8t05qUdui0cvfWi5GiVVyHP6OB8KPuSisP2" class="ecobee"></a> -->
<a href="<?php echo 'http://' . str_replace('beestat.io', 'app.beestat.io', $_SERVER['HTTP_HOST']); ?>" class="ecobee"></a>
</div>
</div>
<div class="demo">
<a href="https://demo.beestat.io" target="_blank">Try a Demo</a>
</div>
</main>
<footer>
<div class="footer_text">
Beestat is a free tool intended to help you view and analyze your home HVAC usage and efficiency.<br/>
</div>
<div class="footer_links">
<a href="mailto:contact@beestat.io">Contact</a>
<a href="privacy/">Privacy</a>
<a href="http://eepurl.com/dum59r" target="_blank">Mailing List</a>
<a href="https://github.com/beestat/app/issues" target="_blank">Report Issue</a>
</div>
</footer>
</div>
</body>
</html>