|
@ -1,6 +1,21 @@ |
|
|
<?php |
|
|
<?php |
|
|
|
|
|
|
|
|
function require_login(&$app) { |
|
|
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)) { |
|
|
if(!array_key_exists('user_id', $_SESSION)) { |
|
|
$app->redirect('/'); |
|
|
$app->redirect('/'); |
|
|
return false; |
|
|
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) { |
|
|
$app->get('/new', function() use($app) { |
|
|
if($user=require_login($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', |
|
|
'title' => 'New Post', |
|
|
'micropub_endpoint' => $user->micropub_endpoint, |
|
|
'micropub_endpoint' => $user->micropub_endpoint, |
|
|
'micropub_scope' => $user->micropub_scope, |
|
|
'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) { |
|
|
$app->post('/prefs', function() use($app) { |
|
|
if($user=require_login($app)) { |
|
|
if($user=require_login($app)) { |
|
|
$params = $app->request()->params(); |
|
|
$params = $app->request()->params(); |
|
|