diff --git a/controllers/auth.php b/controllers/auth.php index 09c8cde..0741d22 100644 --- a/controllers/auth.php +++ b/controllers/auth.php @@ -79,13 +79,10 @@ $app->get('/', function($format='html') use($app) { $res = $app->response(); - ob_start(); render('index', array( 'title' => 'Teacup', 'meta' => '' )); - $html = ob_get_clean(); - $res->body($html); }); $app->get('/auth/start', function() use($app) { @@ -97,12 +94,11 @@ $app->get('/auth/start', function() use($app) { // aaronparecki.com http://aaronparecki.com http://aaronparecki.com/ // Normlize the value now (move this into a function in IndieAuth\Client later) if(!array_key_exists('me', $params) || !($me = normalizeMeURL($params['me']))) { - $html = render('auth_error', array( + render('auth_error', array( 'title' => 'Sign In', 'error' => 'Invalid "me" Parameter', 'errorDescription' => 'The URL you entered, "' . $params['me'] . '" is not valid.' )); - $app->response()->body($html); return; } @@ -161,7 +157,7 @@ $app->get('/auth/start', function() use($app) { $user->type = $micropubEndpoint ? 'micropub' : 'local'; $user->save(); - $html = render('auth_start', array( + render('auth_start', array( 'title' => 'Sign In', 'me' => $me, 'authorizing' => $me, @@ -172,7 +168,6 @@ $app->get('/auth/start', function() use($app) { 'authorizationEndpoint' => $authorizationEndpoint, 'authorizationURL' => $authorizationURL )); - $app->response()->body($html); } }); @@ -183,12 +178,11 @@ $app->get('/auth/callback', function() use($app) { // Double check there is a "me" parameter // Should only fail for really hacked up requests if(!array_key_exists('me', $params) || !($me = normalizeMeURL($params['me']))) { - $html = render('auth_error', array( + render('auth_error', array( 'title' => 'Auth Callback', 'error' => 'Invalid "me" Parameter', 'errorDescription' => 'The ID you entered, ' . $params['me'] . ' is not valid.' )); - $app->response()->body($html); return; } @@ -199,34 +193,31 @@ $app->get('/auth/callback', function() use($app) { } if(!array_key_exists('code', $params) || trim($params['code']) == '') { - $html = render('auth_error', array( + render('auth_error', array( 'title' => 'Auth Callback', 'error' => 'Missing authorization code', 'errorDescription' => 'No authorization code was provided in the request.' )); - $app->response()->body($html); return; } // Verify the state came back and matches what we set in the session // Should only fail for malicious attempts, ok to show a not as nice error message if(!array_key_exists('state', $params)) { - $html = render('auth_error', array( + render('auth_error', array( 'title' => 'Auth Callback', 'error' => 'Missing state parameter', 'errorDescription' => 'No state parameter was provided in the request. This shouldn\'t happen. It is possible this is a malicious authorization attempt.' )); - $app->response()->body($html); return; } if($params['state'] != $_SESSION['auth_state']) { - $html = render('auth_error', array( + render('auth_error', array( 'title' => 'Auth Callback', 'error' => 'Invalid state', 'errorDescription' => 'The state parameter provided did not match the state provided at the start of authorization. This is most likely caused by a malicious authorization attempt.' )); - $app->response()->body($html); return; } @@ -275,12 +266,11 @@ $app->get('/auth/callback', function() use($app) { // Verify the login actually succeeded if(!k($token['auth'], 'me')) { - $html = render('auth_error', array( + render('auth_error', array( 'title' => 'Sign-In Failed', 'error' => 'Unable to verify the sign-in attempt', 'errorDescription' => '' )); - $app->response()->body($html); return; } @@ -317,7 +307,7 @@ $app->get('/auth/callback', function() use($app) { if($skipDebugScreen) { $app->redirect($_SESSION['redirect_after_login'], 301); } else { - $html = render('auth_callback', array( + render('auth_callback', array( 'title' => 'Sign In', 'me' => $me, 'authorizing' => $me, @@ -328,7 +318,6 @@ $app->get('/auth/callback', function() use($app) { 'curl_error' => (array_key_exists('error', $token) ? $token['error'] : false), 'redirect' => $_SESSION['redirect_after_login'] )); - $app->response()->body($html); } }); diff --git a/controllers/controllers.php b/controllers/controllers.php index 1adc5da..9e94902 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -57,7 +57,7 @@ $app->get('/new', function() use($app) { // will still be a list of options presented on the page by the time it loads. // Javascript will replace the options after location is available. - $html = render('new-post', array( + render('new-post', array( 'title' => 'New Post', 'micropub_endpoint' => $user->micropub_endpoint, 'micropub_media_endpoint' => $user->micropub_media_endpoint, @@ -71,6 +71,12 @@ $app->get('/new', function() use($app) { 'time_str' => $time_str, 'enable_array_micropub' => $user->enable_array_micropub )); + } +}); + +$app->get('/settings', function() use($app) { + if($user=require_login($app)) { + $html = $app->response()->body($html); } }); @@ -98,13 +104,11 @@ $app->get('/creating-a-token-endpoint', function() use($app) { $app->redirect('http://indiewebcamp.com/token-endpoint', 301); }); $app->get('/creating-a-micropub-endpoint', function() use($app) { - $html = render('creating-a-micropub-endpoint', array('title' => 'Creating a Micropub Endpoint')); - $app->response()->body($html); + render('creating-a-micropub-endpoint', array('title' => 'Creating a Micropub Endpoint')); }); $app->get('/docs', function() use($app) { - $html = render('docs', array('title' => 'Documentation')); - $app->response()->body($html); + render('docs', array('title' => 'Documentation')); }); $app->get('/add-to-home', function() use($app) { @@ -143,8 +147,7 @@ $app->get('/add-to-home', function() use($app) { $app->redirect('/add-to-home?token='.$token, 302); } else { unset($_SESSION['add-to-home-started']); - $html = render('add-to-home', array('title' => 'Teacup')); - $app->response()->body($html); + render('add-to-home', array('title' => 'Teacup')); } } } @@ -392,14 +395,13 @@ $app->get('/:domain', function($domain) use($app) { $newer = false; } - $html = render('entries', array( + render('entries', array( 'title' => 'Teacup', 'entries' => $entries, 'user' => $user, 'older' => ($older ? $older->id : false), 'newer' => ($newer ? $newer->id : false) )); - $app->response()->body($html); })->conditions(array( 'domain' => '[a-zA-Z0-9\.-]+\.[a-z]+' )); @@ -418,12 +420,11 @@ $app->get('/:domain/:entry', function($domain, $entry_id) use($app) { return; } - $html = render('entry', array( + render('entry', array( 'title' => 'Teacup', 'entry' => $entry, 'user' => $user )); - $app->response()->body($html); })->conditions(array( 'domain' => '[a-zA-Z0-9\.-]+\.[a-z]+', 'entry' => '\d+'