diff --git a/controllers/auth.php b/controllers/auth.php index 7ac212f..de4cd2e 100644 --- a/controllers/auth.php +++ b/controllers/auth.php @@ -4,26 +4,22 @@ function buildRedirectURI() { return Config::$base_url . 'auth/callback'; } -function clientID($pebble=false) { - if($pebble) { - return Config::$base_url . 'pebble'; - } else { - return trim(Config::$base_url, '/'); // remove trailing slash from client_id - } +function clientID() { + return Config::$base_url; } -function build_url($parsed_url) { - $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; - $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; - $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; - $user = isset($parsed_url['user']) ? $parsed_url['user'] : ''; - $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : ''; - $pass = ($user || $pass) ? "$pass@" : ''; - $path = isset($parsed_url['path']) ? $parsed_url['path'] : ''; - $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : ''; - $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : ''; - return "$scheme$user$pass$host$port$path$query$fragment"; -} +function build_url($parsed_url) { + $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; + $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; + $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; + $user = isset($parsed_url['user']) ? $parsed_url['user'] : ''; + $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : ''; + $pass = ($user || $pass) ? "$pass@" : ''; + $path = isset($parsed_url['path']) ? $parsed_url['path'] : ''; + $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : ''; + $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : ''; + return "$scheme$user$pass$host$port$path$query$fragment"; +} // Input: Any URL or string like "aaronparecki.com" // Output: Normlized URL (default to http if no scheme, force "/" path) @@ -72,7 +68,7 @@ function add_hcard_info($user, $hCard) { $user->name = BarnabyWalters\Mf2\getPlaintext($hCard, 'name'); if(BarnabyWalters\Mf2\hasProp($hCard, 'photo')) $user->photo_url = BarnabyWalters\Mf2\getPlaintext($hCard, 'photo'); - } + } } $app->get('/', function($format='html') use($app) { @@ -89,7 +85,7 @@ $app->get('/auth/start', function() use($app) { $req = $app->request(); $params = $req->params(); - + // the "me" parameter is user input, and may be in a couple of different forms: // aaronparecki.com http://aaronparecki.com http://aaronparecki.com/ // Normlize the value now (move this into a function in IndieAuth\Client later) @@ -112,28 +108,20 @@ $app->get('/auth/start', function() use($app) { // Generate a "state" parameter for the request $state = IndieAuth\Client::generateStateParameter(); $_SESSION['auth_state'] = $state; - - // Store whether to return to the Pebble settings tab or the new post page after signing in - if(array_key_exists('redirect', $params) && $params['redirect'] == 'settings') { - $_SESSION['redirect_after_login'] = '/pebble/settings/finished'; - } else { - $_SESSION['redirect_after_login'] = '/new'; - } - $pebble = k($params, 'pebble'); - $_SESSION['pebble'] = $pebble; + $_SESSION['redirect_after_login'] = '/new'; if($tokenEndpoint && $micropubEndpoint && $authorizationEndpoint) { $scope = 'create'; - $authorizationURL = IndieAuth\Client::buildAuthorizationURL($authorizationEndpoint, $me, buildRedirectURI(), clientID($pebble), $state, $scope); + $authorizationURL = IndieAuth\Client::buildAuthorizationURL($authorizationEndpoint, $me, buildRedirectURI(), clientID(), $state, $scope); $_SESSION['authorization_endpoint'] = $authorizationEndpoint; $_SESSION['micropub_endpoint'] = $micropubEndpoint; $_SESSION['token_endpoint'] = $tokenEndpoint; } else { - $authorizationURL = IndieAuth\Client::buildAuthorizationURL('https://indieauth.com/auth', $me, buildRedirectURI(), clientID($pebble), $state); + $authorizationURL = IndieAuth\Client::buildAuthorizationURL('https://indieauth.com/auth', $me, buildRedirectURI(), clientID(), $state); } - // If the user has already signed in before and has a micropub access token, skip + // If the user has already signed in before and has a micropub access token, skip // the debugging screens and redirect immediately to the auth endpoint. // This will still generate a new access token when they finish logging in. $user = ORM::for_table('users')->where('url', hostname($me))->find_one(); @@ -229,8 +217,6 @@ $app->get('/auth/callback', function() use($app) { } $me = $_SESSION['attempted_me']; - $pebble = k($_SESSION, 'pebble'); - // Now the basic sanity checks have passed. Time to start providing more helpful messages when there is an error. // An authorization code is in the query string, and we want to exchange that for an access token at the token endpoint. @@ -246,7 +232,7 @@ $app->get('/auth/callback', function() use($app) { if($tokenEndpoint) { // Exchange auth code for an access token - $token = IndieAuth\Client::getAccessToken($tokenEndpoint, $params['code'], $me, buildRedirectURI(), clientID($pebble), true); + $token = IndieAuth\Client::getAccessToken($tokenEndpoint, $params['code'], $me, buildRedirectURI(), clientID(), true); // If a valid access token was returned, store the token info in the session and they are signed in if(k($token['auth'], array('me','access_token','scope'))) { @@ -274,7 +260,7 @@ $app->get('/auth/callback', function() use($app) { $authorizationEndpoint = 'https://indieauth.com/auth'; } - $token['auth'] = IndieAuth\Client::verifyIndieAuthCode($authorizationEndpoint, $params['code'], $me, buildRedirectURI(), clientID($pebble)); + $token['auth'] = IndieAuth\Client::verifyIndieAuthCode($authorizationEndpoint, $params['code'], $me, buildRedirectURI(), clientID()); if(k($token['auth'], 'me')) { $token['response'] = ''; // hack becuase the verify call doesn't actually return the real response diff --git a/controllers/controllers.php b/controllers/controllers.php index ba797b5..9e724d9 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -200,7 +200,6 @@ $app->post('/post', function() use($app) { $entry->tz_offset = tz_offset_to_seconds($params['note_tzoffset']); $published = $date_string; } else { - // Pebble doesn't send the date/time/timezone $entry->published = date('Y-m-d H:i:s'); $published = date('c'); // for the micropub post if($location && ($timezone=get_timezone($location['latitude'], $location['longitude']))) { diff --git a/controllers/pebble.php b/controllers/pebble.php deleted file mode 100644 index daf0868..0000000 --- a/controllers/pebble.php +++ /dev/null @@ -1,44 +0,0 @@ -get('/pebble', function() use($app) { - $html = render('pebble', array( - 'title' => 'Teacup for Pebble' - )); - $app->response()->body($html); -}); - -$app->get('/pebble/settings', function() use($app) { - $html = render('pebble-settings-login', array( - 'title' => 'Log In', - 'footer' => false - )); - $app->response()->body($html); -}); - -$app->get('/pebble/settings/finished', function() use($app) { - if($user=require_login($app)) { - $token = JWT::encode(array( - 'user_id' => $_SESSION['user_id'], - 'me' => $_SESSION['me'], - 'created_at' => time() - ), Config::$jwtSecret); - - $html = render('pebble-settings', array( - 'title' => 'Pebble Settings', - 'token' => $token - )); - $app->response()->body($html); - } -}); - -$app->get('/pebble/options.json', function() use($app) { - if($user=require_login($app)) { - $params = $app->request()->params(); - - $options = get_entry_options($user->id, k($params,'latitude'), k($params,'longitude')); - - $app->response()['Content-Type'] = 'application/json'; - $app->response()->body(json_encode($options)); - } -}); - diff --git a/public/index.php b/public/index.php index 4c9b68b..8184705 100644 --- a/public/index.php +++ b/public/index.php @@ -13,7 +13,6 @@ $app = new \Slim\Slim(array( require 'controllers/auth.php'; require 'controllers/controllers.php'; -require 'controllers/pebble.php'; require 'controllers/alexa.php'; session_name('teacup'); diff --git a/views/pebble-settings-login.php b/views/pebble-settings-login.php deleted file mode 100644 index 21b636f..0000000 --- a/views/pebble-settings-login.php +++ /dev/null @@ -1,16 +0,0 @@ -
Enter your website below to sign in.
-If your website supports Micropub, it will log posts directly to your site. Otherwise, it will post to your profile on teacup.p3k.io.
- - - -Teacup for Pebble is a simple app for tracking what you are drinking.
- -To use Teacup, download it to your Pebble, and sign in with your domain. If your website supports Micropub, it will log posts directly to your site. Otherwise, it will post to your profile on teacup.p3k.io.
- - - - - -