Browse Source

remove pebble stuff. RIP pebble.

master
Aaron Parecki 4 months ago
parent
commit
94ec79eedc
7 changed files with 22 additions and 129 deletions
  1. +22
    -36
      controllers/auth.php
  2. +0
    -1
      controllers/controllers.php
  3. +0
    -44
      controllers/pebble.php
  4. +0
    -1
      public/index.php
  5. +0
    -16
      views/pebble-settings-login.php
  6. +0
    -8
      views/pebble-settings.php
  7. +0
    -23
      views/pebble.php

+ 22
- 36
controllers/auth.php View File

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

+ 0
- 1
controllers/controllers.php View File

@ -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']))) {

+ 0
- 44
controllers/pebble.php View File

@ -1,44 +0,0 @@
<?php
$app->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));
}
});

+ 0
- 1
public/index.php View File

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

+ 0
- 16
views/pebble-settings-login.php View File

@ -1,16 +0,0 @@
<div class="narrow">
<?= partial('partials/header') ?>
<h2>Sign in with your Domain</h2>
<p>Enter your website below to sign in.</p>
<p>If your website supports Micropub, it will log posts directly to your site. Otherwise, it will post to your profile on teacup.p3k.io.</p>
<form action="/auth/start" method="get" class="form-inline">
<input type="url" name="me" placeholder="http://me.com" value="" class="form-control">
<input type="hidden" name="redirect" value="settings">
<input type="hidden" name="pebble" value="true">
<input type="submit" value="Sign In" class="btn btn-primary">
</form>
</div>

+ 0
- 8
views/pebble-settings.php View File

@ -1,8 +0,0 @@
<h2>Finished!</h2>
<script>
var options = {
token: '<?= $this->token ?>'
};
location.href = 'pebblejs://close#' + encodeURIComponent(JSON.stringify(options));
</script>

+ 0
- 23
views/pebble.php View File

@ -1,23 +0,0 @@
<div class="narrow">
<div class="jumbotron h-x-app">
<h1><img src="/images/teacup-logo-144.png" height="72" style="margin-bottom: 13px;" class="u-logo" alt="Teacup">Teacup</h1>
<p class="tagline"><span class="p-name">Teacup for Pebble</span> is a simple app for tracking what you are drinking.</p>
<p>To use Teacup, download it to your Pebble, and sign in with your domain. If your website supports <a href="http://indiewebcamp.com/micropub">Micropub</a>, it will log posts directly to your site. Otherwise, it will post to your profile on teacup.p3k.io.</p>
<p><span style="font-size: 16pt;"><a href="https://apps.getpebble.com/applications/5456c83433c864a87f0000b9">Download Teacup for Pebble</a></span></p>
<a href="https://apps.getpebble.com/applications/5456c83433c864a87f0000b9"><img src="/images/screenshots.jpg" width="100%" class="screenshot"></a>
</div>
</div>
<style type="text/css">
.screenshot {
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
</style>

Loading…
Cancel
Save