adds bookmark posting interface with bookmarklet. now any URL can auto-login given a login token.
This commit is contained in:
parent
9cfa0ff2c1
commit
cf8ecf1fc9
8 changed files with 278 additions and 100 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue