summaryrefslogtreecommitdiff
path: root/controllers/controllers.php
diff options
context:
space:
mode:
authorAaron Parecki <aaron@parecki.com>2014-09-07 11:48:52 -0700
committerAaron Parecki <aaron@parecki.com>2014-09-07 11:48:52 -0700
commitcf8ecf1fc9942dc00f0a5a11b313f8babbc9c3cd (patch)
treeaf6a3e99b19383ea5642f530451ff450072a9345 /controllers/controllers.php
parent9cfa0ff2c18e25a9c00d80624e6abea487bd9136 (diff)
adds bookmark posting interface with bookmarklet. now any URL can auto-login given a login token.
Diffstat (limited to 'controllers/controllers.php')
-rw-r--r--controllers/controllers.php57
1 files changed, 56 insertions, 1 deletions
diff --git a/controllers/controllers.php b/controllers/controllers.php
index dc18584..0de366b 100644
--- a/controllers/controllers.php
+++ b/controllers/controllers.php
@@ -1,6 +1,21 @@
<?php
function require_login(&$app) {
+ $params = $app->request()->params();
+ if(array_key_exists('token', $params)) {
+ try {
+ $data = JWT::decode($params['token'], Config::$jwtSecret);
+ $_SESSION['user_id'] = $data->user_id;
+ $_SESSION['me'] = $data->me;
+ } catch(DomainException $e) {
+ header('X-Error: DomainException');
+ $app->redirect('/', 301);
+ } catch(UnexpectedValueException $e) {
+ header('X-Error: UnexpectedValueException');
+ $app->redirect('/', 301);
+ }
+ }
+
if(!array_key_exists('user_id', $_SESSION)) {
$app->redirect('/');
return false;
@@ -9,6 +24,14 @@ function require_login(&$app) {
}
}
+function generate_login_token() {
+ return JWT::encode(array(
+ 'user_id' => $_SESSION['user_id'],
+ 'me' => $_SESSION['me'],
+ 'created_at' => time()
+ ), Config::$jwtSecret);
+}
+
$app->get('/new', function() use($app) {
if($user=require_login($app)) {
@@ -26,7 +49,7 @@ $app->get('/new', function() use($app) {
}
}
- $html = render('dashboard', array(
+ $html = render('new-post', array(
'title' => 'New Post',
'micropub_endpoint' => $user->micropub_endpoint,
'micropub_scope' => $user->micropub_scope,
@@ -40,6 +63,38 @@ $app->get('/new', function() use($app) {
}
});
+
+$app->get('/bookmark', function() use($app) {
+ if($user=require_login($app)) {
+ $params = $app->request()->params();
+
+ $url = '';
+ $name = '';
+ $content = '';
+ $tags = '';
+
+ if(array_key_exists('url', $params))
+ $url = $params['url'];
+
+ if(array_key_exists('name', $params))
+ $name = $params['name'];
+
+ if(array_key_exists('content', $params))
+ $content = $params['content'];
+
+ $html = render('new-bookmark', array(
+ 'title' => 'New Bookmark',
+ 'bookmark_url' => $url,
+ 'bookmark_name' => $name,
+ 'bookmark_content' => $content,
+ 'bookmark_tags' => $tags,
+ 'token' => generate_login_token(),
+ 'syndication_targets' => json_decode($user->syndication_targets, true)
+ ));
+ $app->response()->body($html);
+ }
+});
+
$app->post('/prefs', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();