Browse Source

move pebble stuff to its own file

pull/10/head
Aaron Parecki 5 years ago
parent
commit
2503607dde
3 changed files with 47 additions and 41 deletions
  1. +3
    -40
      controllers/controllers.php
  2. +43
    -0
      controllers/pebble.php
  3. +1
    -1
      views/pebble-settings.php

+ 3
- 40
controllers/controllers.php View File

@@ -58,46 +58,6 @@ $app->get('/new', function() use($app) {
}
});

$app->get('/pebble/settings', function() use($app) {
$html = render('pebble-settings-login', array(
'title' => 'Log In'
));
$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) {
$app->response()['Content-Type'] = 'application/json';
$app->response()->body(json_encode(array(
'sections' => array(
array(
'title' => 'Caffeine',
'items' => array_map(function($e){ return array('title'=>$e); }, caffeine_options())
),
array(
'title' => 'Alcohol',
'items' => array_map(function($e){ return array('title'=>$e); }, alcohol_options())
)
)
)));
});


$app->post('/prefs', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();
@@ -193,6 +153,9 @@ $app->post('/post', function() use($app) {
if(k($params, 'drank')) {
$entry->content = $params['drank'];
$type = 'drink';
} elseif(k($params, 'drink')) {
$entry->content = $params['drink'];
$type = 'drink';
} elseif(k($params, 'custom_drank')) {
$entry->content = $params['custom_drank'];
$type = 'drink';


+ 43
- 0
controllers/pebble.php View File

@@ -0,0 +1,43 @@
<?php

$app->get('/pebble/settings', function() use($app) {
$html = render('pebble-settings-login', array(
'title' => 'Log In'
));
$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) {
// TODO: if a token is provided, return the user's custom list

$app->response()['Content-Type'] = 'application/json';
$app->response()->body(json_encode(array(
'sections' => array(
array(
'title' => 'Caffeine',
'items' => array_map(function($e){ return array('title'=>$e, 'type'=>'drink'); }, caffeine_options())
),
array(
'title' => 'Alcohol',
'items' => array_map(function($e){ return array('title'=>$e, 'type'=>'drink'); }, alcohol_options())
)
)
)));
});


+ 1
- 1
views/pebble-settings.php View File

@@ -4,5 +4,5 @@
var options = {
token: '<?= $this->token ?>'
};
document.location = 'pebblejs://close#' + encodeURIComponent(JSON.stringify(options));
location.href = 'pebblejs://close#' + encodeURIComponent(JSON.stringify(options));
</script>

Loading…
Cancel
Save