do the micropub post and redirect after it's created!
This commit is contained in:
parent
3dc97d7478
commit
3b7d766c31
7 changed files with 103 additions and 8 deletions
|
@ -74,7 +74,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)
|
||||
|
@ -88,6 +88,10 @@ $app->get('/auth/start', function() use($app) {
|
|||
return;
|
||||
}
|
||||
|
||||
if(k($params, 'redirect')) {
|
||||
$_SESSION['redirect_after_login'] = $params['redirect'];
|
||||
}
|
||||
|
||||
$authorizationEndpoint = IndieAuth\Client::discoverAuthorizationEndpoint($me);
|
||||
$tokenEndpoint = IndieAuth\Client::discoverTokenEndpoint($me);
|
||||
$micropubEndpoint = IndieAuth\Client::discoverMicropubEndpoint($me);
|
||||
|
@ -244,7 +248,13 @@ $app->get('/auth/callback', function() use($app) {
|
|||
unset($_SESSION['auth_state']);
|
||||
|
||||
if($redirectToDashboardImmediately) {
|
||||
$app->redirect('/new', 301);
|
||||
if(k($_SESSION, 'redirect_after_login')) {
|
||||
$dest = $_SESSION['redirect_after_login'];
|
||||
unset($_SESSION['redirect_after_login']);
|
||||
$app->redirect($dest, 301);
|
||||
} else {
|
||||
$app->redirect('/new', 301);
|
||||
}
|
||||
} else {
|
||||
$html = render('auth_callback', array(
|
||||
'title' => 'Sign In',
|
||||
|
@ -254,7 +264,8 @@ $app->get('/auth/callback', function() use($app) {
|
|||
'tokenEndpoint' => $tokenEndpoint,
|
||||
'auth' => $token['auth'],
|
||||
'response' => $token['response'],
|
||||
'curl_error' => (array_key_exists('error', $token) ? $token['error'] : false)
|
||||
'curl_error' => (array_key_exists('error', $token) ? $token['error'] : false),
|
||||
'destination' => (k($_SESSION, 'redirect_after_login') ?: '/new')
|
||||
));
|
||||
$app->response()->body($html);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,26 @@ $app->get('/editor', function() use($app) {
|
|||
$app->response()->body($html);
|
||||
});
|
||||
|
||||
$app->post('/editor/publish', function() use($app) {
|
||||
|
||||
if($user=require_login($app)) {
|
||||
$params = $app->request()->params();
|
||||
|
||||
$micropub_request = array(
|
||||
'h' => 'entry',
|
||||
'name' => $params['name'],
|
||||
'content' => $params['body']
|
||||
);
|
||||
|
||||
$r = micropub_post_for_user($user, $micropub_request);
|
||||
|
||||
$app->response()['Content-type'] = 'application/json';
|
||||
$app->response()->body(json_encode([
|
||||
'location' => $r['location']
|
||||
]));
|
||||
}
|
||||
});
|
||||
|
||||
$app->post('/editor/upload', function() use($app) {
|
||||
// Fake a file uploader by echo'ing back the data URI
|
||||
$fn = $_FILES['files']['tmp_name'][0];
|
||||
|
@ -21,6 +41,7 @@ $app->post('/editor/upload', function() use($app) {
|
|||
]
|
||||
]));
|
||||
});
|
||||
|
||||
$app->post('/editor/delete-file', function() use($app) {
|
||||
$app->response()['Content-type'] = 'application/json';
|
||||
$app->response()->body(json_encode(['result'=>'deleted']));
|
||||
|
@ -33,6 +54,12 @@ $app->get('/editor/oembed', function() use($app) {
|
|||
$app->response()->body($json);
|
||||
});
|
||||
|
||||
$app->post('/editor/test-login', function() use($app) {
|
||||
$logged_in = array_key_exists('user_id', $_SESSION);
|
||||
$app->response()['Content-type'] = 'application/json';
|
||||
$app->response()->body(json_encode(['logged_in'=>$logged_in]));
|
||||
});
|
||||
|
||||
// $app->get('/appcache.manifest', function() use($app) {
|
||||
// $content = partial('partials/appcache');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue